2021-09-04 08:48 PM
Hi.
I thought this question is more suited to education.
I have been working on a STM32F091 C++ project just to get an idea code size, and I noticed that the size of the binary is huge even when optimisation is set to (-Os). I think its because the compiler is bringing in everything, even when certain functions, and section are not being used, but! I’m not sure.
Generally speaking, is there a way if streamlining my project to cut down on code?
Thanks
cp
2021-09-04 09:18 PM
> I think its because the compiler is bringing in everything, even when certain functions, and section are not being used, but! I’m not sure.
You can open up the map file and figure out what's taking so much space. Ensure your linker discards unused code (-WL,--gc-sections)
> Generally speaking, is there a way if streamlining my project to cut down on code?
Remove unnecessary code, don't duplicate code.
Use a reduced library such as nano (--specs).
Avoid using dynamic memory allocation (malloc/free).
The -Os optimization flag should be about the best you can do for size from a compiler standpoint. Might get more with link time optimization (-flto).
2021-09-07 01:05 AM
Thanks for your answer TDK.
Where do I place (-WL,--gc-sections) and (--specs) in the cubeIDE settings.
2021-09-07 03:31 AM
In project settings.
2021-09-08 10:57 PM
ok, I checked my settings, and that's the way they are set up already. This code I'm using compiles for a mega2560 AVR at just under 128K, but as it is, ported to STM32F091, it generates 241k of code. That a big difference.
2021-09-10 11:43 PM
Just to complete this thread, one of the files contained an #include <iostream> statement.
When I removed this, the code size came down to 88K, which seems about right for this project size.
cheers