Hello together,
I’m currently trying to switch from Arduino IDE to PlatformIO and have a problem, that drives me nuts. I hope, someone can help me.
As stated in the topic, I’m using a STM32 Blue Pill with F103C8T6 MCU as development board. Here is the code I’m using for a first test:
#include <Arduino.h>
void setup() {
pinMode(PB6, PWM);
pwmWrite(PB6, 32767);
}
void loop() {
}
My platformio.ini file looks like this:
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = serial
According to the Leaf Labs Documentation (pinMode() — Maple v0.0.12 Documentation ) this should give me a PWM signal with a duty cycle of 50 % at around 500 Hz.
The problem: The compiler doesn’t recognize neither the “PWM” pin mode nor the “pwmWrite” function. When I use the same code in the Arduino IDE, it works just fine.
I have tried to change the .ini file to the following (found somewhere here in the forum):
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
board_build.mcu = stm32f103c8t6 //tested with and without this line; makes no difference
board_build.core = maple
upload_protocol = serial
With these two changes, the PWM pin mode and the pwmWrite function are both recognized and the program compiles without a problem, but nothing happens on the specified pin (or any other pin; checked with my scope)
So in this combination the syntax is accepted, but the pin mapping seems to be wrong. I have also tried to swap the PB6 pin designator with 42 according to the pinout diagram of the Blue Pill, but that doesn’t work either.
Just for verifying that the upload works correct: If I use a code like this
#include <Arduino.h>
void setup() {
pinMode(PB6, OUTPUT);
analogWrite(PB6, 128);
}
void loop() {
}
with the .ini-file like this
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = serial
I get a beautiful square wave with a duty cycle of 50 % and a frequency of 1 kHz (by the way: Why is that? Without modifying the prescaler and/or overflow of the responsible timer, the frequency should be around +/- 500 Hz…)
So my upload works just fine.
In short: How can I use the “advanced” functions of the Blue Pill (in comparison with an Arduino Nano), according to the Leaf Labs documentation? For me the whole point at the STM32 MCU is the higher timer and therefore PWM resolution. Later I also will have to use these functions
HardwareTimer timer(X)
timersetPrescaleFactor(Y);
timer.setOverflow(Z);
to configure the PWM output as I need it.
Hours and hours with Google and the search function in this forum couldn’t help me, so can PLEASE someone explain how I can get this running?
In case it matters: For uploading I use a FTDI adapter and I’m running PlatformIO on Linux Mint 19.3 Cinnamon.
Many thanks in advance and my apologies for the lengthy explanation and the maybe crude english, I’m not a native speaker.
Regards, Hagen