STM32 Bluepill PWM Frequency

Hey Guys,
I’ve been experimenting a bit with the SimpleFOC library and so far I am very impressed.
However I have encountered a problem that I have not been able to fix.
I am using a regular STM32 “Bluepill” and I wasn’t able to increase the PWM frequency, which is currently at around 549 Hz. That’s why my Nema 34 Stepper is making a lot of noise.
Is it because of the stm32_mcu.cpp file or because I am using maple core?
This is my platformio.ini file:
platform = ststm32
board = genericSTM32F103C8
framework = arduino
board_build.core = maple
lib_deps =
askuric/Simple FOC@^2.1

The driver is connected to pins PB6, PB7, PB8, PB9 and the enable pins are connected to pins PA1 and PA2.

I also tried: driver.pwm_frequency = 25000;, which didn’t work.
Thanks in advance for your help.

Any reason you are using maple? stm32_mcu.cpp makes use of HAL and LL libraries that aren’t (i believe) available on maple. My suspicion is that maple doesn’t set #defined _STM32_DEF_ and therefore your board is running generic_mcu.cpp and not stm32_mcu.cpp.

1 Like

Thanks for your quick reply.
That was exactly the problem.
I was using maple because I needed 2 more PWM pins with a PWM frequency above 20kHz and maple makes it easy to do that.
Now I am not using the maple core anymore and I am using:
_writeDutyCycle2PWM(float dc_a, float dc_b, int pinA, int pinB) , which is implemented in the SimpleFOC library to set the duty cycle on the 2 pins and it works perfectly fine.

1 Like