This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding UARTE1 to CLI OpenThread Example

Hi everyone,

I wanted to add a second UART (UARTE1) to the CLI example in the OpenThread SDK 0.10.0 since UART0 is used by CLI but I was not able to find any documentation on using two UARTs at the same time other than a clue in the header file "app_uart.h" where it states:

"[app_uart_init(...)]: Function for initializing the UART module. Use this initialization when several instances of the UART module are needed."

Does this mean you initiate the UART twice using the above function? Another question I have is can the CLI example have multiple UARTs (I noticed a macro flag '-DUART_ENABLED=0' and was wondering if UART settings are to be disabled fully from the user's control)?

Any help would be greatly appreciated.

Thank you.

  • I would like to receive bytes from a COM port connected through the USB cable plugged into the nRF52840. I'm not sure I follow correctly but to my understanding I'm still using the same NRF_LOG_BACKEND_SERIAL_UART_TX_PIN 6 and NRF_LOG_BACKEND_SERIAL_UART_RX_PIN 8 pins. Can you please provide an example to "If you want to use another instance of UART, you need to choose other, unused pins to initialize the UART instance"?

  • If you want to communicate with a nRF52840 through the SEGGER J-LINK COM port, you have to use those pins. But initializing second UART instance on the same pins is not a good approach, beacause you will get collissions on transmit/receive. Do you need to have OpenThread CLI enabled? If not, there is an option to disable OpenThread CLI in the aplication, and register application's own otPlatUartReceived handler. This way you can use OpenThread UART driver for communication via built-in USB serial port.

  • No, I don't have to use the OpenThread CLI since I can manually configure the network in main() using the API. I'm assuming after disabling the OpenThread CLI and then using otPlatUartReceived, I have to enable UART0 and disable UART1. Is there a function in the API to disable the OpenThread CLI?

  • If you do not want to use CLI, simply do not initialize it. I cannot post files via comment section, but the steps are pretty simple, so you can reproduce them. I have modified the OpenThread CLI form Thread SDK, as it's the simplest, but you can apply these steps to any Thread example:

    1. Add OT UART header : #include <openthread/platform/uart.h>
    2. Replace otCliUartInit(p_instance); with otPlatUartEnable(); to enable UART0 (CLI does it by itself).
    3. Create receive handler, for example:
    void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
    {
        (void)aBuf;
        (void)aBufLength;
        bsp_board_led_invert(BSP_BOARD_LED_3);
    }
    
    1. In a Makefile, remove the line that linked CLI library: $(SDK_ROOT)/external/openthread/lib/gcc/libopenthread-cli-ftd.a \

    After reproducing these steps you will be able to control UART0 manually from the application.

Related