Atmel AT89C5131 Support?

dondee
2005-01-05
2013-03-12
  • dondee
    dondee
    2005-01-05

    Can SDCC compile for c51 cores, like AT89C5131?  If so, are there special compile options I need to use?  Thanks!

     
    • the 8051 core has been the primary target cpu for SDCC. No special options are needed for an AT89C5131. An adapted header file with the additional AT89C5131 function registers will be needed. The script sdcc/support/scripts/keil2sdcc.pl might help there.

       
    • dondee
      dondee
      2005-01-12

      i wrote a c code that only turns on an LED.  why is it that the hex file generated by sdcc is so much bigger than that compiled by keil?

       
      • dondee
        dondee
        2005-01-13

        hmmm...2.3.0 compiles ok...what changed in 2.4?

         
    • Maarten Brock
      Maarten Brock
      2005-01-14

      A lot has changed between 2.3.0 and 2.4.0.

      If you expect help, I suggest to tell some more on the problem, sdcc options and the code you're using. You could even file a support request or bug report and upload the code there.

       
    • Andrea
      Andrea
      2005-01-14

      I think my problem is similiar but I dont want to flood the forum with code lines (not yet, at least..).
      I'm just trying to port to SDCC the UDP sample program that comes with the atmel devkit;you can find it at

      http://www.iinchip.com/wiznet/images/Download/W3100A/Sample%20Codes/LB_UDP.zip

      it's meant to be compiled with Keil.
      I've already made some minor changes by hand, eg:

      [Original]
      sfr  CKCON              = 0x8F;

      [for SDCC]
      sfr  at 0x8F CKCON;

      Anyway if I compile it with no options it tells me:

      ?ASlink-Error-Could not get 147 consecutive bytes in internal RAM for area DSEG.

      If I use --model-large I'm able to compile but it behaves weirdly.

      Any clue?

      PS: I apologize for the trivial question but how can I have the keil2sdcc.pl script working on a Win machine?

      Thanks,
      Andrea

       
      • tony_pemberton
        tony_pemberton
        2005-01-14

        I use sdcc version 2.4.7 #906 in the Silabs IDE. I am using the small model. I think the AS-link error means that some of your variables might need to be allocated into the Indirect data segment (declared with the idata prefix). That said, I have had the same error (with different amouts of memory required of course) and that has usually been a silly typo on my part (such as an odd brace char). Difficult to find though! 

        Looking at CKCON (for the Silabs C8051F040)

        sfr at 0x8E CKCON    ;  // CLOCK CONTROL

        works fine for me.

        I would also like to know about the keil2sdcc tool on a windows machine, though for any code I have needed to convert, hand conversion has been fine for me.

        Tony

         
        • Andrea
          Andrea
          2005-01-14

          Thanks, Tony, for answering.

          1- I'm using SDCC 2.4.7 #906 too. You're suggesting me to use ISEG (right?) but there's no indirect memory on an 8051. So should I declare some more xdata variables?

          2- If it's only a not-enough-room problem, why does it works badly when compiled using the large model?

          3- After getting the error message the first time I began once again from the start and modified all the original source files, thus (hopefully) reducing the possibility of typo errors; I eventually got the same error message.

          Thanks,
          Andrea

           
          • Maarten Brock
            Maarten Brock
            2005-01-17

            Andrea,

            There definitely is indirect memory on an AT89C51RD2. See figure 8 of the datasheet. Unfortunately it's only 128 bytes in size, so not nearly enough for your 147 needed bytes. Moving stuff to xdata is the way to go, either by hand or by using large memory model. Most data memory is probably used for so-called spill locations. Using --stack-auto might help here as it moves all spill locations to the stack where they can be overlayed better than SDCC's overlaying algorithm can. But it will cost code speed and size.

            You were right in not flooding the forum with source code. But there is another option: use the support request page and you can upload as files. If traffic is too low there, you can still post a reference question here.

            Hope this helps,
            Maarten

             
            • Andrea
              Andrea
              2005-01-18

              I apologize with Tony and thank Maarten for correcting me. There are 256 byte of RAM on the 89C51RD2.

              I've posted a support request with the files.

              I've tried the --stack-auto option but it gives me an error:

              socket.c:1201: error 16: variable 'UDPHeader' must be static to have storage class in reentrant function

              Anyway, if it compiles when the --model-large is set, the problem is: why does it hang up after a while?

              Next try: I think I'll manage to make the keil2sdcc.pl run... Is it something you do by default when using "foreign" libraries?

               
    • dondee
      dondee
      2005-01-16

      This is basically my test code:

      #include "at89c5131.h"
                                                                                     
      void main (void)
      {
              P3_3 = ~P3_3;
      }

      I compiled it with default options: sdcc main.c

      It seems that some extra code was added because the resulting hex file was about 100 lines long (2.5kB).  Compiling the same code with Keil only gave me a couple of lines in the hex file.  When I compiled it with 2.3 the hex file was a lot smaller but still bigger than Keil's, but at least it worked after I programmed the device.

       
      • Maarten Brock
        Maarten Brock
        2005-01-17

        Dondee,

        The difference in size can be explained by more initialization code in the new version. To suppress xdata (eram) initialization use option --no-xinit-opt. The fact that Keil does better than SDCC doesn't surprise me. They can put a lot more manhours into development and you pay for that when you buy their product.

        Now the question remains why it doesn't work. We developers decided that "bit/sbit" should be like "bool" as defined in the C standard. One result of that is you can no longer use ~ to invert a bit. This will result in a 1 always due to required conversion to int before complementing. Use P3_3 = !P3_3 instead.

        Greets,
        Maarten

         
    • dondee
      dondee
      2005-01-17

      First of all, I apologize for my previous post.  I did not mean to sound like I'm undermining SDCC.  I think it's great that there's a freeware 8051 compiler out there.  I just made the comparison with Keil to better describe what I'm seeing.  I would just like to get some ideas how I can get my code to work when compiled with 2.4. 

      I modified my test code to look like the following:

      #include <at89c5131.h>

      #define LED_2MA                 0x01
      #define cfg_led(num,type)  {LEDCON &= (0xFF & ~(0x03 << (num*2))); \                                  LEDCON |= (type << (num*2));}
      #define led_0_on()              (P3_3 = 0)

      void main (void)
      {
              cfg_led(0,LED_2MA);
              led_0_on();
      }

      Using --no-xinit-opt brought the ihx size down from 2474 to 2290 bytes, but still does not work (does not turn LED on).  This same exact code works fine when compiled with 2.3 (254 byte ihx), but flakes out when code gets bigger and more complex. 

       
      • Maarten Brock
        Maarten Brock
        2005-01-18

        Where did you get the at89c5131.h file? If it's the one from atmel, it must be updated. Change the two defines at the top to this:

        #define Sfr(x,y)      sfr at y   x
        #define Sbit(x,y,z)  sbit at y+z x

         
        • dondee
          dondee
          2005-01-18

          Thank you very much, Maarten!  That fixed my problem!  And the code is actually smaller than Keil's ;)