2021-12-11 12:30 AM
Hello,
I use STM32IDE to programmer for STM32F030K6, when i call the function in the main function or interrupt function, it consumes a lot of Flash.I have already changed the optimization option. But it doesn't work.
I try again with Keil C and this error does not occur, the code size is well optimized.
Can you guys tell me what I did wrong? Thanks you all!
2021-12-11 01:40 AM
I don't see any striking difference in FLASH consumption (17kB vs 13kB), nor in RAM consumption (3kB vs 2.5kB). Keil is simply better in optimization, that's all.
JW
2021-12-11 03:11 AM
Thank for your answer. Sorry for misleading you. With STM32Cube I have many function calls disabled so it only consume 17KB flash, if I enable them all it consumes 31KB of flash. Here is the result when i build full project with STM32IDE
And here is the result when i build full project with Keil C:
2021-12-11 03:28 AM
You have SSD1306, probably a bitmap screen, with bitmap font, strings, menu, etc.. lots of flash data.
If you want to see the details generate the MAP file from the linker. You will see how much code, rom data, ram data you consume PER function
Some compilers/linker will try to smartly factorize share some of the ROM data if used by pointers.
Ideally, use something simple like RLE compression for your strings or bitmap as I suspect it's the #1 memory hungry contributor.
2021-12-11 07:21 AM
There are other options besides -O3 to optimize code size. Change the build configuration to Release and try.
I'm unfamiliar with Keil, but wouldn't all of "code", "ro-data", and "rw-data" sections be put into FLASH? Wouldn't that make the total ~20kB?
Here's a random project compiled with different options. Release is less than Debug with -O3:
Debug:
text data bss dec hex filename
11440 10260 1844 23544 5bf8 ***.elf
Debug with -O3:
text data bss dec hex filename
7184 10260 1844 19288 4b58 ***.elf
Release:
text data bss dec hex filename
6664 10260 1844 18768 4950 ***.elf
Examining usage per-function or per-variable would likely yield more informative results.
2021-12-11 06:17 PM
Hello, do you mean i choose this option? The results do not change.
2021-12-11 07:48 PM
The problem is not from SSD1306, i realized that when i call the function it consumes flash a lot.
2022-01-09 01:09 PM
Only the Os optimizes code for size. All other options optimize for speed. O2 is a good compromise and O3 and Ofast are the fastest and biggest ones.
Probably the real problem is using printf() functions from the Newlib library. Those take several KB and adding float support adds another 10+ KB. Also those pull in malloc() and add 2 KB of initialized data to the FLASH memory.
2022-01-09 05:26 PM
Thanks a lot for your answer, but how can i fix it? I do not know what to do.
2022-01-09 05:41 PM
Your screenshot shows the memory usage is still from the Debug build. You need to rebuild the project for it to update.