Electronic – Using different UART pins on STM32 Nucleo

microcontrollernucleostm32

I am trying to use the STM32F103RB Nucleo board. I am learning how to do serial comms so started with the classic 'Hello world' printed to a serial monitor.

Eventually, I want to print data to the serial monitor, while receiving data via different UART pins. The Nucleo uses pins 16 & 17 (PA22 & PA3) as the default Tx/Rx pins. I started with them, and had no problem. The code was simple:

#include "mbed.h"

Serial pc(PA_2, PA_3);

int main() {
        pc.printf("Hello World \n");
}

Looking through the DATASHEET I can see that pins 42 & 43 (PA9 & PA10) can also be used for UART, with PA9 Tx, & PA10 Rx. I decided to change the pin definitions for Tx and Rx, so the code now looked like this:

#include "mbed.h"

Serial pc(PA_9, PA_10);

int main() {
        pc.printf("Hello World \n");
}

And this now doesn't work. Looking through THIS PAGE I don't see why that doesn't work. I have used 'Serial', given it a name (pc), then defined the Tx and Rx pins. I am using the mBed online environment if that makes a difference to anything.

Can anyone see if there is some simple mistakle or something I have overlooked when trying to do what should be a simple task?

If there is any more information required, please ask.

Best Answer

Along with SWD flashing, the debug interface chip on the Nucleo provides a USB<>serial functionality to allow the target chip to communicate with a PC.

But this functionality is hard wired to the default UART pins of the target.

If you wish to use different UART pins, you will need something to connect those to your PC as well or instead - either an external 3v3 USB-UART, or to somehow rewire the on board one.

The signals to the on-board one are routed via resistors which can be removed, and there are header footprints which could help with re-routing. For the 64-pin STM32 Nucleo, these can be seen in the schematic (circled in red).

enter image description here