Bootloader address flash write

1. Hi i am utilizing nrf52840 sdk with ver 17.1.10 s140 and i have the central UART as main app from there we are calling bootloader

2. Before calling bootloader ble dfu we are writing the data in the Flash address 0x3e000 4 bytes

3. After entering into bootloader ble dfu mode the flash address 0x3e000  data is FF 

4.  which flash address i can write so that the value remains  even it enters into ble bootloader dfu 

5. for flash writing i am using fstorage funcions   in the main central uart app

ret_code_t ret = nrf_fstorage_erase(&fstorage, 0x3e000, 1, NULL);


ret_code_t ret1 = nrf_fstorage_write(&fstorage, 0x3e000, &data_wrt, sizeof(data_wrt), NULL);


Parents Reply Children
  • Hi thanks for your reply i need to write only 1 byte data and currently i am using fstorage libraries can we achieve using this or is there any other method for writing small data into flash or any registers that can be used ?

  • Can you please elaborate on what you are trying to achieve? The minimum write size for flash is 4 bytes.

  • 1. So i need  to retain the data at least 4 byte even if it enters into bootloader_ble dfu after triggering form the main central UART

    2.  I have explained requirements in the above post so need to know that for writing at least 4 bytes is possible using fstorage because we need to erase before writing 

    3. Is it required to erase 4096 bytes before writing the data ?

    3. Is there any other method like registers, so that i can write 4 bytes data in the flash and that should be accessible even if it enters in the bootloader_ble dfu mode also 

    Note : I need only 1 byte if it is not happening 4 bytes is also ok but i need a simple way to write small data in flash or registers so that i can access in bootloader_ble dfu also    

  • I'm trying to understand your goal is. If just want the app to be able to pass a flag/value to the bootloader, you could just use the one of the General purpose retention registers (GPREGRET). These are retained through a Soft reset.

    Note that there are two of these registers available, and one is used by the bootloader when NRF_BL_APP_CRC_CHECK_SKIPPED_ON_GPREGRET2 is enabled, and the other when NRF_BL_DFU_ENTER_METHOD_GPREGRET is enabled.

  • 1. Hi  after setting the GPREGRET2 register value  in which address should i verify that the value is written properly 

    i have the following code snippet in central uart app before calling ble bootloader is this a correct method ?

    // Clear GPREGRET register
    err_code = sd_power_gpregret_clr(0, 0xFF);

    // Set GPREGRET register to trigger DFU
    err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START);

    // Clear GPREGRET2 register
    err_code = sd_power_gpregret_clr(1, 0xFF);

    // Set GPREGRET2 register
    err_code = sd_power_gpregret_set(1, 0x56);

    // Reset the system

    2. I Tried to write the register in the Bootloader_ble_debug app to verify whether we can able to write and read the data  but error code 01 is returned form the func what are the required things to be done before writing into it 

    code snippet 

    uint32_t err_code;

    err_code = sd_power_gpregret_clr(1, 0xFF);
    NRF_LOG_DEBUG("ret 1 = %d\n", err_code);

    // Set GPREGRET2 register
    err_code = sd_power_gpregret_set(1, 0x56);
    NRF_LOG_DEBUG("ret 2 = %d\n", err_code);

    uint32_t custom_data = NRF_POWER->GPREGRET2;

    NRF_LOG_DEBUG("custom data 0x%04X", custom_data);


    <info> app: Inside main
    <debug> app: ret 1 = 1

    <error> app: Received an error: 0x00000001!

    Note : i have tried to achieve that read and write in both the app for verification of this GPREGRET2 register