LED Blink
Let's blink an LED on the STM32 board.
Code
Here is the full code to blink an LED on the STM32 board:
main.cpp
#include <Arduino.h>
#include <WSerial.h>
#define LED_PIN PC13
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
delay(5000);
Serial.println("Start!");
}
void loop() {
Serial.println("Turn on!");
digitalWrite(LED_PIN, HIGH);
delay(1000);
Serial.println("Turn off!");
digitalWrite(LED_PIN, LOW);
delay(1000);
}
For the Blackpill STM32 board, the LED pin is PC13
. You should change the pin according to your board.
platformio.ini
[env:genericSTM32F411CE]
platform = ststm32
board = genericSTM32F411CE
lib_archive = false
framework = arduino
upload_protocol = stlink
monitor_speed = 115200
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_SERIAL_WITHOUT_GENERIC
If you add the above build_flags
to the platformio.ini
file, you can read the serial monitor output with USB.