URAT Data Transmission in DFU mode

nrf52840 17.1.0 s140 SDK :- examples/dfu/secure_bootloader/pca10056_s140_ble_debug

We are using the secure bootloader with BLE debug and have combined BLE and UART for the DFU bootloader. However, while performing DFU over-the-air (FOTA) from a mobile device, I am trying to send data to print BLE packets using UART. I am able to send only one packet; after that, the transmission stops, and I cannot send additional data. For reference, see the log below.

We call the function from nrf_dfu_ble.c:
static void on_write(ble_dfu_t * p_dfu, ble_evt_t const * p_ble_evt)
{
// Existing code

nrf_drv_uart_tx(&m_uart, data, length);

// Existing code
}

Note: We need to achieve this using only in this SDK version pca10056_s140_ble_debug.

<info> app: Inside main
<debug> app: In nrf_bootloader_init
<debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
<debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
<debug> nrf_dfu_settings: Using settings page.
<debug> nrf_dfu_settings: Copying forbidden parts from backup page.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
<debug> app: Enter nrf_bootloader_fw_activate
<info> app: No firmware to activate.
<info> app: Boot validation failed. No valid app to boot.
<debug> app: DFU mode because app is not valid.
<info> nrf_bootloader_wdt: WDT is not enabled
<debug> app: in weak nrf_dfu_init_user
<debug> app: timer_stop (0x20005998)
<debug> app: timer_activate (0x20005998)
<info> app: Entering DFU mode.
<debug> app: Initializing transports (found: 2)
<debug> nrf_dfu_ble: Initializing BLE DFU transport
<debug> nrf_dfu_ble: Setting up vector table: 0x000E8000
<debug> nrf_dfu_ble: Enabling SoftDevice.
<debug> nrf_dfu_ble: Configuring BLE stack.
<debug> nrf_dfu_ble: Enabling the BLE stack.
<debug> nrf_dfu_ble: No advertising name found
<debug> nrf_dfu_ble: Using default advertising name
<debug> nrf_dfu_ble: Advertising...
<debug> nrf_dfu_ble: BLE DFU transport initialized.
<debug> nrf_dfu_serial_uart: serial_dfu_transport_init()
<debug> nrf_dfu_serial_uart: serial_dfu_transport_init() completed
<info> nrf_dfu_serial_uart: Sending initial byte 0x24
<debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
<debug> app: Enter main loop
<debug> nrf_dfu_ble: Connected
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST.
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE (27, max_rx_time 328).
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_CONN_PARAM_UPDATE
<debug> nrf_dfu_ble: max_conn_interval: 12
<debug> nrf_dfu_ble: min_conn_interval: 12
<debug> nrf_dfu_ble: slave_latency: 0
<debug> nrf_dfu_ble: conn_sup_timeout: 600
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_CONN_PARAM_UPDATE
<debug> nrf_dfu_ble: max_conn_interval: 6
<debug> nrf_dfu_ble: min_conn_interval: 6
<debug> nrf_dfu_ble: slave_latency: 0
<debug> nrf_dfu_ble: conn_sup_timeout: 500
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_CONN_PARAM_UPDATE
<debug> nrf_dfu_ble: max_conn_interval: 12
<debug> nrf_dfu_ble: min_conn_interval: 12
<debug> nrf_dfu_ble: slave_latency: 0
<debug> nrf_dfu_ble: conn_sup_timeout: 600
<debug> nrf_dfu_ble: Received BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST (request: 517, reply: 247).
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST.
<debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE (251, max_rx_time 2120).
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_SELECT (command)
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> nrf_dfu_ble: Set receipt notif
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_RECEIPT_NOTIF_SET
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> app: Shutting down transports (found: 2)
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_CREATE (command)
<debug> app: timer_stop (0x20005998)
<debug> app: timer_activate (0x20005998)
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> nrf_dfu_ble: Buffer 0x20006ED8 acquired, len 141 (244)
<debug> nrf_dfu_ble: Copying 141 bytes from p_write_evt->data to p_balloc_buf:
12 8A 01 0A 44 08 01 12|....D...
40 08 01 10 34 1A 02 80|@...4...
02 20 00 28 00 30 00 38|. .(.0.8
E0 F0 03 42 24 08 03 12|...B$...
20 60 23 74 3A 38 1B 65| `#t:8.e
2E 68 F0 F3 05 97 26 76|.h....&v
D3 61 C0 4C 00 F4 D7 E6|.a.L....
B2 44 DE EC 6C 90 75 1E|.D..l.u.
D7 48 00 52 04 08 01 12|.H.R....
00 10 00 1A 40 CA 06 15|....@...
<debug> nrf_dfu_ble: Sending 141 bytes via UART:
12 8A 01 0A 44 08 01 12|....D...
40 08 01 10 34 1A 02 80|@...4...
02 20 00 28 00 30 00 38|. .(.0.8
E0 F0 03 42 24 08 03 12|...B$...
20 60 23 74 3A 38 1B 65| `#t:8.e
2E 68 F0 F3 05 97 26 76|.h....&v
D3 61 C0 4C 00 F4 D7 E6|.a.L....
B2 44 DE EC 6C 90 75 1E|.D..l.u.
D7 48 00 52 04 08 01 12|.H.R....
00 10 00 1A 40 CA 06 15|....@...
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_WRITE (command)
<debug> nrf_dfu_ble: Freeing buffer 0x20006ED8
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_CRC_GET (command)
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_EXECUTE (command)
<debug> nrf_dfu_validation: PB: Init packet data len: 64
<info> nrf_dfu_validation: Signature required. Checking signature.
<info> nrf_dfu_validation: Calculating hash (len: 64)
<info> nrf_dfu_validation: Verify signature
<info> nrf_dfu_validation: Image verified
<info> nrf_dfu_validation: Total size= 0

<debug> app: Enter nrf_dfu_cache_prepare()
<debug> app: required_size: 0xF860.
<debug> app: single_bank: false.
<debug> app: keep_app: false.
<debug> app: keep_softdevice: true.
<debug> app: SD_PRESENT: true.
<debug> app: Bank contents:
<debug> app: Bank 0 code: 0x00: Size: 0x0
<debug> app: Bank 1 code: 0x00: Size: 0x0
<debug> nrf_dfu_validation: Write address set to 0x00027000
<debug> nrf_dfu_settings: Writing settings...
<debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
<debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 0
<debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x200084EC, len=896 bytes), queue usage: 1
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Writing settings...
<debug> nrf_dfu_settings: Erasing old settings at: 0x000FE000
<debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FE000, len=1 pages), queue usage: 2
<debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FE000, src=0x2000816C, len=896 bytes), queue usage: 3
<debug> nrf_dfu_req_handler: Writing valid init command to flash.
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_SELECT (data)
<debug> nrf_dfu_req_handler: crc = 0x0, offset = 0x0, max_size = 0x1000
<debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
<debug> app: timer_stop (0x20005998)
<debug> app: timer_fire (0x20005998)
<info> app: Inactivity timeout.
<debug> app: Resetting bootloader.
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<error> app: Received a fault! id: 0x00004002, pc: 0x00000000, info: 0x2003FF20

  • RAJVARDHAN said:

    nrf_uarte_task_trigger(NRF_UARTE0, NRF_UARTE_TASK_STARTTX);

    //it will hang here .

    }

    Not sure what you mean by hang, if you think it is looping there, then it should not be possible. UARTE task trigger is unconditional execution and does not depend on anything apart from the CPU writing to that register. There is no hardware wait condition on this task trigger unless there is something in the code that waits for something else. In short, I do not see how the system waits or hangs in there. Have you evaluated that the system hangs in there after starting the application in the debugger? Is it possible that there is a fault?

    Can you show me the registers value in the debugger and the context of the CPU as to which instruction it was executing in this wait state? Show me the snapshot of your paused debugger session in this hang/wait state and most of the info I am asking should be available in the snapshot.

  • 1. After sending one packet, the system waits until a timeout occurs, at the point the bootloader will reset. Please refer to the logs for details.

    <debug> nrf_dfu_settings: Writing settings...
    <debug> nrf_dfu_settings: Erasing old settings at: 0x000FE000
    <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FE000, len=1 pages), queue usage: 2
    <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FE000, src=0x2000816C, len=896 bytes), queue usage: 3
    <debug> nrf_dfu_req_handler: Writing valid init command to flash.
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_SELECT (data)
    <debug> nrf_dfu_req_handler: crc = 0x0, offset = 0x0, max_size = 0x1000
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> app: timer_stop (0x20005998)
    <debug> app: timer_fire (0x20005998)
    <info> app: Inactivity timeout.
    <debug> app: Resetting bootloader.
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <error> app: Received a fault! id: 0x00004002, pc: 0x00000000, info: 0x2003FF20

    2. Our requirement is to send packets continuously, but the transmission is stopping after only one packet via UART.

    3. We need to transfer binary packet to another controller via UART.

    Note: We need to achieve this using only in this SDK version pca10056_s140_ble_debug.

  • RAJVARDHAN said:
    2. Our requirement is to send packets continuously, but the transmission is stopping after only one packet via UART.

    Rajvardhan, 

    Again, you have not clearly mentioned where the system seems to 'hang'.  The last mentioning you mentioned at the nrf_uarte_task_trigger is not the possible fault scenario. It is extremely important to know the context of the system idleness/stuck_state so that we are able to narrow down the issue to specific peripheral or resource.

    Can you send me a snapshot of the debugging session where you have run the program until you see the inactivity in the UART and then halt the debugger and show me the snapshot on the current execution, registers and the function_call_stack?

  • 1. Hi i have attached picture while running in debug mode 

    code snippet

    ret_code_t nrf_dfu_flash_store(uint32_t dest,
    void const * p_src,
    uint32_t len,
    nrf_dfu_flash_callback_t callback)
    {
    ret_code_t rc;

    NRF_LOG_DEBUG("nrf_fstorage_write(addr=%p, src=%p, len=%d bytes), queue usage: %d",
    dest, p_src, len, m_flash_operations_pending);


    //lint -save -e611 (Suspicious cast)
    rc = nrf_fstorage_write(&m_fs, dest, p_src, len, (void *)callback);
    //lint -restore
    // return rc;

    rc = uart_send_data(p_src, len);

    if ((NRF_LOG_ENABLED) && (rc == NRF_SUCCESS))
    {
    m_flash_operations_pending++;
    }
    else
    {
    NRF_LOG_WARNING("nrf_fstorage_write() failed with error 0x%x.", rc);
    }

    return rc;
    }

    user code for sending in tx 

    uint32_t uart_send_data(const uint8_t *data, uint8_t length)
    {
    if (uart_tx_busy)
    {
    NRF_LOG_ERROR("UART buffer is busy");
    //return NRF_ERROR_BUSY;
    }

    uart_tx_busy = true; // Set the busy flag

    uint32_t err_code = nrf_drv_uart_tx(&m_uart, data, length);
    if (err_code != NRF_SUCCESS)
    {
    uart_tx_busy = false; // Clear the busy flag on failure
    NRF_LOG_ERROR("Failed to send data: 0x%x", err_code);
    }

    return err_code;

    }

    logs: 

    <info> app: Inside main
    <debug> app: In nrf_bootloader_init
    <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    <debug> nrf_dfu_settings: Using settings page.
    <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <debug> app: Enter nrf_bootloader_fw_activate
    <info> app: No firmware to activate.
    <info> app: Boot validation failed. No valid app to boot.
    <debug> app: DFU mode because app is not valid.
    <info> nrf_bootloader_wdt: WDT is not enabled
    <debug> app: in weak nrf_dfu_init_user
    <debug> app: timer_stop (0x20005998)
    <debug> app: timer_activate (0x20005998)
    <info> app: Entering DFU mode.
    <debug> app: Initializing transports (found: 2)
    <debug> nrf_dfu_ble: Initializing BLE DFU transport
    <debug> nrf_dfu_ble: Setting up vector table: 0x000E8000
    <debug> nrf_dfu_ble: Enabling SoftDevice.
    <debug> nrf_dfu_ble: Configuring BLE stack.
    <debug> nrf_dfu_ble: Enabling the BLE stack.
    <debug> nrf_dfu_ble: No advertising name found
    <debug> nrf_dfu_ble: Using default advertising name
    <debug> nrf_dfu_ble: Advertising...
    <debug> nrf_dfu_ble: BLE DFU transport initialized.
    <debug> nrf_dfu_serial_uart: serial_dfu_transport_init()
    <debug> nrf_dfu_serial_uart: serial_dfu_transport_init() completed
    <info> nrf_dfu_serial_uart: Sending initial byte 0x24
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
    <debug> app: Enter main loop
    <debug> nrf_dfu_ble: Connected
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST.
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE (27, max_rx_time 328).
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_CONN_PARAM_UPDATE
    <debug> nrf_dfu_ble: max_conn_interval: 12
    <debug> nrf_dfu_ble: min_conn_interval: 12
    <debug> nrf_dfu_ble: slave_latency: 0
    <debug> nrf_dfu_ble: conn_sup_timeout: 600
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_CONN_PARAM_UPDATE
    <debug> nrf_dfu_ble: max_conn_interval: 6
    <debug> nrf_dfu_ble: min_conn_interval: 6
    <debug> nrf_dfu_ble: slave_latency: 0
    <debug> nrf_dfu_ble: conn_sup_timeout: 500
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_CONN_PARAM_UPDATE
    <debug> nrf_dfu_ble: max_conn_interval: 12
    <debug> nrf_dfu_ble: min_conn_interval: 12
    <debug> nrf_dfu_ble: slave_latency: 0
    <debug> nrf_dfu_ble: conn_sup_timeout: 600
    <debug> nrf_dfu_ble: Received BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST (request: 517, reply: 247).
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST.
    <debug> nrf_dfu_ble: Received BLE_GAP_EVT_DATA_LENGTH_UPDATE (251, max_rx_time 2120).
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_SELECT (command)
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> nrf_dfu_ble: Set receipt notif
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_RECEIPT_NOTIF_SET
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> app: Shutting down transports (found: 2)
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_CREATE (command)
    <debug> app: timer_stop (0x20005998)
    <debug> app: timer_activate (0x20005998)
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> nrf_dfu_ble: Buffer 0x20006ED8 acquired, len 141 (244)
    <debug> nrf_dfu_ble: Copying 141 bytes from p_write_evt->data to p_balloc_buf:
    12 8A 01 0A 44 08 01 12|....D...
    40 08 01 10 34 1A 02 80|@...4...
    02 20 00 28 00 30 00 38|. .(.0.8
    84 ED 01 42 24 08 03 12|...B$...
    20 23 D6 A2 B0 77 38 59| #...w8Y
    01 26 57 1A 30 10 3E 75|.&W.0.>u
    F1 23 10 75 3D 35 C2 74|.#.u=5.t
    34 BF 6C B1 5C 9A D5 70|4.l.\..p
    B6 48 00 52 04 08 01 12|.H.R....
    00 10 00 1A 40 46 71 70|....@Fqp
    <debug> nrf_dfu_ble: Sending 141 bytes via UART:
    12 8A 01 0A 44 08 01 12|....D...
    40 08 01 10 34 1A 02 80|@...4...
    02 20 00 28 00 30 00 38|. .(.0.8
    84 ED 01 42 24 08 03 12|...B$...
    20 23 D6 A2 B0 77 38 59| #...w8Y
    01 26 57 1A 30 10 3E 75|.&W.0.>u
    F1 23 10 75 3D 35 C2 74|.#.u=5.t
    34 BF 6C B1 5C 9A D5 70|4.l.\..p
    B6 48 00 52 04 08 01 12|.H.R....
    00 10 00 1A 40 46 71 70|....@Fqp
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_WRITE (command)
    <debug> nrf_dfu_ble: Freeing buffer 0x20006ED8
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_CRC_GET (command)
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
    <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_EXECUTE (command)
    <debug> nrf_dfu_validation: PB: Init packet data len: 64
    <info> nrf_dfu_validation: Signature required. Checking signature.
    <info> nrf_dfu_validation: Calculating hash (len: 64)
    <info> nrf_dfu_validation: Verify signature
    <info> nrf_dfu_validation: Image verified
    <info> nrf_dfu_validation: Total size= 0

    <debug> app: Enter nrf_dfu_cache_prepare()
    <debug> app: required_size: 0x7684.
    <debug> app: single_bank: false.
    <debug> app: keep_app: false.
    <debug> app: keep_softdevice: true.
    <debug> app: SD_PRESENT: true.
    <debug> app: Bank contents:
    <debug> app: Bank 0 code: 0x00: Size: 0x0
    <debug> app: Bank 1 code: 0x00: Size: 0x0
    <debug> nrf_dfu_validation: Write address set to 0x00027000
    <debug> nrf_dfu_settings: Writing settings...
    <debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
    <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 0
    <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x200084EC, len=896 bytes), queue usage: 0
    <error> nrf_dfu_serial_uart: UART buffer is busy
    <error> nrf_dfu_serial_uart: Failed to send data: 0x200084EC
    <warning> nrf_dfu_flash: nrf_fstorage_write() failed with error 0x200084EC.
    <error> nrf_dfu_settings: Could not write the DFU settings page!
    <debug> nrf_dfu_req_handler: Request handling complete. Result: 0xA
    <warning> nrf_dfu_ble: DFU request 4 failed with error: 0xA

  • Hi Rajvardhan, is thread and the thread with support number 331140 related? both are discussing the similar topic from same company at the same time.

Related