Hello, I am currently trying to make my stm32 + FTDI so make the serial port working.
with the following circuit:
I managed to make it working on the arduino IDE with the following configration:
And using Serial1 in the code.
Note that for uploading I use a ST-LINK V2 adapter
Now this is my platformIO config for this project
PlatfromIO does show the good serial port but I cannot find how to print anything
You explicitly enable the USB Serial (CDC), so by default Serial
will go to USB device. Not via UART (PA9/10).
What src/main.cpp code are you running on the STM32?
This is my code, nothing complicated
The constructor arguments look wrong, shouldn’t they be PA9
and PA10
instead of PA_9
, PA_10
?
To my knowledge, they are the same, but replacing them changes nothing
Okay, indeed both the int
version (PA9) and PinName
enum (PA_9
) are accepted. But RX and TX are reversed.
PA9 = Serial1 TX and PA10 = Serial1 RX
the constructor wants
aka, RX first, then TX.
So you should write
HardwareSerial Serial1(PA10, PA9);
Okay yes, my mistake.
how should I fix that ?
When I remove the problematic line, the code doesn’t compile
I wonder what should my platform.ini look like
I had problems with Serial1, solved it by adding the line
HardwareSerial Serial2(PA3, PA2);
After that, Serial1(PA10, PA9) worked fine, although I did not specify it at all. And I did not use Serial2, but it also works…
It happened by accident, I do not know the reason for this phenomenon.
Using STM32 HID Bootloader 2.2.2
Releases · Serasidis/STM32_HID_Bootloader (github.com)
\bin\stm32_binaries\stm32_binaries\F103\low_and_medium_density\hid_generic_pc13.bin
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
stm32 mcu based boards 2.8.1
Test code:
// test of STM32F103C8T6 board LED and serial
#define ledPin PC13
// hardware serial from https://github.com/stm32duino/wiki/wiki/API#hardwareserial
// RX TX
// HardwareSerial Serial1(PA10, PA9);
HardwareSerial Serial2(PA3, PA2);
// HardwareSerial Serial3(PB11, PB10);
void setup() {
pinMode(ledPin, OUTPUT);
Serial1.begin(9600);
Serial2.begin(9600);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
if (Serial) {
Serial.println("Hallo, World!");
}
if (Serial1) {
Serial1.println("Yeah, Science!");
}
if (Serial2) {
Serial2.println("Yeah, Science!");
}
}