This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Go to bootloader from app with preserving pstorage value

hi, i made ble app including bootloader using nRF51822 (s110), sdk 6.1.0

when i use sd_nvic_SystemReset() function in app, it erase app's pstorage. But i want to preserve pstorage.

also when i use sd_power_system_off() function, my kit doesn't wake up.

then.. how can i start bootloader from app with preserving pstorage value?

thanks :)

  • Would be good to know how to do this. Would help in restarting DFU from a BLE command, instead of requiring a manual restart.

  • In a normal application, the pstorage data is stored in the last page in flash. However, when you use bootloader, the bootloader itself also uses the last page in flash for the bootloader settings. The application should then use the last page in flash before the bootloader.

    pstorage_platform.h file contains the "is bootloader present" check for the application with the following code:

    #define PSTORAGE_FLASH_PAGE_END                                     \
            ((NRF_UICR->BOOTLOADERADDR != PSTORAGE_FLASH_EMPTY_MASK)    \
            ? (NRF_UICR->BOOTLOADERADDR / PSTORAGE_FLASH_PAGE_SIZE)     \
            : NRF_FICR->CODESIZE)
    
    #define PSTORAGE_DATA_START_ADDR    ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_MAX_APPLICATIONS - 1) \
                                        * PSTORAGE_FLASH_PAGE_SIZE)
    

    the NRF_UICR->BOOTLOADERADDR is at address 0x10001014 and it should contain the bootloader start address when you have flashed your bootloader. Check it with the following command:

    nrfjprog --memrd 0x10001014 --n 4
    

    So if you see an address there (not 0xFFFFFFFF), then the bootloader address is set and your application data should not be written in the bootloader space, but in the page/pages below the bootloader.

Related