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
  • Hi Sama, 
    We need to have a look on how you modified the DFU project. I assume DFU works fine before you add the modification ? 


    I think what you would need to do is to verify that both UARTs work together. Have you tried to send some data to UART0 and UART1 , just don't test DFU before you verify that you can use both UARTs normally. 

  • 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

  • Hi,

    Could you please advise me to solve this problem?

    I am struggling with that too much time.

    Br,

    Sama

  • Hi Sama, 
    Sorry for late response, I was on vacation. 
    From what I can see it seems that you were calling the send message from a Thread level. Could you show how you call send message in your code ? 
    Can you send a minimal code that show the issue so that I can test here ? Please try to keep it as minimal as possible so I can run on a DK here. 

Reply Children
No Data
Related