This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Init Packet

I'm referring this

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Flib_dfu_transport_ble.html

which states that when in bootloader mode, I've to send the init packet first & then the firmware image.

So what happens after I send 06 01 command. What is init packet? How do I create one? The response received for each command - is it written over a characteristic or a descriptor inside characteristic? My understanding is DFU Control Point & DFU Packet characteristics do not support read property. So where can I see the response received for every command sent by host to BLE device?

Sorry I could not understand a thing from the sniffer trace which I captured while executing the actual DFU procedure listed on Nordic Infocenter. I'm using SDK 15.2 & nrf52832.

5875.original.pcapng

Parents
  • Hi Sonal, 

    What is init packet? How do I create one?

    the Init packet is part of the DFU firmware image that you create using nrfutil, see https://github.com/NordicSemiconductor/pc-nrfutil

    The response received for each command - is it written over a characteristic or a descriptor inside characteristic? My understanding is DFU Control Point & DFU Packet characteristics do not support read property. So where can I see the response received for every command sent by host to BLE device?

     The response is a characteristic notification from the BLE peripheral to the BLE Central. 

    Best regards

    Bjørn

  • Thanks Bjorn! How can I read this response? On which characteristic is this response sent? 

  • I followed the sequence which you mentioned above. Could you please tell me the location where the packets from firmware file being received are handled in bootloader code? For me, the DFU process stops midway, like only 50% of the firmware file is sent OTA.

    How come nRFConnect sends 244 byte packets? The connection diagram in the documentation mentions sending only 20 bytes. Also the sdk config file in the bootloader has 27 bytes set for BLE packet.

  • HI Sonal, 

    its on_data_obj_write_request() in nrf_dfu_req_handler.c that handles data sent do the DFU packet characteristic. 

        NRF_LOG_DEBUG("Handle NRF_DFU_OP_OBJECT_WRITE (data)");
    
        if (!nrf_dfu_validation_init_cmd_present())
        {
            /* Can't accept data because DFU isn't initialized by init command. */
            p_res->result = NRF_DFU_RES_CODE_OPERATION_NOT_PERMITTED;
            return;
        }
    
        uint32_t const data_object_offset = s_dfu_settings.progress.firmware_image_offset -
                                            s_dfu_settings.progress.firmware_image_offset_last;
    
        if ((p_req->write.len + data_object_offset) > s_dfu_settings.progress.data_object_size)
        {
            /* Can't accept data because too much data has been received. */
            NRF_LOG_ERROR("Write request too long");
            p_res->result = NRF_DFU_RES_CODE_INVALID_PARAMETER;
            return;
        }
    
        uint32_t const write_addr = m_firmware_start_addr + s_dfu_settings.write_offset;
    
        ASSERT(p_req->callback.write);
    
        ret_code_t ret =
            nrf_dfu_flash_store(write_addr, p_req->write.p_data, p_req->write.len, p_req->callback.write);
    
        if (ret != NRF_SUCCESS)
        {
            /* When nrf_dfu_flash_store() fails because there is no space in the queue,
             * stop processing the request so that the peer can detect a CRC error
             * and retransmit this object. Remember to manually free the buffer !
             */
            p_req->callback.write((void*)p_req->write.p_data);
            return;
        }
    
        /* Update the CRC of the firmware image. */
        s_dfu_settings.write_offset                   += p_req->write.len;
        s_dfu_settings.progress.firmware_image_offset += p_req->write.len;
        s_dfu_settings.progress.firmware_image_crc     =
            crc32_compute(p_req->write.p_data, p_req->write.len, &s_dfu_settings.progress.firmware_image_crc);
    
        /* This is only used when the PRN is triggered and the 'write' message
         * is answered with a CRC message and these field are copied into the response.
         */
        p_res->write.crc    = s_dfu_settings.progress.firmware_image_crc;
        p_res->write.offset = s_dfu_settings.progress.firmware_image_offset;
    }

    If the DFU process stops, then please post the debug log output from the bootloader. 

    It is possible to write larger chunks than 20 bytes as long as you do not exceed the object size, see on_data_obj_write_request().  The ATT MTU size is negotiable, see the BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST case in ble_evt_handler() in nrf_dfu_ble.c. It can be set as high as NRF_SDH_BLE_GATT_MAX_MTU_SIZE, i.e. 247.

    Best regards

    Bjørn

  • HI Sonal, 

    its on_data_obj_write_request() in nrf_dfu_req_handler.c that handles data sent do the DFU packet characteristic. 

        NRF_LOG_DEBUG("Handle NRF_DFU_OP_OBJECT_WRITE (data)");
    
        if (!nrf_dfu_validation_init_cmd_present())
        {
            /* Can't accept data because DFU isn't initialized by init command. */
            p_res->result = NRF_DFU_RES_CODE_OPERATION_NOT_PERMITTED;
            return;
        }
    
        uint32_t const data_object_offset = s_dfu_settings.progress.firmware_image_offset -
                                            s_dfu_settings.progress.firmware_image_offset_last;
    
        if ((p_req->write.len + data_object_offset) > s_dfu_settings.progress.data_object_size)
        {
            /* Can't accept data because too much data has been received. */
            NRF_LOG_ERROR("Write request too long");
            p_res->result = NRF_DFU_RES_CODE_INVALID_PARAMETER;
            return;
        }
    
        uint32_t const write_addr = m_firmware_start_addr + s_dfu_settings.write_offset;
    
        ASSERT(p_req->callback.write);
    
        ret_code_t ret =
            nrf_dfu_flash_store(write_addr, p_req->write.p_data, p_req->write.len, p_req->callback.write);
    
        if (ret != NRF_SUCCESS)
        {
            /* When nrf_dfu_flash_store() fails because there is no space in the queue,
             * stop processing the request so that the peer can detect a CRC error
             * and retransmit this object. Remember to manually free the buffer !
             */
            p_req->callback.write((void*)p_req->write.p_data);
            return;
        }
    
        /* Update the CRC of the firmware image. */
        s_dfu_settings.write_offset                   += p_req->write.len;
        s_dfu_settings.progress.firmware_image_offset += p_req->write.len;
        s_dfu_settings.progress.firmware_image_crc     =
            crc32_compute(p_req->write.p_data, p_req->write.len, &s_dfu_settings.progress.firmware_image_crc);
    
        /* This is only used when the PRN is triggered and the 'write' message
         * is answered with a CRC message and these field are copied into the response.
         */
        p_res->write.crc    = s_dfu_settings.progress.firmware_image_crc;
        p_res->write.offset = s_dfu_settings.progress.firmware_image_offset;
    }

    If the DFU process stops, then please post the debug log output from the bootloader. 

    It is possible to write larger chunks than 20 bytes as long as you do not exceed the object size, see on_data_obj_write_request().  The ATT MTU size is negotiable, see the BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST case in ble_evt_handler() in nrf_dfu_ble.c. It can be set as high as NRF_SDH_BLE_GATT_MAX_MTU_SIZE, i.e. 247.

    Best regards

    Bjørn

  • Hi Bjorn,

    I have the init packet as 141 bytes. I am sending over the DFU packet characteristics as 15 bytes from nrf52833 controller. The another nrf52833 DFU bootloader receives upto 135 bytes. the last set of 6 bytes are not received by the bootloader. If i retransmit also, it gives the same result. Please suggest how to send all the 141 init bytes data.

Reply
  • Hi Bjorn,

    I have the init packet as 141 bytes. I am sending over the DFU packet characteristics as 15 bytes from nrf52833 controller. The another nrf52833 DFU bootloader receives upto 135 bytes. the last set of 6 bytes are not received by the bootloader. If i retransmit also, it gives the same result. Please suggest how to send all the 141 init bytes data.

Children
No Data
Related