Define hardware serial for ST MCU

I’m new to PlatformIO so trying to get my sea legs. I’ve search through the forum and haven’t found directions on this. Here is an example of what i’m trying to do. I’m using a ST disco_l072cz_lrwan1 board. I’ve got it set to use the arduino framework at the moment. I can communicate with the board and flash code without issue. The terminal is working just fine with “Serial” print commands. What i’m trying to do is access other hardware serial ports of the MCU, in this case Serial1 on pins PA9 & PA10.

I’ve tried just " Serial1.begin(4800);" but throws an error that Serial1 is not defined, so I suspect I need to updated some hardware definitions for this MCU to get it to work. What i’m not clear on his how I go about that in PlatformIO. Any guidance would be great.

I’m not in the inner circle and I’ve run into this issue with a few boards. I have a Nucleo_F302R8 board that is supposed to have 2 additional hardware serial ports, under the stmduino build environments. My example is missing Serial1 object all together and Serial2 doesn’t seem to work.

I just moved the project over to mbed.

Interesting. I was trying to see if I could find where it’s defined but so far no luck. Maybe I will try moving over to MBED too.

Did more digging on the stm32duino Github site and found via a logged “issue” how to do it. Here is the link: Define Two Serial ports · Issue #230 · stm32duino/Arduino_Core_STM32 · GitHub

They should add these types of notes in the docs :slight_smile:

In my case here is all that I had to add (I am using it for a GPS):

#define GPS_UART_TX PA9
#define GPS_UART_RX PA10
HardwareSerial SerialGPS(GPS_UART_RX, GPS_UART_TX);

1 Like