1 year, 9 months ago.

Serial 2 Port problem with NUCLEO-L432KC


I'm using a NUCLEO-L432KC in order to construct an embedded system (that means I want to connect a bunch of sensors & modules to the card). At the moment, I'd like to use Serial Port 1 (PA_9 & PA_10) to connect to a GPS module, Serial Port 2 (PA_2 & PA_3) to connect to a Sigfox telecommunications module, and the USB RX & TX to print debugging information to my computer. However, Serial Port 2 doesn't seem to work. I've updated the NUCLEO's firmware to the latest version, made sure to update the "mbed" library and compiled all the files, but I still get an mbed-os error in serial (I can also tell by a LED blinking on the card, which happens every time there's an mbed-os error). The error is:

mbed-os error

-- MbedOS Error Info --

                                                                ++ MbedOS Error Info ++
       Error Status: 0x80010130 Code: 304 Module: 1
                                                   Error Message: pinmap not found for peripheral
                 Location: 0x8005D1D
                                    Error Value: 0xFFFFFFFF
                                                           Current Thread: Id: 0xFFFFFFFF Entry: 0x2 StackSize: 0x0 StackMem: 0x0 SP: 0x800723C

Here is my code to test the port 2:

Test code for the Serial Port 2 (import mbed library of course)

#include "mbed.h"

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

DigitalOut myled(LED1);

int main ()
    int i = 1;
    pc.printf("Hello World !\r\n");
    while (1) {
        pc.printf("This program has been running for %d seconds.\r\n", i++);
        myled = !myled;

Does anyone know how to solve this?

2 Answers

1 year, 9 months ago.

Dimitris -

The STM32L432KC MCU on the NUCLEO-L432KC has only 2 USARTs, so your basic architecture requiring 3 USARTs won't work.

You don't say what Sigfox module you are using, but many appear to offer SPI and I2C communication in addition to a USART interface. For example, you could use UART_1 (PA_9 and PA_10) for the GPS module, the default USB serial port (PA_2 and PA_15 through the ST-Link) for debugging and SPI_3 (eg. PB_3, PB_4, PB_5 and PA_11 for nCS) for communication with an SPI-compatible SigFox.

Note that the solder bridges on the NUCLEO-L432KC board come pre-configured for Arduino Nano connectivity. This may require you to remove some solder bridges (eg. SB16 and S18) if you want to make full use of the pins available on CN3 and CN4. Details for configuring the solder bridges are in the User Manual (UM1956) for the NUCLEO-L432KC board. Zoltan provided a link to UM1956 in his response.

Accepted Answer
1 year, 9 months ago.

Hello Dimitris,

SerialPort2 is initially (by default) used for serial communication over the USB cable connected to the PC (as mbed virtual serial port). So when we create a SerialPort object, for example as below:



Serial pc(USBTX, USBRX);

then the mbed code (provided in the mbed library) will recognize, based on the pin names passed to the constructor, that SerialPort2 shall be used (this is defined by the files you can find in the folders indicated on the NUCLEO-L432KC mbed page). And because those pins, on a NUCLEO-L432KC board, are physically connected also to the other chip located on the board and used for serial communiction over the the USB connector (for pin PA_2, which is available at the CN4 connector, this is indicated by highlighting its pin name backround in dark blue color - see the pin legend), we cannot use them for our own design. I think that PA_3 is indicated in the pinout picture as UART2_RX by mistake, since that definition is commented out in the PeripheralPins.c file (I think that the reported error is most likely caused by missing UART RX pinmap for pin PA_3). However, because PinMap_UART_TX[] and PinMap_UART_RX[] are defined as weak (MBED_WEAK) in the PeripheralPins.c file, you can try to define your own PinMap_UART_TX[] and PinMap_UART_RX[] in your code (remember to omit the MBED_WEAK specifier) which will override the original ones. But I'm afraid that you won't be able to find other than pin PA_2 to configure as TX pin for SerialPort2. Nevertheless, according chapter 6.9 "USART virtual communication" of the User manual the PA_2 pin is connected to the USB serial communication chip over the SB2 solder bridge. So when this solder bridge is OFF (ON by default) we should be able to use Serial2 (USART2) for user projects. But at the cost of loosing the virtual serial port.

After checking the datasheet I think we can use both Serial1 (USART1) and Serial2 (USART2) ports in user projects if we turn off (open) solder bridges SB2 and SB3 and add the following code to the main.cpp:

#include "mbed.h"

const PinMap PinMap_UART_TX[] = {
    {PA_2,       UART_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},  // Disconnected from STDIO_UART_TX by opening SB2
    {NC, NC, 0}

const PinMap PinMap_UART_RX[] = {
    {PA_3,       UART_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},  // Not connected to STDIO_UART_RX 
//  {PA_15,      UART_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_USART2)},  // Disconnected from STDIO_UART_RX by opening SB3
    {NC, NC, 0}

Serial  serial1(PA_9, PA_10);
Serial  serial2(PA_2, PA_3);

// ...

But as I already said, at the cost of loosing the virtual serial port. And that means no bebug messages on the PC during the development :-(

posted by Zoltan Hudak 08 Oct 2018