SSZT904 November 2017 MSP430FR2000
Have you ever been close to finishing your microcontroller (MCU) code, only to get the dreaded error message shown in Figure 1?
Your program is too large to fit in your device! This may seem like a hopeless situation, but fortunately, there are a lot of strategies you can take to get your code to build smaller and hopefully squeeze a few more functions into your device. By using the compiler settings to their fullest and carefully considering how you write your code, you can get the best code-size efficiency possible for your MSP430™ MCU project.
Optimizer Assistant automatically builds with all of the different variants for size versus speed or optimization level and reports the code size back for each, along with whether the project will fit into the device. You can use it to help pick the right settings for your project: for example, to get the best speed performance for code that will still fit into the device’s nonvolatile memory.
So if you are using an MSP430 device that doesn’t have any nonvolatile memory above 10000h, make sure to choose small code model so that the compiler can optimize and use only 16-bit addressing, thus taking less code space.
Selecting small data model tells the compiler that there will be no variables above 10000h (for example, no random access memory [RAM] nor ferroelectric RAM [FRAM] variables above 10000h). Making just this simple setting change on the msp430fr211x_euscia0_uart_03.c code example caused the code to build 38% smaller.
Then, set Project > Properties > MSP430 Linker > Advanced Options > Miscellaneous > “Zero initialize ELF uninitialized sections (--zero_init)” to off, as shown in Figure 5.
For the msp430fr211x_euscia0_uart_03.c example, making this change resulted in a 62% reduction in code size, saving more than half the memory size of the 512-byte MSP430FR2000 device.