cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 HAL Peripherals Using too Much FLASH Memory

rbenfichera
Associate II

Hi Folks, 

I am using a STM32F070F6P6 microcontroller for a very basic/simple project to help learn the STM32 platform, etc.

I am getting an error when I attempt to build my project that my code overflows FLASH memory by quite a bit.  I did a test on a new project, and even without any personal code of my own, if I try to compile the exact same build, the USB middleware overflows my FLASH memory by a ton.  I am only using I2C and USB peripheral in my project.

Does this seem abnormal? Am I doing something wrong?  It doesn't seem right to me that these add-ins themselves should be enough to overflow the FLASH memory size when I haven't even written a single line of code.  

Are there any steps you usually take to optimize the code?

rbenfichera_1-1721052980296.png

 

 

rbenfichera_0-1721052958071.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

>Why is 32KB not a clever decision for USB?

F07x can have 128K + 16K :

AScha3_0-1721066876611.png

This is ok for using USB , but still a "small" cpu for such use .

I just tried using a F103C8 , 64K flash + 20K ram. (I would say: minimum for simple USB , like CDC device.)

It needs (with -O2 ) : (all ram i use is about 8 byte, for test CDC , send: "check ! \n " )

AScha3_1-1721067197653.png

If you wanna play the "can i get USB device with 6K ram running" game  - ok, maybe using other USB stack, it could work.

see or try: https://github.com/hathach/tinyusb

 

>Why would STM32 offer it if it were a bad idea?

Maybe for an USB charger this 90ct version is a cheap solution (= good idea) - but for more, need the bigger 128/16K version.

AScha3_2-1721067687796.png

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
AScha.3
Chief II

Hi,

try : set optimizer -O2  , in IDE -> project-> properties

see:

AScha3_0-1721054831061.png

For F103 with USB->CDC device i get 23KB flash used.

btw  just a 32KB cpu is NOT clever decision for anything like USB ...

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for the reply.  Why is 32KB not a clever decision for USB?  Why would STM32 offer it if it were a bad idea?

Chris21
Senior

ST offers microcontrollers with wide ranges of memory sizes and peripherals.  Certainly some people apply devices like STM32F07 but don't use USB and therefore don't need memory for a USB stack.

>Why is 32KB not a clever decision for USB?

F07x can have 128K + 16K :

AScha3_0-1721066876611.png

This is ok for using USB , but still a "small" cpu for such use .

I just tried using a F103C8 , 64K flash + 20K ram. (I would say: minimum for simple USB , like CDC device.)

It needs (with -O2 ) : (all ram i use is about 8 byte, for test CDC , send: "check ! \n " )

AScha3_1-1721067197653.png

If you wanna play the "can i get USB device with 6K ram running" game  - ok, maybe using other USB stack, it could work.

see or try: https://github.com/hathach/tinyusb

 

>Why would STM32 offer it if it were a bad idea?

Maybe for an USB charger this 90ct version is a cheap solution (= good idea) - but for more, need the bigger 128/16K version.

AScha3_2-1721067687796.png

 

If you feel a post has answered your question, please click "Accept as Solution".

Thank you and all else for the very informative answers.

Watch also if anything pulls in the floating point libraries, these too can have quite a large up-front cost.

You might want to try building with the Keil MDK, there's a free license for STM CM0(+) parts and you might be able to play games with optimization, dead code removal, and link time optimization. LTO is a multi-pass compile/link, which again tries to identify dead code, and the minimal working set.

I've used some L011 (16KB) parts, but honestly it too tight to do much of anything, and I'm not attempting to pull in the USB stack. We liked the 20-pin square part, but this an exact fit C0 or G0 with more memory which I'd look to move too.

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