RedHat Toolchain for small chips

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

RedHat Toolchain for small chips

Esmil-2
Hi,

I just tried installing the new toolchain, r206599 from the GCC SVN and the
latest newlib from CVS.
However when I try to compile simple programs for small chips it seems just
the runtime takes up more SRAM than the chip has. Eg.

$ cat simple.c
#include <msp430.h>

static inline void delay(unsigned int n) {
  __asm__ __volatile__ (
      "1: \n"
      " dec %[n] \n"
      " jne 1b \n"
      : [n] "+r"(n));
}

int main(void) {
  WDTCTL = WDTPW | WDTHOLD; /* watchdog_off();       */
  P1DIR |= BIT0;            /* pin_mode_output(1.0); */

  while (1) {
    P1OUT |= BIT0;  /* pin_high(1.0); */
    delay(0xFFFF);
    P1OUT &= ~BIT0; /* pin_low(1.0);  */
    delay(0xFFFF);
  }
}
$ msp430-elf-gcc -mmcu=msp430g2231 -Os -static -Wall -Wextra simple.c -o
simple.elf
/usr/lib/gcc/msp430-elf/4.9.0/../../../../msp430-elf/bin/ld: simple.elf
section `.bss' will not fit in region `RAM'
/usr/lib/gcc/msp430-elf/4.9.0/../../../../msp430-elf/bin/ld: region `RAM'
overflowed by 16 bytes
collect2: error: ld returned 1 exit status

So am I doing something wrong or will it work eventually and I'm just being
impatient?

/Emil

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

Lorenzo Marcantonio
On Tue, Jan 14, 2014 at 01:27:26PM +0100, Emil Renner Berthing wrote:
> So am I doing something wrong or will it work eventually and I'm just being
> impatient?

I could say that newlib is huge and the crt code for gcc too could use
a trim (for example it links in code for C++ and java initialization
even for straight C :D). Also probably libgloss is taking some bss for
ANSI features, like stdio and stuff...

And, by the way, even the 'lite' printf pulls in the whole malloc
machinery (so a simple siprintf eats about 5KB of code space!)

Maybe newlib is not the best tool for small MCU (128 byte of RAM IIRC)

--
Lorenzo Marcantonio
Logos Srl

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

nick clifton
In reply to this post by Esmil-2
Hi Emil,
> However when I try to compile simple programs for small chips it seems just
> the runtime takes up more SRAM than the chip has.

Have you tried turning on linker garbage collection ?  This should make
the linker discard unused bits of code (eg most of newlib).  So for example:

   msp430-elf-gcc -mmcu=msp430g2231 -Os -static -Wall -Wextra simple.c -o
simple.elf -Wl,-gc-sections


Cheers
   Nick


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

Lorenzo Marcantonio
In reply to this post by Lorenzo Marcantonio
On Tue, Jan 14, 2014 at 02:08:53PM +0100, Emil Renner Berthing wrote:
> Right, so the workaround is something like
> $  msp430-elf-gcc -mmcu=msp430g2231 -Os -static -nostdlib -Wall -Wextra
> simple.c -o simple.elf `msp430-elf-gcc gcc -print-libgcc-file-name`
> ..and then add my own assembly to clear .bss etc. and jump to main().
>
> I guess I had just hoped there would be a standard way of doing this, so
> everyone doesn't have to implement that bit again.

An objdump of the newlib .o could tell where the bss is eaten up, then
selective surgery on newlib/libgloss can be done (do the MSP *really*
need stdio?). Other cruft (the C++ and java one) can be ifdeffed out in
crtstuff.c (in libgcc). And that printf is pure evil :D (not that
I often use printf on MCUs...)

Compiling the target app with LTO (verify that ISR are actually
emitted! attribute used helps) or better yet do a single compilation
unit with the world declared static (essentially what Byte Craft does
from forever) gain *huge* code space with -Os. Yes, I'm aggressively
spacing optimizing the code :D

Also unsigned int is obviously easier to process than an unsigned char,
most of the time: the MSP is almost pure 16 bit (except for load/store),
the stack is slotted on even addresses and registers needs to be anded
with FFh to ensure 8-bit semantic. At 4 bytes (IIRC) for each unsigned
char parameter used, the gain is significant.

--
Lorenzo Marcantonio
Logos Srl

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

Esmil-2
In reply to this post by nick clifton
On 14 January 2014 14:17, nick clifton <[hidden email]> wrote:

> Hi Emil,
>
>  However when I try to compile simple programs for small chips it seems
>> just
>> the runtime takes up more SRAM than the chip has.
>>
>
> Have you tried turning on linker garbage collection ?  This should make
> the linker discard unused bits of code (eg most of newlib).  So for example:
>
>   msp430-elf-gcc -mmcu=msp430g2231 -Os -static -Wall -Wextra simple.c -o
> simple.elf -Wl,-gc-sections
>
Hi Nick,

Thanks for the suggestion. I just tried that, but it unfortunately it
doesn't seem to have any effect.

$ msp430-elf-gcc -mmcu=msp430g2231 -Os -static -Wall -Wextra simple.c -o
simple.elf -Wl,-gc-sections
/usr/lib/gcc/msp430-elf/4.9.0/../../../../msp430-elf/bin/ld: simple.elf
section `.bss' will not fit in region `RAM'
/usr/lib/gcc/msp430-elf/4.9.0/../../../../msp430-elf/bin/ld: region `RAM'
overflowed by 14 bytes
collect2: error: ld returned 1 exit status

/Emil

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

nick clifton
Hi Emil,

> Thanks for the suggestion. I just tried that, but it unfortunately it
> doesn't seem to have any effect.

Darn.

I did try compiling your test case locally, but I do not run into these
errors.  The binary I end up with is 13182 bytes on disk and only uses
38 bytes of data:

   % msp430-elf-size simple.elf
    text    data     bss
    488      22      16

Maybe it is the version of the toolchain that I am using.  In which case
the answer to your original question is "yes, you are being impatient" :-)

Cheers
   Nick

PS. In case it helps I have attached the simple.elf binary that I am using.

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

DJ Delorie
In reply to this post by Esmil-2

The typical case for tiny programs is that the startup/shutdown code,
which normally has to be robust enough to handle all language
extensions, is vastly bigger than the program itself.  There are a
couple of things you can manually do to trim out bits you know you
don't need, like custom crt0.S (to cut out calls you don't need) or
*.lnk files (to discard functions that are implicitly pulled in).

We have some patches to do more of this automatically, which just
haven't made it to the public releases yet.  It might be worth
comparing with TI's release of gcc.  Also, be aware that some of the
changes are in newlib and binutils, not just gcc.

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: RedHat Toolchain for small chips

David Brown-4
In reply to this post by Esmil-2
On 14/01/14 13:27, Emil Renner Berthing wrote:

> Hi,
>
> I just tried installing the new toolchain, r206599 from the GCC SVN and the
> latest newlib from CVS.
> However when I try to compile simple programs for small chips it seems just
> the runtime takes up more SRAM than the chip has. Eg.
>
> $ cat simple.c
> #include <msp430.h>
>
> static inline void delay(unsigned int n) {
>   __asm__ __volatile__ (
>       "1: \n"
>       " dec %[n] \n"
>       " jne 1b \n"
>       : [n] "+r"(n));
> }
>
> int main(void) {
>   WDTCTL = WDTPW | WDTHOLD; /* watchdog_off();       */
>   P1DIR |= BIT0;            /* pin_mode_output(1.0); */
>
>   while (1) {
>     P1OUT |= BIT0;  /* pin_high(1.0); */
>     delay(0xFFFF);
>     P1OUT &= ~BIT0; /* pin_low(1.0);  */
>     delay(0xFFFF);
>   }
> }
> $ msp430-elf-gcc -mmcu=msp430g2231 -Os -static -Wall -Wextra simple.c -o
> simple.elf
> /usr/lib/gcc/msp430-elf/4.9.0/../../../../msp430-elf/bin/ld: simple.elf
> section `.bss' will not fit in region `RAM'
> /usr/lib/gcc/msp430-elf/4.9.0/../../../../msp430-elf/bin/ld: region `RAM'
> overflowed by 16 bytes
> collect2: error: ld returned 1 exit status
>
> So am I doing something wrong or will it work eventually and I'm just being
> impatient?
>
> /Emil
>
>

You need to generate a map file to see what is /actually/ taking up space:

-Wl,-Map=simple.map,--cref



------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users