cancel
Showing results for 
Search instead for 
Did you mean: 

HAL flash size

david lion
Associate II
Posted on March 01, 2017 at 15:32

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 ! 

6 REPLIES 6
achin
Associate II
Posted on March 01, 2017 at 16:34

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. 

Posted on March 01, 2017 at 17:07

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Nor Sch
Associate III
Posted on March 02, 2017 at 08:54

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 ...

david lion
Associate II
Posted on March 02, 2017 at 11:45

I try the keil compiler, and the size is well optimised ! It is almost divided by 2. Thanks a lot ! 

Posted on March 02, 2017 at 13:33

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 ...

Posted on March 02, 2017 at 13:50

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.

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