Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 4 months ago.
Huge binary size when building with ARM GCC Toolchain
I am trying out mbed OS with flavor of RTOS. Everything works well when using online compiler. Example programs compiles just fine and binary size is adequate.
I then decided to export the program using "GNU ARM Eclipse" as an export toolchain and import in Eclipse to work offline. I managed to build it successfully but I was unable to flash the binary onto MCU (STM32F103). I then observed that binary produced by online compiler was just 41KB in size while the binary produced by GNU toolchain is 80KB.
I used Nucleo-F103RB as a target as it is compatible with STM32F103.
Can anyone comment on why there is a huge size difference in binaries sizes? May be I need to add some flags in linker scripts or may be make some change in target device?
Any help will be much appreciated!
1 Answer
5 years, 4 months ago.
I figured out that the compiler that online Mbed Compiler use is ARMC6 while to work offline I was using GCC_ARM compiler with Eclipse as well as Mbed CLI.
All compilers compile code differently. I tried changing the optimization flags, debug flags etc. to produce the shortest code possible but none worked.
I then used ARMC6 compiler and binary size was same as the Mbed Online Compiler and it worked!
Next issue was that if I start more than 2 threads, my microcontroller chokes. I then found in the Mbed Thread documentation that by default threads stack is allocated in heap. To allocate it in stack, we need to initialize the thread like this:
Thread thread(osPriorityNormal, 3 * 1024); 3K Stack Size
Allocating the memory for thread statically, only the amount you need (and doing it carefully not to cause stack overflow), we can make optimal use of available memory to start more threads.
Hope this information is helpful for someone!
Assigned to
5 years, 4 months ago.This means that the question has been accepted and is being worked on.
I figured out that the compiler that online Mbed Compiler use is ARMC6 while to work offline I was using GCC_ARM compiler with Eclipse as well as Mbed CLI.
All compilers compile code differently. I tried changing the optimization flags, debug flags etc. to produce the shortest code possible but none worked.
I then used ARMC6 compiler and binary size was same as the Mbed Online Compiler and it worked!
Next issue was that if I start more than 2 threads, my microcontroller chokes. I then found in the Mbed Thread documentation that by default threads stack is allocated in heap. To allocate it in stack, we need to initialize the thread like this:
Thread thread(osPriorityNormal, 3 * 1024); 3K Stack Size
Allocating the memory for thread statically, only the amount you need (and doing it carefully not to cause stack overflow), we can make optimal use of available memory to start more threads.
Hope this information is helpful for someone!
posted by Hamza Rizwan 15 Jul 2019