STM32 bluepill pwm frequency - another question

Hi, I am testing with a STM32F103 and realised that PWM frequency is 1 kHz but I would have expected 25 kHz as set in the MCU specific header. I am using platformio and have nothing special in the ini file:

[env:bluepill_f103c8_128k]
platform = ststm32
board = bluepill_f103c8_128k
framework = arduino
upload_protocol = stlink
monitor_speed = 115200
lib_deps = askuric/Simple FOC@2.2

when I click through the code I end up in the correct line in stm32_mcu.cpp (I think).

What is missing / incorrect?

I would also expect that one should use specific pins to use the timers efficiently but couldn’t find any hint - have used according to example
BLDCDriver3PWM driver = BLDCDriver3PWM(PB6, PB7, PB8, PB5);

Thanks!

Hi and welcome @Lutz1967 !

Please add the option lib_archive = false to your platformio.ini

That should help matters with your PWM frequency :slight_smile:

1 Like

Thanks! Will test tonight. Could you explain what the problem is?

It’s some kind of difference in the compiler setups.

SimpleFOC supports many kinds of hardware, and has implementations for the PWM-driver functions for each hardware type (AtmelAVR, STM32, SAMD21, RP2040, etc).
There is also a “generic” implementation which just uses analogWrite() and relies on the Arduino framework to set the PWM. This results in the bad 1kHz PWM performance on most boards.
The code selects the correct option using a C/C++ construct called “weak bindings”.

When using platformIO, you need this option, or the linker gets confused and incorrectly binds the generic, weakly bound implementation.
When using ArduinoIDE the linker does the right thing and binds the hardware-specific implementation by default.

1 Like

Thanks a lot! Worked perfectly! If it is not written in the docs already (and I just missed it) I hope it gets noted.

It’s there on the PlatformIO page, but I should make it a lot more prominent… many people face this issue…