CMSIS and stm32cube frameworks results in different sized output files with the same program

I have been trying to compile a simple blink program with self written libraries for the bluepill boards. So I initially compiled this program with the stm32cube framework and got the output program at around 1780kB.

Then I got curious and switched over to a new project with the CMSIS framework. After configuring the .ini file, I compiled and shocked to find a very big program size of nearly 4888kb.

So I generated the map file for both programs and realised that the CMSIS framework is actually linking every functions(even the ones that I do not use) from my headers while as expected the stm32cube framework’s output file does not do this.

Any idea why this happens and what am I doing wrong?

Before someone asks me, here’s my platformio.ini file on cmsis, which is mostly identical with the stm32cube’s one, where the framework and board is different.


I am pretty convinced that this is not my fault, but I would like to be corrected if I am wrong also the right way to do this.

Thank you in advance.

You did mistake using optimization flag. It should be -O instead of -o.