cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE vs Keil µVision generated code size

Thomas LB
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.
Thomas LB
Associate III

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 🙂

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
Associate III

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