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.

  • 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

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

Children
No Data
Related