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

DFU with external QSPI memory

Hi,

   I am working on project, in which we using nordic nRF52840 chip. We need to flash the app+SD+BL image file in external QSPI memory.

After prevalidation, the DFU controller starts to send flash image package, we need to receive this and need to save in external QSPI memory. Once the postvalidation is successful, then read all the flash image package stored in external QSPI memory and write it to internal flash memory.

For that we use secure bootloader example code as reference file. I need to know where i need to modify the secure bootloader code.

I noticed that after prevalidation, the flash is erased in on_data_obj_create_request() function in nrf_dfu_req_handler.c file, and flash is written in on_data_obj_write_request() under the same c file. Is that right?

Thanks & Regards

Mohammad Gouse

Parents
  • Hi Hung Bui,

      I have modified the files nrf_fstorage_nvmc.c, nrf_flash.c, nrf_dfu_flash.c (with their corresponding header file) to have external qspi memory interface.

    Once the device enter into DFU mode, it initialize the nrf_dfu_req_handler_init(), so I modified this function by adding nrf_dfu_qspi_init() in it.

      In this project, MX25R6435F used as external QSPI memory. The memory map of this will be same as Nordic system memory map, but without MBR and Bootloader (In our case bootloader in internal flash memory).

    Step 1: After pre-validation, I need to copy the image file (SD + APP) to external QSPI. Now I need to know where I need to change the code to proceed to next step.

  • Hi Mohammad, 

    I assume you are familiar with the DFU procedure as described here

    After you pass the pre-validation (received the init packet and then got the NRF_DFU_OP_OBJECT_WRITE to execute it), you will receive the data objects. 

    They will be handled inside nrf_dfu_data_req(). It will start with the NRF_DFU_OP_OBJECT_CREATE and the page will be erased with the call to nrf_dfu_flash_erase() inside on_data_obj_create_request(). You would need to modify that function to erase the QSPI flash page instead. 

    Next is NRF_DFU_OP_OBJECT_WRITE , which handled in on_data_obj_write_request(). You need to modify nrf_dfu_flash_store() to store on QSPI. And so on. 

    I'm not 100% sure why you would need to make the addressing on QSPI the same as on the internal chip. But it's up to you. You can have a look at our discussion with TomWS above to know about other stuff you need to modify. 

  • Hi TomWS, Thanks for your reply. Can you pls let me know where i need to use this, EXTERNAL_FLASH_ADDRESS=0x0A00000;

    I would have expected you to know this by now.  However, to answer your question, there are two places where this is relevant.  On the start of download where the DFU code gets the Bank1 start address:

    File: nrf_dfu_utils.c, nrf_dfu_bank1_start_addr()

    You need to return the synthetic address used to distinguish your external flash.

    And in your QSPI read & write functions where you need to strip off the upper bits of the synthetic address before using it.

    Note, as mentioned in an earlier reply (about 2 months ago), once you use a 'synthetic' address that is outside the range of the device flash, you need to modify the error checking in  nrf_dfu_cache_prepare() as in:

     

            //TWS: IGNORED! ASSERT(cache_address <= DFU_REGION_END(bootloader_start_addr));
            //TWS: REPLACED BELOW: cache_too_small = required_size > (DFU_REGION_END(bootloader_start_addr) - cache_address);
            cache_too_small = required_size > EXTERNAL_FLASH_SIZE;
            delete_more     = cache_too_small || single_bank; // Delete app or SoftDevice only if we need more room, or if single bank is requested.
    

  • Hi TomWS,

    Thanks for rour response.

    I have made modification according to your instruction. But it throws hardware error after the hash verification succeed.

    nrf_dfu_bank1_start_addr(void) will return return ALIGN_TO_PAGE(0x0A00000 + bank0_addr + s_dfu_settings.bank_0.image_size);

    ASSERT((cache_address & 0x000FFFFF) <= DFU_REGION_END(bootloader_start_addr));
    cache_too_small = required_size > (DFU_REGION_END(bootloader_start_addr) - (cache_address & 0x000FFFFF));
    delete_more = cache_too_small || single_bank; // Delete app or SoftDevice only if we need more room, or if single bank is requested.

    And strip off the upper bits of the synthetic address before using in QSPI read & write functions.

  • I'm not sure why you're getting a hardware fault, examining the stack might give you a clue.  However, I also don't know why you're modifying the bank1 start address.  ISTM that using the beginning of the QSPI memory should be sufficient.  What you store in QSPI flash doesn't have to have the same location as the firmware address.  Here is my dfu_bank1_start_addr():

    uint32_t nrf_dfu_bank1_start_addr(void)
    {
      if ((s_dfu_settings.bank_0.bank_code == NRF_DFU_BANK_VALID_APP) && s_dfu_settings.bank_0.image_size) { // is there an app already loaded?
        return EXTERNAL_FLASH_ADDRESS;  // yes, use external flash for bank1
      }    
      // no, use bank 0 for downloading
      uint32_t bank0_addr = nrf_dfu_bank0_start_addr();
      return ALIGN_TO_PAGE(bank0_addr + s_dfu_settings.bank_0.image_size);
    }
    

  • After the hash is verified successfully. Old setting are erased and new one written at 0x000FF000 and 0x000FE000. Then bootloader resets and check the backup settings which inturn throws ""Destination settings are identical to source, write not needed. Skipping".

    After that it goes to NMI_Handler Exception.

    But when i disable the External QSPI storage and work with standard bootloader code everything works fine, there is no NMI_Handler Exception.

    Pls help me to solve this issue.

  • Hi Hung Bui & TomWS,

     Sorry for the late response. I am busy with some other task. I have completed the Bootloader for QSPI external memory. Its working fine.

    I have check the firmware update without SD and also did some modification in SD activation in order to receive new SD upgrade.

    I will write a brief note later on, how to modifiy the present bootloader to place the firmware image(APP + SD), it will help some other guys.

    I thank to Hung Bui and TomWS helping me in this issue.

    But there is a lack of support from nordic team, because Hung Bui has disappeared long back. 

Reply
  • Hi Hung Bui & TomWS,

     Sorry for the late response. I am busy with some other task. I have completed the Bootloader for QSPI external memory. Its working fine.

    I have check the firmware update without SD and also did some modification in SD activation in order to receive new SD upgrade.

    I will write a brief note later on, how to modifiy the present bootloader to place the firmware image(APP + SD), it will help some other guys.

    I thank to Hung Bui and TomWS helping me in this issue.

    But there is a lack of support from nordic team, because Hung Bui has disappeared long back. 

Children
Related