2024-06-06 09:24 AM
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.
After compiling I get this:
When I flash this compiled code and read the flash memory I canclearly see that the memory usage is around 38 kB.
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?
Solved! Go to Solution.
2024-08-08 02:18 AM
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
2024-06-06 12:46 PM
SREC file is a text file. It's size is a little over 2 times the programmed Flash footprint.
2024-06-07 03:55 AM
Thank you very much, is there a way to reduce its size or to flash into memory a different file that woul dbe smaller?
2024-06-07 04:25 AM
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:
https://stackoverflow.com/questions/15265295/understanding-the-libc-init-array
2024-06-07 04:49 AM
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?
2024-06-07 05:12 AM
Show your Build Analyser output
2024-06-07 05:15 AM
Sure, here it is
2024-06-07 05:27 AM
@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?
2024-06-07 05:32 AM
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.
2024-06-07 05:37 AM
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?