cancel
Showing results for 
Search instead for 
Did you mean: 

Even after building code with optimization level -0s. There is no change in size, it just get adjusted with .text and .data.

PSola.1
Associate

I am facing issue of memory with Stm32L432xx, So i tried option of increase optimization level from -01 to -0s.

But observe no change it just reduce in .text section... but it increased in .data segment. ultimately value is same and issue is continue

Before optimization i.e -01

 text    data     bss     dec     hex filename

  117760        11264        30064        159088        26d70      build/app-firmware.elf

After optimization level set -0s

 text    data     bss     dec     hex filename

 117480         11544         30064        159088         26d70 build/app-firmware.elf

 

1 ACCEPTED SOLUTION

Accepted Solutions
Andrew Neil
Evangelist III

Optimisation affects the code generated. The .text section is where the generated code goes - so that's where you'd expect to see any changes!

-Os optimises for the size of generated code - smaller code might require extra RAM.

Optimisation documentation:

https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Optimization-Levels.html

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

The main "consumer" of RAM is variables declared by your code, So, to reduce RAM usage, you're going to have to review your code for what is using memory, and think how you can reduce that.

The linker map file should help you with that.

Also the nm utility: https://sourceware.org/binutils/docs/binutils/nm.html

View solution in original post

7 REPLIES 7
Andrew Neil
Evangelist III

Optimisation affects the code generated. The .text section is where the generated code goes - so that's where you'd expect to see any changes!

-Os optimises for the size of generated code - smaller code might require extra RAM.

Optimisation documentation:

https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Optimization-Levels.html

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

The main "consumer" of RAM is variables declared by your code, So, to reduce RAM usage, you're going to have to review your code for what is using memory, and think how you can reduce that.

The linker map file should help you with that.

Also the nm utility: https://sourceware.org/binutils/docs/binutils/nm.html

Markus GIRDLAND
ST Employee

To add to what Andrew mentioned, to see what consumes the most memory of your application you can use the Build Analyzer inside STM32CubeIDE. Choose "Show Byte" and sort by the "Size" column as shown in the screenshot below:

0693W00000Npl9JQAR.png 

Although @PSola.1​ seems to be concerned about RAM - not Flash?

Or that the 128KB FLASH of the L432RB is all consumed. Same die used for the RC device.

Optimization can't fix algorithmic issues, or compress data structures.

Will need to make things more efficient, use subroutines for repetitive code, use of structures and tables, compress or encode data better, determine scope of buffers, don't make everything global, especially stuff used once at initailization.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for help @Andrew Neil (Community Member), I have re organize linker file by keeping 127k for flash and 1k for NV data

and does that help?

Ironically the screenshot also clearly shows how bloated the HAL is - the clock initialization with HAL_RCC_***() and some companion functions wastes 2 KB of flash.