True UART Vs Virtual Comm port over STLink

02 Sep 2015

I have the Virtual comm port running ok in this code below:

#include "mbed.h"

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);
//Serial pc(PA_2, PA_3);


int main()
{
    int i = 0;
    pc.printf("Hello World !\n");
    while(1) {
        wait(0.1);
        pc.printf("Counter %d %x\n", i++,i);
    }
}

but when I try to use the true serial port, UART PA_2 and PA_3 as coded here below, the data is still coming out of the Virtual comm port.

#include "mbed.h"

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

//Serial pc(SERIAL_TX, SERIAL_RX);
Serial pc(PA_2, PA_3);


int main()
{
    int i = 0;
    pc.printf("Hello World !\n");
    while(1) {
        wait(0.1);
        pc.printf("Counter %d %x\n", i++,i);
    }
}

02 Sep 2015

Serial_TX/RX, USBTX/RX, PA_2/PA_3 and D0/D1 are all aliases of exactly the same pins: You didn't actually change your program :).

They will always go to the virtual serial port. It is also possible to route them in addition to that to D0/D1 (PA_2/PA_3). I think in the Nucleo manual it is shown which jumper/connection you need to make to have that connection work.

Some background: A long time ago, in a galaxy far away, someone made the Arduino platform. This made alot of people sad :P. (Mainly that the Arduino pinout isn't on the 2.54mm grid because someone worked late, made an error, no one catched it, and now we are all stuck with off-grid Arduino connectors). The Atmega used for the Arduino only has a single Serial connection on one set of pins: So it needed to be shared between the virtual one, and D0/D1. On Arduino you can use either set by default, but obviously not both at the same time.

Now fast forward to ARM boards with Arduino layout, and manufacturers simply don't realise that that sharing of the UART is not a feature, but an unwanted necesity. So they implement the same, even though it is stupid and makes no sense. To be fair: Freescale also did this initially, but they finally realised it was actually pretty stupid and their newer boards use a different UART with different pins for the virtual com port.

02 Sep 2015

Thanks Erik,

ok. I found the document, links SB6263 ON and SB13..14 OFF, but that just moves the one serial port (USART2) from the virtual link to the real connector.

How do I access another serial port (USART3) ? the pins exist, how do I make the software access USART3 ?

02 Sep 2015

Make a Serial object to whichever pins you want, it will automatically select an USART for it.

02 Sep 2015

I adjusted the code, we have 4 separate serial ports now, thanks.

Serial Usart1(PA_9, PA_10); Serial Usart2(PA_2, PA_3); Serial Usart3(PB_10, PB_11); Serial Usart4(PA_0, PA_1);

Thanks again Erik...