2017-03-01 06:32 AM
Hi, can you tell me if it is normal that the stm32 hal use a lot of flash size. For exemple, just to setup the main clock, 3ko is used (3ko is the difference without the setup and with the setup). And when I use a lot of peripheral, the flash size of my program is huge ! I used gcc to compile.
Is there some option to reduce flash size or the stm32 HAL is not optimised. I used an stm32l0 with only 64kb and I use all of peripherals so it's very critic for me, the flash size.
Thanks !
2017-03-01 07:34 AM
The HAL is pretty bloated, especially if you use Cube. I am not surprised that the code size footprint is pretty big even with nothing in it.
2017-03-01 08:07 AM
The compiler has optimization options on the command like. GCC isn't known for the tightest code, and the Cortex-M0 has to implement more functionality in software to overcome the deficiencies in the hardware. There is going to be some buy-in cost to get libraries to work, but the HAL is a rather thick abstraction. You can choose not to use it.
Would suggest you review the .MAP to see what's contributing to the size, and build something more substantial to determine if the incremental cost of adding code scales better. The Keil compiler is free for STM32 Cortex-M0 parts, see if it does a better job.
2017-03-01 11:54 PM
Optimization is not really nice for Debugging. But if you need to shrink the Binary, you can also optimize only some of your Files and keep the Rest 'normal'. Give it a Try ...
2017-03-02 02:45 AM
I try the keil compiler, and the size is well optimised ! It is almost divided by 2. Thanks a lot !
2017-03-02 05:33 AM
I try the keil compiler, and the size is well optimised ! It is almost divided by 2.
One might be tempted to draw the conclusion that good compilers provoke sloppy coding habits ...
2017-03-02 05:50 AM
Optimization is usually only a problem there for people who insist on single stepping there own code to understand the logic and flow of it. Or fail to use the volatile keyword appropriately.
Optimizers frequently amplify flaws in coding to the point there become visible or gross. Ie initialization, data held in registers vs memory, reduced scope, etc.