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.

Parents
  • Hi, As you already noticed, OpenThread CLI uses UART0 and that cannot be changed without modyfing OpenThread driver and rebuilding libraries.

    You should be able though to use UARTE1 with app_uart in OpenThread CLI as a secondary UART. Unfortunately OpenThread CLI example does not provide app_uart support by default, so you will have to add app_uart and nrf_drv_uart manually to the project. You can use UART peripheral example as a reference. Make sure to copy respective configuration from sdk_config.h as well.

    Keep in mind, that you have to modify default sdk_config.h configuration. Disable UART0 in nrf_drv_uart by setting UART0_ENABLED 0, as this peripheras is owned by OpenThread driver. To enable UARTE1 in app_uart, set UART1_ENABLED 1 and APP_UART_DRIVER_INSTANCE 1. When initializing app_uart make sure to use other pins than UART0 does.

    The last thing is to remove -DUART_ENABLED=0 from the makefile, as we do want to use the UART driver from SDK now.

  • 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.

Reply
  • 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.

Children
No Data
Related