cancel
Showing results for 
Search instead for 
Did you mean: 

Compiled code size and flashed code size are different in STM32CUBEIDE v1.15.1

Simo_Sappo
Associate III

Hi everyone, I created an HID bootloader for the STM32G4xxx, it works and now I am trying to optimize the size. After compiling I can read this on the Build Analyzer a flash memory usage of 17.85 kB.Screenshot 2024-06-06 181018.png 

After compiling I get this:

Screenshot 2024-06-06 180859.png

 

When I flash this compiled code and read the flash memory I canclearly see that the memory usage is around 38 kB.  

Screenshot 2024-06-06 180946.png

I also used the STM32CubeProgrammer to look at the actual memory (I didn't manage to use this function directly on STM32CubeIDE) and I can see that more than 38 kB are used in the memory

Can somebody explain why? Am I missing something about the Build Analyzer function?

  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Simo_Sappo
Associate III

I found the problem, somehow even if I set the Release mode as active (with the size optimization) it was still flashing the Debug version of the code which is not optimized for size. I discovered this only after deleting the Debug and Release folders and staring the flashing process again. Thank you everyone for your help

View solution in original post

13 REPLIES 13
gbm
Lead III

SREC file is a text file. It's size is a little over 2 times the programmed Flash footprint.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Thank you very much, is there a way to reduce its size or to flash into memory a different file that woul dbe smaller?

What's programmed into Flash is more than just the code - there's also all the data initialisation values.

The Build Analyser shows you exactly what's going into the Flash, and where:

AndrewNeil_2-1717759397633.png

 

AndrewNeil_3-1717759518617.png

 

Everything in the 'Load address' column is stored in Flash

.text is your executable code; some of the other things are mentioned here:

https://stackoverflow.com/questions/15265295/understanding-the-libc-init-array 

 

 

Okey so I understood what the build analyzer is showing. BUt where do the other 20 kB of code come from? Is there anyway to reduce this amount?

 

Show your Build Analyser output

Sure, here it is

Screenshot 2024-06-07 141431.png


@Simo_Sappo wrote:
AndrewNeil_1-1717762947716.png

 


So you have 16.88KB of code, and a total of just 1092 bytes of extras.

That's pretty insignificant - only ~6% - so what are you worrying about?

 

Simo_Sappo
Associate III

 My problem is that the code I am actually flashing in the microcontroller is 38.37 kB, which I confirmed by also opening the flash memory with STM32CubeProgrammer. I don't understand why I am flashing a file that is double the size of my actual code.


Screenshot 2024-06-06 180946.png

But, as @gbm already said, that's the size of  the SREC file on your hard drive - not the size of the data which gets programmed into the Flash?