Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

OTA over serial failure| sdk 15.2

Hello Everyone,

I am using nrf52832 and sdk 15.2 for ota over serial. I have made bootloader for OTA over UART and tested same with nrfutil using my dfu package file. firmware is upgraded successfully and  working fine.

Now I need to upgrade firmware using host MCU. I tried sending dfu package file( .zip ) to nrf52832 over UART using slip librairy to upgrade firmware but it is not working.

Is there any compulsion to send Ping packet, PNR, MTU Packet, init packet, application and bootloader separately over UART?

Can we send directly dfu package created through nrfutil to nrf52832 from other MCU over UART?

Kindly suggest me right approach.

Parents
  • Hello,

     

    Now I need to upgrade firmware using host MCU. I tried sending dfu package file( .zip ) to nrf52832 over UART using slip librairy to upgrade firmware but it is not working.

     From this, I interpret that you want to drag'n'drop from a computer, isn't that right? Is that the final way you want to do it? Or do you want to program the nRF From a microcontroller on a PCB? 

    What HW are you running on? Is it a DK, or is it a custom PCB?

    BR,

    Edvin

  • No, I don't want drag and drop from computer. I want upgrade nrf from other MCU through UART. I have custom PCB. Kindly help for the same.

  • Sorry, I attached the wrong attachment in the previous reply. Attached the correct one now (but you have probably seen something similar when testing yourself.

    6305.nrfutil_dfu_log.txt

    Ok. Did you do any changes to the bootloader project that may affect the behavior of the CRC and EXECUTE commands? Or any other changes that can affect the bootloader?

  • Yes, I changed NRF_DFU_SERIAL_UART_RX_BUFFERS  to 10.

    Please check attached 5305.sdk_config.h file.

  • Did you test the pca10040_uart_debug bootloader with the logging turned on? 

    What does the bottom of the log from the bootloader say? (The log uses RTT Backend)

    In the case where I used nrfutil, it looks like this:

     0> <debug> app: Shutting down transports (found: 1)
     0> <info> nrf_dfu_serial_uart: Allocated buffer 2000311C
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x00033900, pending 0
     0> <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
     0> <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_WRITE (data)
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x00033940, src=0x20003018, len=8 bytes), queue usage: 1
     0> <debug> app: Shutting down transports (found: 1)
     0> <info> nrf_dfu_serial_uart: Allocated buffer 2000311C
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x00033940, pending 0
     0> <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
     0> <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_CRC_GET (data)
     0> <debug> nrf_dfu_req_handler: Offset:26952, CRC:0xC312551E
     0> <debug> nrf_dfu_req_handler: Request handling complete. Result: 0x1
     0> <debug> nrf_dfu_serial: Sending Response: [0x3, 0x1]
     0> <debug> app: Shutting down transports (found: 1)
     0> <info> nrf_dfu_serial_uart: Allocated buffer 2000311C
     0> <debug> nrf_dfu_req_handler: Handle NRF_DFU_OP_OBJECT_EXECUTE (data)
     0> <debug> nrf_dfu_req_handler: Whole firmware image received. Postvalidating.
     0> <debug> nrf_dfu_validation: Hash verification. Firmware start address: 0x2D000, size: 0x6948
     0> <debug> nrf_dfu_validation: Invalidating old application in bank 0.
     0> <debug> nrf_dfu_serial: Sending Response: [0x4, 0x1]
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, src=0x20002D48, len=348 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
     0> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007E000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007E000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007E000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007E000, src=0x20002EB4, len=348 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007E000, pending 0
     0> <debug> nrf_dfu_req_handler: All flash operations have completed. DFU completed.
     0> <debug> app: Shutting down transports (found: 1)
     0> <debug> app: Resetting bootloader.
     0> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
     0> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
     0> <info> app: Inside main
     0> <debug> app: In nrf_bootloader_init
     0> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
     0> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
     0> <debug> nrf_dfu_settings: Settings OK
     0> <debug> app: Enter nrf_bootloader_fw_activate
     0> <debug> app: Valid App
     0> <debug> app: Enter nrf_dfu_app_continue
     0> <info> nrf_bootloader_wdt: WDT is not enabled
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x00026000, len=7 pages), queue usage: 0
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x00026000, pending 0
     0> <debug> app: Copying 0x2D000 to 0x26000, size: 0x6948
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x00026000, src=0x0002D000, len=26952 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x00026000, pending 0
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, src=0x20002D48, len=348 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
     0> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007E000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007E000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007E000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007E000, src=0x20002EB4, len=348 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007E000, pending 0
     0> <debug> app: Setting app as valid
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007F000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007F000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007F000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007F000, src=0x20002D48, len=348 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007F000, pending 0
     0> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
     0> <debug> nrf_dfu_settings: Writing settings...
     0> <debug> nrf_dfu_settings: Erasing old settings at: 0x0007E000
     0> <debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x0007E000, len=1 pages), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash erase success: addr=0x0007E000, pending 0
     0> <debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x0007E000, src=0x20002EB4, len=348 bytes), queue usage: 1
     0> <debug> nrf_dfu_flash: Flash write success: addr=0x0007E000, pending 0
     0> <debug> app: Resetting bootloader.
     0> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
     0> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
     0> <info> app: Inside main
     0> <debug> app: In nrf_bootloader_init
     0> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
     0> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
     0> <debug> nrf_dfu_settings: Settings OK
     0> <debug> app: Enter nrf_bootloader_fw_activate
     0> <info> app: No firmware to activate.
     0> <debug> app: Enter nrf_dfu_app_is_valid
     0> <debug> app: Return true. App was valid
     0> <warning> nrf_dfu_settings: No additional data erased
     0> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
     0> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
     0> <debug> app: Running nrf_bootloader_app_start with address: 0x00001000
     0> <debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
     0> <debug> app: running irq table set
     0> <debug> app: After running irq table set
    

    It would be interresting to see what that log says in your case.

    Best regards,

    Edvin

  • The logs are printed using RTT (via the debugger). If you have your programmer attached you can use Segger RTT Viewer to monitor the logs.

Reply Children
  • Hi ,

    no response when used debug code. I tested on DK board and nrfutil.

    How?

    Before going to discuss this I have a question.

    I you see DFU_logs (1).txt, there is response( 60 01 03 ) for create object for last 3780 bytes but for previous packets it is different (60 01 01). Why it is  NRF_DFU_RES_CODE_INVALID_PARAMETER = 0x03?

    In nrfutil dfu_nrfutil.txt it is showing 0x01.

    It may reason behind dfu fail.

  • There is something in that create object packet that the DFU target doesn't accept. Can you try to debug the bootloader project and see why it returns NRF_DFU_RES_CODE_INVALID_PARAMETER? According to this it is because: "The specified size for a data object is not page aligned, and it is not the last object."

    Best regards,

    Edvin

  • I tried with debug project but not giving any response for ping packet in nrfutil. working on it.

    the error should come for both nrfutil and my MCU also. but in nrfutil it is ok and giving  NRF_DFU_RES_CODE_INVALID_PARAMETER when doing dfu from other MCU. 

    I compared both logs, all the other packets are same as nrfutil.

  • It could be that the issue is due to flow control being disabled. It is a shot in the dark, but if the DFU target doesn't have time to write everything to flash, it may not be ready to receive new packets, and hence doesn't know what to reply to. Perhaps you can try to add some delay between all uart packets, to see whether or not this changes the behavior. 

    I don't think I have shown you this yet, but we have an unofficial project for an nRF working as a serial DFU master. You can find it in this blog, Section 5 "DFU Master code". I have not tested it myself, but perhaps you can look at that implementation.

    Best regards,

    Edvin

  • I tried with the delay's but still same issue.

    I referred "DFU Master code" and implemented same.

    please see follwing code to send app.

    static void uart_send_application_image(uint8_t *data, uint32_t length)
    {
    
    	uint8_t CRC[] = {3};
    	uint32_t CRC_len = 1;
    	uint8_t execute[] = {4};
    	uint32_t exe_len = 1;
    	uint8_t create_obj[10];
    	uint32_t create_obj_len= 6;
    	uint32_t enc_data_len = 0;
    	size_t read_len =0;
    	uint8_t  RespData[100];
    	uint8_t enc_data[100];
    
    	//Create Object
    	create_obj[0]=0x01;
    	create_obj[1]=0x02;//Command Object
    	create_obj[2]=length;
    	create_obj[3]=length>>8;
    	create_obj[4]=length>>16;
    	create_obj[5]=length>>24;
    
    	memset(enc_data,0,sizeof(enc_data));
    	//CREATE COMMAND OBJECT
    	encode_slip(enc_data,&enc_data_len,create_obj,create_obj_len);
    	uart_flush(UART_NUM_1);
    	uart_write_bytes(UART_NUM_1,(char*) enc_data, enc_data_len);
    	uart_wait_tx_done(UART_NUM_1, 5);
    
    	vTaskDelay(10);         //100ms
    	ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUM_1,&read_len));
    	int readBytes = uart_read_bytes(UART_NUM_1, RespData,(uint32_t)read_len, 0);
    
        uint32_t encoded_slip_packet_length;
    
        while(length>0)
        {
            encoded_slip_packet[0]=0x08;//Write object opcode
    
            if (length>=MAX_ACTUAL_PAYLOAD)
            {
            	encode_slip( &encoded_slip_packet[1], &encoded_slip_packet_length, data, MAX_ACTUAL_PAYLOAD);
                length= length-MAX_ACTUAL_PAYLOAD;
                data = data+MAX_ACTUAL_PAYLOAD;
            }else
            {
            	encode_slip( &encoded_slip_packet[1], &encoded_slip_packet_length, data, length);
                length=0;
            }
    
            // send
    
            uart_flush(UART_NUM_1);
    		uart_write_bytes(UART_NUM_1,(char*) encoded_slip_packet, encoded_slip_packet_length+1);
    		uart_wait_tx_done(UART_NUM_1, 5);
        }
    
    	vTaskDelay(1);              //10ms
    	//CRC
    	encode_slip(enc_data,&enc_data_len,CRC,CRC_len);
    	uart_flush(UART_NUM_1);
    	uart_write_bytes(UART_NUM_1,(char*) enc_data, enc_data_len);
    	uart_wait_tx_done(UART_NUM_1, 5);
    
    	vTaskDelay(10);             //100ms
    	ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUM_1,&read_len));
    	readBytes = uart_read_bytes(UART_NUM_1, RespData,(uint32_t)read_len, 0);
    
    	memset(enc_data,0,sizeof(enc_data));
    	//EXECUTE
    	encode_slip(enc_data,&enc_data_len,execute,exe_len);
    	uart_flush(UART_NUM_1);
    	uart_write_bytes(UART_NUM_1,(char*) enc_data, enc_data_len);
    	uart_wait_tx_done(UART_NUM_1, 5);
    
    	vTaskDelay(20);             //200ms
    	ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUM_1,&read_len));
    	readBytes = uart_read_bytes(UART_NUM_1, RespData,(uint32_t)read_len, 0);
    }
    

    Can you please explain in brief how to see logs on RTT viewer. not getting logs yet.

Related