Help Needed: Serial2 (PA10/PA9) on Nucleo L432KC Not Working Properly

I’m trying to get Serial2 working on my Nucleo L432KC, using PA10 (RX) and PA9 (TX). My goal is to verify that Serial2 is transmitting and receiving properly. However, I’m running into issues where:

  • I receive garbled characters (�� Serial2 Test Start).
  • Serial2 does not seem to be receiving any data.

I suspect a baud rate mismatch, pin mapping issue, or hardware limitation. I’ve tried different baud rates and swapping TX/RX connections, but the issue persists.

#include <Arduino.h>

// Define Serial2 explicitly on PA10 (RX) and PA9 (TX)
HardwareSerial ss(PA10, PA9);

void setup() {
Serial.begin(9600); // USB Serial for debugging
ss.begin(9600); // Initialize Serial2
delay(100);
Serial.println(“:white_check_mark: Serial2 Test Start”);
}

void loop() {
ss.write(‘A’); // Send ‘A’ every second
delay(1000);

if (ss.available()) {  // Read from Serial2
    char received = ss.read();
    Serial.print("📩 Serial2 Received: ");
    Serial.println(received);
}

}

What I’ve Tried So Far:

  1. Checked TX/RX wiring:
  • PA9 (TX) → FTDI RX
  • PA10 (RX) → FTDI TX
  • GND → GND
  1. Swapped TX and RX just in case
  2. Tested different baud rates (9600, 115200)
  3. Added a small delay (delay(100);) after ss.begin()
  4. Tried a different UART port (PA2/PA3), but no luck
  5. Tried a simpler sketch with just ss.println("Hello from Serial2!");, but still no response
    Checked PlatformIO settings in platformio.ini

[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc
framework = arduino
upload_protocol = stlink
monitor_port = COM2
monitor_speed = 9600
lib_deps =
Wire
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_HWSERIAL2