Page 2 of 2

Re: USART on STM32F411 BlackPill

Posted: Wed Feb 09, 2022 12:39 pm
by ag123
hardware serial is that hardware uart in the stm32, this is basically an api to access the hardware.
there are specific pins for each uart.
you would need to review the spec sheets for your mcu and the ref manual to determine what those pins are.

and yes you can use all 3 uarts i.e. Serial1, Serial2, Serial3 if you'd like.
The pins needs to be mapped correctly and HardwareSerial needs to be initialised correctly.

you can make a protocol that use all 3 of them, e.g. modbus
https://en.wikipedia.org/wiki/Modbus
https://modbus.org/

And you still have your usb (CDC) serial (i.e. Serial) on your virtual comm port. That goes to your host / pc.

Re: USART on STM32F411 BlackPill

Posted: Wed Feb 09, 2022 5:09 pm
by GonzoG
Olareanu wrote: Wed Feb 09, 2022 11:43 am (...)
Somewhat unrelated: On the chip manufacturer's website (https://www.st.com/en/microcontrollers- ... 2f411.html), it says that the stm32f411 supports 3 USARTs and an USB 2.0 OTG. Does that mean you can start 3 diffrent Serial connections and the USB at once or is one of the USARTs taken up by the USB?
No, you cannot use all 3 UARTS and USB. UART6 uses same pins as USB (PA11 and PA12)

Re: USART on STM32F411 BlackPill

Posted: Tue Feb 22, 2022 10:39 pm
by batoaqaa
You only need to define hardware serial in platformio.ini file:
[env:blackpill_f401cc]
platform = ststm32
board = blackpill_f401cc
framework = arduino
upload_protocol = dfu
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D ENABLE_HWSERIAL2 ;Enable hardware serial2 <=====
-D PIN_SERIAL2_RX=PB7 ;default PA3 <== if you want to change the default RX
-D PIN_SERIAL2_TX=PB6 ;default PA2 <==


Then you can use Serial2 normal way as:
#include <Arduino.h>
void setup() {
Serial2.begin(9600);
pinMode(PC13, OUTPUT);
}

void loop() {
digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Serial2.println("Hello World");
}