Mbed-os: Changing default serial port conflicts with other serial ports

Created on 28 Aug 2020  路  10Comments  路  Source: ARMmbed/mbed-os

Description of defect


My target is a Nucleo F103RB board and I want to use two serial ports. One is a USB port and a USART1 serial.
I'm trying to change the default serial pins for printf as described in here to use with USART1 instead of default USB and manually initialize USB serial in my code.

Target(s) affected by this defect ?

STM32F103RBT6

Toolchain(s) (name and version) displaying this defect ?

GNU gdb (GNU Arm Embedded Toolchain 9-2020-q2-update

What version of Mbed-os are you using (tag or sha) ?

mbed-os 6.2.0

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

mbed-cli 1.10.1

How is this defect reproduced ?

mbed_app.json:

{
    "requires": ["bare-metal"],
    "macros": [
        "MBED_HEAP_STATS_ENABLED=1",
        "MBED_STACK_STATS_ENABLED=1",
        "MBED_MEM_TRACING_ENABLED=1"
    ],
    "target_overrides": {
        "*": {
            "target.c_lib": "small",
            "target.printf_lib": "minimal-printf",
            "platform.minimal-printf-enable-floating-point": false,
            "platform.stdio-baud-rate": 115200,
            "target.stdio_uart_tx": "PA_9",
            "target.stdio_uart_rx": "PA_10"
        }
    }
}

Sample code:

#include "mbed.h"

static BufferedSerial USBSerial(USBTX, USBRX, 115200);

int main()
{
    const char* msg = "Message from USB Serial\r\n";
    USBSerial.write(msg, strlen(msg));
    // This should print to USART1
    printf("Message from USART1\r\n");
}

I get no results in the USB port and get both outputs in USART1:

22:49:13.109 -> Message from USB Serial
22:49:13.109 -> Message from USART1

CLOSED st bug

Most helpful comment

What I said is that issue is USBTX is defined as "target.stdio_uart_tx",
so whatever the stdio_uart_tx value you set in json, USBTX will follow...

Solution is to not use USBTX name, use USBSerial(PA_2, PA_3, 115200)

All 10 comments

@masoudr thank you for raising this issue.Please take a look at the following comments:

We cannot automatically identify a release based on the version of Mbed OS that you have provided.
Please provide either a single valid sha of the form #abcde12 or #3b8265d70af32261311a06e423ca33434d8d80de
or a single valid release tag of the form mbed-os-x.y.z .
E.g. '6.2' has not been matched as a valid tag or sha.It would help if you could also specify the versions of any tools you are using?

NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'.This indicates to us that at least all the fields have been considered.
Please update the issue header with the missing information, the issue will not be mirroredto our internal defect tracking system or investigated until this has been fully resolved.

@ciarmcom I've updated the issue. I think it is been completed now.

Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers.
Internal Jira reference: https://jira.arm.com/browse/MBOTRIAGE-2807

Hi @masoudr

From
https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32F1/TARGET_STM32F103xB/TARGET_NUCLEO_F103RB/PinNames.h#L126-L148

here is my understanding...

Default configuration:
STDIO_UART_TX = PA_2,
STDIO_UART_RX = PA_3,
USBTX = STDIO_UART_TX,
USBRX = STDIO_UART_RX,
So, USBSerial and printf mapped to UART2

With
"target.stdio_uart_tx": "PA_9",
"target.stdio_uart_rx": "PA_10"
STDIO_UART_TX = MBED_CONF_TARGET_STDIO_UART_TX,
STDIO_UART_RX = MBED_CONF_TARGET_STDIO_UART_RX,
USBTX = STDIO_UART_TX,
USBRX = STDIO_UART_RX,
So, USBSerial and printf mapped to UART1...

Could you try to change your code like this?
static BufferedSerial USBSerial(PA_2, PA_3, 115200);

Currently, I removed the pin configuration from mbed_app.json and created two buffers like this:

static BufferedSerial USBSerial(USBTX, USBRX, 115200);
static BufferedSerial DebugSerial(PA_9, PA_10, 115200);

Then I have separate data lines in both USB connection and UART1 pins and works fine without any conflict.
This chip has a separate USB connection that is connected to USB Pins (USBDM and USBDP equivalent to PA11 and PA12).
I thought that in the Nucleo board they connected the USB connector directly to those pins but I was wrong.
Is there any way so I can use serial on USB connection? I found this but it seems that it doesn't work on mbed-os 6.

You can use USB pins after #13406 integration :-)

Correct mbed documentation page is
https://os.mbed.com/docs/mbed-os/v6.2/apis/usbserial.html

@masoudr is this all resolved with following references or there is still an issue to be fixed?

@0xc0170 There was misunderstood with me about USBSerial but I'm still haven't convinced about the configuration because when I set these

{
      "target.stdio_uart_tx": "PA_9",
      "target.stdio_uart_rx": "PA_10"
}

It should set the default serial to UART1. And when I set static BufferedSerial USBSerial(USBTX, USBRX, 115200); I'm setting the UART2 serial. So as @jeromecoutant said if I change a serial port in mbed_app.json it would map USBTX and USBRX to those pins which I think is wrong.

What I said is that issue is USBTX is defined as "target.stdio_uart_tx",
so whatever the stdio_uart_tx value you set in json, USBTX will follow...

Solution is to not use USBTX name, use USBSerial(PA_2, PA_3, 115200)

I'll close as resolved

Was this page helpful?
0 / 5 - 0 ratings