Skip to main content
Harryzhangpro
Associate
June 12, 2021
Question

HAL_ADC_Start_DMA() consume so many ROM with STM32F031 MCU & latest GCC compiler.

  • June 12, 2021
  • 3 replies
  • 1602 views

Hi!I am using STM32F031 MCU as my BLDC motor controler,I using "gcc-arm-none-eabi-10-2020-q4-major-win32.exe" as compiler and compile with -Ofast option.However,when i using HAL_ADC_Start_DMA(),the ROM of code almost fill up the MCU.is it normal?

TURN ON HAL_ADC_Start_DMA() :

0693W00000BaoBeQAJ.pngTURN OFF HAL_ADC_Start_DMA() :

0693W00000BaoBjQAJ.png

This topic has been closed for replies.

3 replies

TDK
June 12, 2021

It is what it is.

Compile with -O3 if you're concerned with size.

You could diff the map files to figure out what the difference is.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Scotty55
Associate II
June 12, 2021

It is a very bad idea to compile with -Ofast for a controller with so little resources and without cache. The bottleneck is NOT the ARM core performance, but the Program Flash access. I recommend to use the following compiler and linker settings:

-Os -ffast-math -fmessage-length=0 -ffunction-sections -fdata-sections -fsingle-precision-constant -Wall -Wextra -Wdouble-promotion

-Xlinker --gc-sections

For max. optimization use "-Os -flto", but this doesn't work with debugging as the optimization reorganizes the whole source code.

Piranha
Principal III
June 13, 2021

Indeed Ofast is the worst choice for size concerned applications and O3 is almost the same. O2 will be much smaller and is a nice speed/size compromise. And the smallest size of course will be reached by the Os with LTO.

Your problem is that you are using the broken bloatware named HAL. Take Amap and look what takes up the FLASH space. You'll be shocked to see that RCC functions are of a size of several KB! On the contrary a normal register based code takes 200 B to do the same job even better.

P.S. Name of the file utlis.c probably has a spelling error...