Showing results for 
Search instead for 
Did you mean: 

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

Associate II

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?



Lead III

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

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:





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

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



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:


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?


Associate II

 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?