5 years, 6 months ago.

Flash overflows with GCC export by adding UART

Hi, I've been using the MBED LPC1768 with the offline GNU toolchain (on Windows) for some time now and recently I switched to compiling for the FRDM-KL05Z.

A basic blinking led is not a problem. However, the second I add a uart port the linker complains about overflowing the flash.

-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 5344 bytes
collect2.exe: error: ld returned 1 exit status

This is by simply calling the exported makefile. The command line this generates is:

arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -fno-common -fmessage-length
=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointe
UINO  -std=gnu++98 -fno-rtti -I. -I./external/mbed -I./external/mbed/TARGET_KL05
Z -I./external/mbed/TARGET_KL05Z/TARGET_Freescale -I./external/mbed/TARGET_KL05Z
/TARGET_Freescale/TARGET_KLXX -I./external/mbed/TARGET_KL05Z/TARGET_Freescale/TA
.o main.cpp

Then the linker generates the error:

arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -Wl,--gc-sections --specs=nano.specs 
-u _printf_float -u _scanf_float -Wl,-Map=frdm_serial.map,--cref -T./external
-L./external/mbed/TARGET_KL05Z/TOOLCHAIN_GCC_ARM  -o frdm_serial.elf main.o 
-lmbed  -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -lmbed  -lstdc++ -lsupc++ -lm -lc
-lgcc -lnosys

The code is surprisingly simple...

Serial uart(PTA0, PTA1);
DigitalOut blinky(LED1);

int main()

        blinky = !blinky


    return 0;

Compiling much more complex programs in the online compiler is not an issue. So is this a bug from the GCC toolchain? Or related to my building on Windows?

Any help would be greatly appreciated

Question relating to:

The FRDM-KL05Z is an ultra-low-cost development platform enabled by the Kinetis L Series KL0x MCU family built on the ARM® Cortex™-M0+ processor. Features include easy access to MCU I/O, battery-ready, …

2 Answers

5 years, 6 months ago.

Edit: Yeah, what Martin said :)

Try removing these two options from the linker command line and see what happens:

-u _printf_float -u _scanf_float

That should discard a bunch of floating point code that the UART streaming support pulls in.

I hope that helps,


Accepted Answer

Hot diggity! Removing -u _printf_float -u _scanf_float did it.

arm-none-eabi-size Blinky.elf text data bss dec hex filename 16912 136 460 17508 4464 Blinky.elf

I already played with optimizations without any luck.

For future reference the KL05z has 32kB of flash:

Blinky with  -u _printf_float -u _scanf_float:

arm-none-eabi-size Blinky.elf
   text    data     bss     dec     hex filename
  32360     228     608   33196    81ac Blinky.elf

Blinky without  -u _printf_float -u _scanf_float:

arm-none-eabi-size Blinky.elf
   text    data     bss     dec     hex filename
   9720     128     352   10200    27d8 Blinky.elf

Blinky without  -u _printf_float -u _scanf_float with serial:

arm-none-eabi-size Blinky.elf
   text    data     bss     dec     hex filename
  16912     136     460   17508    4464 Blinky.elf

Still seems high for just a LED and uart though?

posted by K. N. L. V. 12 Dec 2014
5 years, 6 months ago.


you did not specify the size of blinky without uart, the size of KL05Z (not all of us know all flash/ram sizes from top of our heads).

I would start removing floating support specs=nano.specs -u _printf_float -u _scanf_float, and play with optimizations, use LTO?