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.

  • Hi Robert,

    I've been trying to run UART1 in simple_coap_server project. I followed your steps, but with no success. So I decided to reproduce them in pure uart example first. I modified sdk_config.h as you described:

    sdk_config.h
    
    // <e> UART0_ENABLED - Enable UART0 instance
    //==========================================================
    #ifndef UART0_ENABLED
    #define UART0_ENABLED 1
    #endif
    
    // ...
    
    // <e> UART1_ENABLED - Enable UART1 instance
    //==========================================================
    #ifndef UART1_ENABLED
    #define UART1_ENABLED 1
    #endif
    
    // ...
    
    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 1
    #endif
    
    

    However I got the following errors:

    Compiling file: app_uart_fifo.c
    In file included from ../../../../../../modules/nrfx/nrfx.h:45:0,
                     from ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:44,
                     from ../../../../../../components/libraries/uart/app_uart_fifo.c:44:
    ../../../../../../modules/nrfx/drivers/include/nrfx_uart.h:79:35: error: 'NRF_UART1' undeclared here (not in a function)
         .p_reg        = NRFX_CONCAT_2(NRF_UART, id),             \
                                       ^
    ../../../../../../modules/nrfx/drivers/nrfx_common.h:94:37: note: in definition of macro 'NRFX_CONCAT_2_'
     #define NRFX_CONCAT_2_(p1, p2)      p1 ## p2
                                         ^~
    ../../../../../../modules/nrfx/drivers/include/nrfx_uart.h:79:21: note: in expansion of macro 'NRFX_CONCAT_2'
         .p_reg        = NRFX_CONCAT_2(NRF_UART, id),             \
                         ^~~~~~~~~~~~~
    ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:78:17: note: in expansion of macro 'NRFX_UART_INSTANCE'
             .uart = NRFX_UART_INSTANCE(id),
                     ^~~~~~~~~~~~~~~~~~
    ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:166:5: note: in expansion of macro 'NRF_DRV_UART_CREATE_UART'
         NRF_DRV_UART_CREATE_UART(id)  \
         ^~~~~~~~~~~~~~~~~~~~~~~~
    ../../../../../../components/libraries/uart/app_uart_fifo.c:47:39: note: in expansion of macro 'NRF_DRV_UART_INSTANCE'
     static nrf_drv_uart_t app_uart_inst = NRF_DRV_UART_INSTANCE(APP_UART_DRIVER_INSTANCE);
                                           ^~~~~~~~~~~~~~~~~~~~~
    ../../../../../../modules/nrfx/drivers/include/nrfx_uart.h:80:35: error: 'NRFX_UART1_INST_IDX' undeclared here (not in a function)
         .drv_inst_idx = NRFX_CONCAT_3(NRFX_UART, id, _INST_IDX), \
                                       ^
    ../../../../../../modules/nrfx/drivers/nrfx_common.h:117:37: note: in definition of macro 'NRFX_CONCAT_3_'
     #define NRFX_CONCAT_3_(p1, p2, p3)  p1 ## p2 ## p3
                                         ^~
    ../../../../../../modules/nrfx/drivers/include/nrfx_uart.h:80:21: note: in expansion of macro 'NRFX_CONCAT_3'
         .drv_inst_idx = NRFX_CONCAT_3(NRFX_UART, id, _INST_IDX), \
                         ^~~~~~~~~~~~~
    ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:78:17: note: in expansion of macro 'NRFX_UART_INSTANCE'
             .uart = NRFX_UART_INSTANCE(id),
                     ^~~~~~~~~~~~~~~~~~
    ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:166:5: note: in expansion of macro 'NRF_DRV_UART_CREATE_UART'
         NRF_DRV_UART_CREATE_UART(id)  \
         ^~~~~~~~~~~~~~~~~~~~~~~~
    ../../../../../../components/libraries/uart/app_uart_fifo.c:47:39: note: in expansion of macro 'NRF_DRV_UART_INSTANCE'
     static nrf_drv_uart_t app_uart_inst = NRF_DRV_UART_INSTANCE(APP_UART_DRIVER_INSTANCE);
                                           ^~~~~~~~~~~~~~~~~~~~~

    Do I miss something?

    SDK: nRF5 SDK for Thread and Zigbee

  • Hi!

    First of all, I can see that in your config file, you are enabling UART0 with #define UART0_ENABLED 1. Again, you cannot do that with OpenThread, as it uses this peripheral, unless you disable OpenThread CLI.

    But regarding your question and adding UARTE1 support to simple_coap_server. I've followed the description I've posted some time ago and was able to compile the project with app_uart and UARTE1 enabled, though I had to take nrfx into consideration, as it's a part of current SDK, and was not present when the answer was posted. So lets iterate through the steps needed to add this support (and use uart peripheral sample as a reference for the configuration):

    1. Modify the simple_coap_server makefile by adding the following lines to the SRC_FILES section:

    $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
    $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
    $(SDK_ROOT)/components/libraries/fifo/app_fifo.c \
    $(SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \


    2. Modify the simple_coap_server makefile by adding the following lines to the INC_FOLDERS section:

    $(SDK_ROOT)/components/libraries/fifo \
    $(SDK_ROOT)/components/libraries/uart \


    3. Remove the CFLAGS += -DUART_ENABLED=0 and ASMFLAGS += -DUART_ENABLED=0 lines from the makefile
    4. From uart peripheral sample sdk_config.h file, copy the configuration enabling UART. This includes NRFX_UART* configs as well. As for the nRF5 SDK for Thread and Zigbee v.1.0.0, you should copy all configs from NRFX_UARTE_ENABLED to APP_UART_DRIVER_INSTANCE (inclusive).
    5. Disable UART0 by setting #define UART0_ENABLED 0 and enable UARTE1 by setting #define UART1_ENABLED 1. Finally, set correct UART instance for app_uart to use - #define APP_UART_DRIVER_INSTANCE 1.

    Following these steps should result in having app_uart over UARTE1 enabled in simple_coap_server, ready to use.

    Regards,
    Robert

Related