Skip to main content
Thomas LB
Associate III
January 14, 2022
Solved

STM32CubeIDE vs Keil µVision generated code size

Hello,

I used to generate code from STM32CubeMX then edit, compile and flash to board with Keil µVision (default config).

Recently, I followed bootloader tutorial that uses STM32CubeIDE and I must admit it's nice but for exact same source code, the generated code size in way bigger (47k vs 27k) and I need it to fit into 32k...

The Debug / Release configuration is unclear to me as well as compiler directive, isn't it technically possible to configure STM32CubeIDE to generate exact same code as Keil µVision from exact same source files ?

Hope someone can help :)

Have a good day,

Thomas

This topic has been closed for replies.
MM..1
MM..1Best answer
Super User
January 14, 2022

Changing debug level can little modify size , but more priority setings is Optimizing levels. try check and change -O0 to -Os

In Project -> Properties -> C/C++ Build -> Settings - MCU GCC Compiler - Optimization

for C++ too in

In Project -> Properties -> C/C++ Build -> Settings - MCU G++ Compiler - Optimization

And for primary quesstion Keil is comercial compiler ... more money more effective optimizing

4 replies

mƎALLEm
ST Technical Moderator
January 14, 2022

Dear @Thomas LB​ ,

It's expected to have different sizes between two different compilers. Moreover even with the same IDE with different version you can have different code size even with the exact same code ..

So the only thing to do is to play with the Optimization of the tool in order to let your code to fit into 32k.

SofLit

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Thomas LB
Thomas LBAuthor
Associate III
January 14, 2022

Thank you for answering,

But I'm pretty sure I'm missing something. When I go in Project -> Properties -> C/C++ Build -> Settings -> and change here the debug level from max (g3) to none and also remove preprocessor instruction DEBUG. The generated code size doesn't changed.

After rebuilding project from scratch from cubeMX, now I can see big difference between Debug and Release version code size (was buggy for some reason).

Effectively removing debug information leads to more reasonable code size :)

MM..1
MM..1Best answer
Super User
January 14, 2022

Changing debug level can little modify size , but more priority setings is Optimizing levels. try check and change -O0 to -Os

In Project -> Properties -> C/C++ Build -> Settings - MCU GCC Compiler - Optimization

for C++ too in

In Project -> Properties -> C/C++ Build -> Settings - MCU G++ Compiler - Optimization

And for primary quesstion Keil is comercial compiler ... more money more effective optimizing

Thomas LB
Thomas LBAuthor
Associate III
January 21, 2022

Seems the "Build Analyser" view is not well refreshed sometimes (that's why I was confused in the first place)0693W00000JMp99QAD.png0693W00000JMp8uQAD.pngIf I rebuild, the Build Analyser data doesn't update. Sometimes it works sometimes not. Havent figured out yet what could be the root cause