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

Using UART1 for SDK and UART0 for Mesh

Hi,

I am trying to integrate UART and DFU serial from the mesh example.

What I did is:

1. Adding uart drivers and libraries into the DFU project.

2. Adding codes of uart into DFU codes. I changed the priority of the art to "LOW".

3. Editing the sdk_config to enable uart1.

4. Programming an nrf52840 devkit by softdevice, dfu application, device page, and a bootloader as the board connected to the pc.

5. Programing an nrf52840 dongle by softdevice, dfu application, device page, and a bootloader as the target device.

Once I enter the command to send a file it returns:

Upgrading target on COM3 with DFU package D:\Behine Niroo\Nordic\NRF Mesh\nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_blinky\pca10059\s140\ses\Output\Release\Exe\dfu_test.zip. Flow control is enabled.


Failed to upgrade target. Error is: Failed to establish connection

Possible causes:
- bootloader, SoftDevice or application on target does not match the requirements in the DFU package.
- baud rate or flow control is not the same as in the target bootloader.
- target is not in DFU mode. If using the SDK examples, press Button 4 and RESET and release both to enter DFU mode.
- if the error is ERROR_BUSY at the beginning of the DFU process,increase the value of PAGE_ERASE_TIME_MAX by few milliseconds.

What does make this problem? May this relate to the art codes I added?

I appreciate it if you advise me on this issue.

Br,

Sama

Parents Reply Children
  • Hi Hung,

    Thank you for your reply.

    The DFU works fine before modifying.


    #ifndef NRFX_UARTE1_ENABLED
    #define NRFX_UARTE1_ENABLED 1
    #endif


    #ifndef NRFX_UART_ENABLED
    #define NRFX_UART_ENABLED 1
    #endif


    #ifndef NRFX_UART0_ENABLED
    #define NRFX_UART0_ENABLED 0
    #endif


    #ifndef NRFX_UART1_ENABLED
    #define NRFX_UART1_ENABLED 1
    #endif

    #ifndef UART_ENABLED
    #define UART_ENABLED 1
    #endif


    #ifndef UART_LEGACY_SUPPORT
    #define UART_LEGACY_SUPPORT 0
    #endif


    #ifndef UART0_CONFIG_USE_EASY_DMA
    #define UART0_CONFIG_USE_EASY_DMA 0
    #endif

    #ifndef UART1_ENABLED
    #define UART1_ENABLED 1
    #endif

    #ifndef UART1_CONFIG_USE_EASY_DMA
    #define UART1_CONFIG_USE_EASY_DMA 1
    #endif

    #ifndef APP_FIFO_ENABLED
    #define APP_FIFO_ENABLED 1
    #endif


    #ifndef APP_UART_ENABLED
    #define APP_UART_ENABLED 1
    #endif


    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 1
    #endif


    #ifndef RETARGET_ENABLED
    #define RETARGET_ENABLED 1
    #endif

    Actually, I have been completely confused. I have been trying to enable uarte1 for nrf_log tasks in the uart example. It compiles without any error and I see that uarte1 is enabled at the code sources. However, I can not see nrf_log messages.

    I had a look at the libuarte in which there is an unclear description about the pin configuration. It is suggested to short Arduino pins, although it works in a loop test without shorting any pin.

    Could you clarify that the uarte1 and uart0 use the same pins? Is it possible to enable both uarts on the same pins and use them for different tasks asynchrony? For example, the uart0 is enabled as default and when I send a command it changes to uarte1. I tried to change APP_UART_DRIVER_INSTANCE but it did no work.

    What I want to do is using a USB connector for the mesh DFU over serial and using another USB connector for communication.

    I tried to add usbd cdc acm to DFU. I faced app_timer errors.

    Which method is the simplest way?

    I look forward to hearing from you.

    Br,

    Sama

  • Hi Sama, 
    No you can't use the same pin for UARTE0 (or UART) and UARTE1. 
    The dual uart example (serial_uartes) you pointed to use the same pin: 
    RX pin on UARTE0 as the TX pin on UARTE1 just to show how a loop back can be done. 
    In reality if you want to use 2 UARTs at the same time you need to use different pins. 

    I don't really understand what you meant by "USB connector for the mesh DFU over serial " I assume it's the USB over USB of the Jlink chip (the normal virtual UART we have when we connect the DK to PC ? )

    Are you planning to use usbd cdc or you are planning to use UARTE1, please stick to one solution only. 

    I strongly recommend you to test both UART using normal application first before you move to mesh and before you move to mesh DFU. 
    You need to be able to understand how things work before you move to more complicated application. 

    Building with no error doesn't mean that it's working. 

  • Hi Hung,

    Thank you for your reply.

    I meant the USB of the Jlink and the nRF USB on the devkit. 

    Anyway, I managed to add USBD CDC ACM to the client example, and I can send and receive data via USB port.

    Now, all I want to do is send the data from the serial terminal on the detected USB PORT and then publish it over the mesh.


    I have a function named "send message" as below, called when data received from the USB port.

    void send_message (void) 
    {
        uint32_t status=0;
        char buffer[8];///={0x44,0x61,0x74,0x61};
        uint8_t length;
        uint16_t address;
        access_message_tx_t msg;
        length= sizeof(buffer);
                   if (length)
                    { 
                      msg.opcode.opcode = simple_message_OPCODE_SEND ;
                      msg.opcode.company_id = 0x0059; // Nordic's company ID
          
                      msg.p_buffer = (const uint8_t *) &buffer[0];
                      msg.length =length;
                
                      
    
                      //SEGGER_RTT_printf(0,"Sending to group address 0x%04x\n", address);
                      status= access_model_publish(m_clients[0].model_handle, &msg);        //CHANGED TO 0 FROM 3 
                      __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status : %u \n", status);
    
                      if (status == NRF_ERROR_INVALID_STATE ||
                      status == NRF_ERROR_BUSY||status == NRF_ERROR_NO_MEM)
                       {
                         __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Cannot send. Device is busy.\n");
                          hal_led_blink_ms(LEDS_MASK, 50, 4);
                       }
                       else
                       {
                             ERROR_CHECK(status);
                       }
                    }
    
    }
    
    
    


    I get the error when I send data:


    app_error_weak.c, 105, Mesh assert at 0x0002CDF8 (:0)
    which I got with adding UART into client example, and I asked in this ticket.

    I have used the addr2line tool and it returned:

    ....\mesh\core\src/timer_scheduler.c:218 (discriminator 1).


    I have searched the Devzone, and I found out this is related to the priority level. As far as I understood, when I call a mesh API from a handler, it is needed to initialize the mesh with "NRF_MESH_IRQ_PRIORITY_LOWEST" and use the same priority level for the user interrupt (cdc_acm_user_ev_handler in this situation).

    Here is the mesh init function:

    static void mesh_init(void)
    {
    mesh_stack_init_params_t init_params =
    {
    .core.irq_priority = NRF_MESH_IRQ_PRIORITY_LOWEST,
    .core.lfclksrc = DEV_BOARD_LF_CLK_CFG,
    .core.p_uuid = NULL,
    .models.models_init_cb = models_init_cb,
    .models.config_server_cb = config_server_evt_cb
    };

    and here is the priority setting of USBD:

    #ifndef NRFX_USBD_CONFIG_IRQ_PRIORITY
    #define NRFX_USBD_CONFIG_IRQ_PRIORITY 6
    #endif

    #ifndef USBD_CONFIG_IRQ_PRIORITY
    #define USBD_CONFIG_IRQ_PRIORITY 6
    #endif


    Any solution?

    Thank you in advance.

    Br,
    Sama

  • Hi Sama, 

    Glad that it's proceeding now. 

    You are correct that it's related to the interrupt priority level. 
    If you have a look at line 218 in timer_scheduer.c you can find that it checks for bearer_event_in_correct_irq_priority()

    So most likely it's something wrong with the priority level. We need to check which priority level you were at when you call send_message(). 

    Please double check if you have NRF_MESH_IRQ_PRIORITY_LOWEST = 6 in your application ? 

    Could you try to step inside bearer_event_in_correct_irq_priority() and check which exactly return false ? 
    There are 2 check inside , please check which exact active_irq is and which exact NVIC_GetPriority(active_irq) is . 

  • Hi Hung,

    Thank you for your reply.

    Here is the log you needed.

    <t: 4>, main.c, 1026, ----- BLE Mesh Light Switch Client Demo -----
    <t: 12562>, main.c, 641, Initializing and adding models
    <t: 17497>, main.c, 442, Node Address: 0x000A
    <t: 17499>, main.c, 1074, Enabling serial interface...
    <t: 17503>, mesh_app_utils.c, 66, Device UUID (raw): 137FF47B11294702B381A62F60654E45
    <t: 17506>, mesh_app_utils.c, 67, Device UUID : 137FF47B-1129-4702-B381-A62F60654E45
    <t: 17511>, bearer_event.c, 419, ----- active_irq is -16 -----
    <t: 17527>, bearer_event.c, 419, ----- active_irq is -16 -----
    <t: 17530>, bearer_event.c, 419, ----- active_irq is -16 -----
    <t: 17536>, bearer_event.c, 419, ----- active_irq is -16 -----
    <t: 17548>, main.c, 1084,
    ------------------------------------------------------------------------------------
    Button/RTT 1) Send a message to the odd group (address: 0xC003) to turn on LED 1.
    Button/RTT 2) Send a message to the odd group (address: 0xC003) to turn off LED 1.
    Button/RTT 3) Send a message to the even group (address: 0xC002) to turn on LED 1.
    Button/RTT 4) Send a message to the even group (address: 0xC002) to turn off LED 1.
    ------------------------------------------------------------------------------------
    <t: 17622>, bearer_event.c, 419, ----- active_irq is 18 -----
    <t: 17625>, bearer_event.c, 428, ----- prio is 6 -----
    <t: 17628>, bearer_event.c, 419, ----- active_irq is 18 -----
    <t: 17631>, bearer_event.c, 428, ----- prio is 6 -----
    <t: 18888>, bearer_event.c, 419, ----- active_irq is 18 -----


    when I send my command through the USB and call the "send message" function the log is:

    <t: 1648319>, main.c, 545, Button 1 pressed
    <t: 1648321>, main.c, 568, Sending msg: ONOFF SET 1
    <t: 1648335>, bearer_event.c, 419, ----- active_irq is -16 -----
    <t: 1648338>, app_error_weak.c, 105, Mesh assert at 0x0002CDE4 (:0)

    Any solution?


    I look forward to hearing from you.

    Br,
    Sama

Related