cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMx size of generated code problem

Serge Lopez
Associate II
Posted on December 21, 2017 at 14:44

I am wroking on a project  using two microcontrollers a STM32F412 and a STM32L011 (8K flash, 2k RAM) .The STM32L011 is used as RTC to manage the power comsumption of the STM32F412. 

I used STM32CubeMx to generate the code to set the peripherics  that I use within the L011 (I2C, RTC, RCC). The problem is the size of the generated code once compiled is bigger than the 8k available inside the flash of the L011.

I only compile the genretaded code without writting a line of code.!

How could be possible to get a bigger code than the place to stored it for a defined STM32?

I think I did something wrong but I can find what is wrong.

Someone could provide me any ideas to resolve this situation. (i can not change the micro)

You will find in attachment the .ioc file. The genrated code from STM32Cube Mx is trasnfered on  a Eclipse platform 

and is used GNU ARM tools.

.Thanks in advance for your help

Best regards

Serge LOPEZ

#stm32cubemx #stm32l0xx #program-size
25 REPLIES 25
Posted on January 11, 2018 at 10:45

You're not using floating-point maths, are you ... ?

(and beware that Cube/HAL isn't sneaking it in through the back door)

Yes, definitely worth to check for that.

I don't use Cube, for this and other reasons (yes, and I repeat it ever time ...).

Another option is a better toolchain.

The Keil compiler, AFAIK, produces best results in regard to code size. IAR WB is not bad either.

But this might prove futile as well when you need to add another 'very important' feature - and you are again beyond the limits.

Versions of the STM32L011 with more Flash (16k instead of 8k) exist, so the swap would be rather painless.

Posted on January 11, 2018 at 11:04

I use Keil MicroLib often to reduce code size.

Posted on January 11, 2018 at 11:12

The only problem I see lack of good documentation for LL. If someone does not study datasheet carefully he/she may have a problem with using them. The HAL documentation at least shows how to use the drivers. Here, in case of LL, we can either study examples or staty datasheet. The latter is better but for requires some time.

Even such simple tick like starting SystTick (for HAL it's an easy task automated through CubeMX) in LL requires to debug the app to discover that IT is not enabled and you need to add extra function to enable it.

I would suggest adding better documentation how to use the LL drivers to avoid reverse engineering;)

Posted on January 11, 2018 at 11:15

I hope that someone with better experience/understanding of will correct my opinion about LL.

Besides I think the LL is good thing (it made me study the datasheet)

Posted on January 11, 2018 at 17:20

Today, LL can be used entirely stand-alone, but I'm pretty sure that you won't allow this for too long. I suppose LL will be soon only a subset of HAL, and using HAL will be the only way to create a project in a supported IDE.  

It would be wise to keep the actual versions of CubeMX and the HAL drivers, archiving them on DVD and then carefully testing the new versions.

Posted on January 11, 2018 at 18:05

Right, I was thinking the same about keeping old CubeMX version. ST should share the older versions.

Posted on January 12, 2018 at 20:55

Try changing the values using ''STM32CubeMx'':

0690X00000609MFQAY.png

The default setting is:

_Min_Heap_Size = 0x200;

_Min_Stack_Size = 0x400;

or 1536 bytes reserved. (75% of 2048).

reduce to:

_Min_Heap_Size = 0x100;

_Min_Stack_Size = 0x200;

or

_Min_Heap_Size = 0x000;

_Min_Stack_Size = 0x200;

Posted on January 12, 2018 at 21:02

I guess care should be taken when playing with stack and the heap. Can reduce the values of these based on the app requirements. e.g. if you allocate an array of 0x200 bytes inside a function (main() is function as well) your app probably crashes as  the stack is used by the array.... Also when you use malloc() or dynamic array you can run into trouble with heap when underestimated.  Also need to take care when using foreign libs when we do not know what are exact requirements.

Posted on January 12, 2018 at 22:49

Apologies for jumping in, but have you found any documentation of the runtime library of Keil for ARM- description of functions, explanation what is the MicroLib at all? Is the source of the libraries available?

-- pa

Posted on January 22, 2018 at 15:20

Hello Andrew,

Thansk for your answer. I doesn't use floating point