STM32F10X Keil to Platformio running at different frequencies

I am switching from Keil, which I originally use <stm32f10x.h> for a stm32f103c8t6
to PlatformIO, now using <stm32f103xb.h> as header.

Everything works fine initially, until I realize when uploading the the program to a blackpill_f103c8, the writing address is different and it also took up more memory(Check Edit1). This lead to the program timings differ from if I uploaded with keil.

A blinking LED uploaded with keil is 1s, while the same program on platformio seems to take up to 10s.

Here’s my platformio.ini

[env:blackpill_f103c8]
platform = ststm32
board = blackpill_f103c8
framework = cmsis
upload_protocol = serial
upload_port = COM7
board_build.mcu = stm32f103c8t6
board_build.f_cpu = 72000000L

This is using the CMSIS framework

Does anyone know what could be wrong or have experience solving this?

Edit1: So I tried to flash the fireware.bin made by platformio and now matches the results from my keil hex file. However, the frequency that the program’s running is still does not match.

The CMSIS framework does not configure the clock, it’ll be at its power-on default.
Maybe framework = stm32cube does, I’m not sure.

So what you’re seeing is that delays are calculated as if the system is running at 72 MHz, but it’s actually running 9x slower, at the default 8 MHz HSI clock rate, i.e. 9s iso 1s blinks.

1 Like

This just creates a macro F_CPU with value 72000000L, it does not configure the clock beyond that. As said above, when using framework = cmsis, you only get the extreme bare-bones CMSIS headers supplied by STM, all clock config has to be done manually in the code.