This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430-gcc generated code too long

Other Parts Discussed in Thread: MSP430F1132

Hi, I downloaded the msp430-gcc from the TI homepage. There is an example program called blink.c. It is very short and very simple, as follows:

#include <msp430.h>

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;        // Stop watchdog timer
    P1DIR |= 0x01;                    // Set P1.0 to output direction

    for(;;) {
        volatile unsigned int i;    // volatile to prevent optimization

        P1OUT ^= 0x01;                // Toggle P1.0 using exclusive-OR

        i = 10000;                    // SW Delay
        do i--;
        while(i != 0);
    }

    return 0;
}

That's all. The problem is that from this tiny program msp430-gcc produces a 13.1 kByte long .out file, although I used the -O3 switch and didn't use the -g switch on the compiler to produce the shortest code.

I want to program an MSP430F1132 which has only 8 kByte program memory. What can I do to make the output files shorter with msp430-gcc?

Stefan

  • The compiler outputs an ELF file, which also can contain things like headers, relocation information, and debug symbols. You should name it .elf to prevent misunderstandings.

    To program the chip, you might need to convert it into a format supported by the programmer.
    Tools like gdb/DDD already support ELF (and use only the actual binary part of the file); to get, e.g., an Intel hex file, you would run something like "msp430-objcopy -O ihex blink.elf blink.hex".

  • Hi,

    Have a look at  -ffunction-sections and fdata-sections under compiler/Optimization, and --gc-sections under Linker/Basic.

    I had a brief look at gcc a while ago and found that these switches help, with removing library functions that are not used by the application.

    Roy

  • Note that the generated TXT or HEX file is human-readable (well, sort of). Each binary byte of the firmware is encoded into two-letter hexadezimal text, along with checksum and/or location information. So the file size is still 2-3 times larger than the real binary size. Also, the binary image also contains a full vector table, even if your program does not contain any ISRs at all. For a very small program, this can be more than the program code itself.
    The program that flashes the TXT or HEX file to the MSP interprets the file content and sends the plain binary data to the MSP into the correct locations.

**Attention** This is a public forum