NRF52833 Adding UART to Thead MQTTSN client publisher

Good day

I need to add UART to a project based "Thead MQTTSN client publisher" example code. The device needs to receive data over UART and then send the data to the MQTT broker. I have tried to port the code over from the peripheral UART example from the same SDK, but to no avail. Where as most of the SDK's examples perfectly illustrate their concept, it can sometimes be a nightmare to merge two examples.

Could you please provide some guidance on how to add UART capabilities to the Thread example.

Project is being done on a NRF52833 chip with version 4.1 of the Thread SDK.

Kind regards

  • Hi,

    Which issues are you facing when adding UART? Can you post the errors you get when building?

    The typical problem when adding UART to the Thread examples is that the OpenThread CLI have been built with UART support into the OpenThread libraries in the SDK. Since you are using nRF52833, you should be able to use the second UART instance (UARTE1) without issues.

    In nRF5 SDK for Thread and Zigbee v4.1.0, the transport is also compiles into a separate library, to be easily changes/removed, without the need to rebuild the OpenThread libraries. If you want to use UART0 in your application, you may try replacing the library "libopenthread-nrf52833-transport.a" with "libopenthread-nrf52833-transport-none.a

    Best regards,
    Jørgen

  • Thank you for the quick response.

    I've added the following drivers to the Thread example, based on what I saw in the UART example:
    nrf_drv_uart
    nrfx_prs (not sure if needed)
    nrfx_uart
    nrfx_uarte

    And the following libraries:
    nrf_fifo
    nrf_uart_fico

    In the main.c file I included:
    #include "app_uart.h"

    And defined:
    #if defined (UART_PRESENT)
    #include "nrf_uart.h"
    #endif
    #if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
    #endif

    #define MAX_TEST_DATA_BYTES     (15U)          /**< max number of test bytes to be used for tx and rx. */
    #define UART_TX_BUF_SIZE 256                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 256                         /**< UART RX buffer size. */

    UART_PRESENT is not defined and this causes errors later in the program -> NRF_UART_BAUDRATE_115200 not found

    I added this above the main function:
    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED

    And in the main function:
    uint32_t err_code;
            const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              UART_HWFC,
              false,
    #if defined (UART_PRESENT)
              NRF_UART_BAUDRATE_115200
    #else
              NRF_UARTE_BAUDRATE_115200
    #endif
          };

        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle,
                             APP_IRQ_PRIORITY_LOWEST,
                             err_code);

        APP_ERROR_CHECK(err_code);

    I also get the following errors in nrf_drv_uart.h:

    Type not found
    line 122: typedef nrf_uarte_baudrate_t        nrf_uart_baudrate_t;
    iine 127: typedef nrf_uarte_error_mask_t      nrf_uart_error_mask_t;
    line 130: typedef nrf_uarte_hwfc_t            nrf_uart_hwfc_t;
    line 133: typedef nrf_uarte_parity_t          nrf_uart_parity_t;
    line 134: typedef nrf_uarte_task_t            nrf_uart_task_t;
    line 135: typedef nrf_uarte_event_t           nrf_uart_event_t;

    I also added the following to the Tread example's config,
    from line 51-492 of the UART example:
    Which gives me the following in the config wizard
    NRFX_PRS_ENABLED - nrfx_prs
    NRFX_UARTE_ENABLED  - nrfx_uarte
    NRFX_UART_ENABLED - nrfx_uart
    UART_ENABLED - nrd_drv_uart

    Also, the IDE I'm working is is Keil uVision5

  • It looks like most of the errors are related to legacy UART vs. EasyDMA UARTE peripheral. Make sure that you set the following configs if you want to support both legacy and EasyDMA UART:

    // <q> UART_EASY_DMA_SUPPORT  - Driver supporting EasyDMA
     
    
    #ifndef UART_EASY_DMA_SUPPORT
    #define UART_EASY_DMA_SUPPORT 1
    #endif
    
    // <q> UART_LEGACY_SUPPORT  - Driver supporting Legacy mode
     
    
    #ifndef UART_LEGACY_SUPPORT
    #define UART_LEGACY_SUPPORT 1
    #endif
    
    // <e> UART0_ENABLED - Enable UART0 instance
    //==========================================================
    #ifndef UART0_ENABLED
    #define UART0_ENABLED 1
    #endif
    // <q> UART0_CONFIG_USE_EASY_DMA  - Default setting for using EasyDMA
     
    
    #ifndef UART0_CONFIG_USE_EASY_DMA
    #define UART0_CONFIG_USE_EASY_DMA 1
    #endif

    If you want me to have a look at the project and help you fix the issues, please upload a zipped version of your project.

  • There are a couple of things needed to make the project compile:

    In sdk_config.h, set NRFX_UARTE0_ENABLED:

    // <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance
    #ifndef NRFX_UARTE0_ENABLED
    #define NRFX_UARTE0_ENABLED 1
    #endif

    In project options, remove the preprocessor symbol "UART_ENABLED=0".

    Add "#include "bsp.h"" to main.c, before the check for #if defined(UART_PRESENT)\#if defined(UARTE_PRESENT).

    I also get one additional error related to the scatter file, but this might be an issue on my end and likely not related to the addition of UART.

Related