2021-06-12 04:06 AM
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() :
TURN OFF HAL_ADC_Start_DMA() :
2021-06-12 05:43 AM
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.
2021-06-12 09:30 AM
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.
2021-06-13 04:00 AM
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...