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);

wait_for_flash_ready(&fstorage);

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

wait_for_flash_ready(&fstorage);

  • 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);
    APP_ERROR_CHECK(err_code);

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

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

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

    // Reset the system
    NVIC_SystemReset();
    }

    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);
    APP_ERROR_CHECK(err_code);

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

    uint32_t custom_data = NRF_POWER->GPREGRET2;

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

    logs:

    <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

  • The GPREGRET registers are included in the POWER peripheral, which the Softdevice reserves access to. Therefore, you need to use the sd_power_gpregret_* APIs to access these registers in the application while the Softdevice is enabled. However, these functions cannot be when the Softdevice is disabled, hence the NRF_ERROR_SVC_HANDLER_MISSING ('1')  error. 

    You can see how the nrf_power_gpregret* functions are used in the bootloader.

  • Hi vidar Berg thanks for your reply

    1.I have tried with nrf_power_gpregret api by writing and reading in the register it is working fine in bootloader_ble_debug app

    2.but when we tried to read only using nrf_power_gpregret2_get() after power reset the data is 0 is that the register value becoming 0 after power reset or any where it is clearing in the code after reset in booloader_ble_debug sdk

    3. Can i verify through any particular flash address or the register address so that the data is written

    4. Is there any other registers which will retain its value even after power reset


    // nrf_power_gpregret2_set(0x56);
    // APP_ERROR_CHECK(err_code);

    // Set GPREGRET register to trigger DFU
    uint8_t ret = nrf_power_gpregret2_get();
    APP_ERROR_CHECK(err_code);

    logs:

    ret = 0x0
    <info> app: Inside main
    <debug> app: In nrf_bootloader_init
    <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    <debug> nrf_dfu_settings: Using settings page.
    <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
    <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    <debug> app: Enter nrf_bootloader_fw_activate
    <info> app: No firmware to activate.
    <info> app: Boot validation failed. No valid app to boot.
    <debug> app: DFU mode because app is not valid.
    <info> nrf_bootloader_wdt: WDT is not enabled
    <debug> app: in weak nrf_dfu_init_user
    <debug> app: timer_stop (0x2000599C)
    <debug> app: timer_activate (0x2000599C)
    <info> app: Entering DFU mode.
    <debug> app: Initializing transports (found: 1)
    <debug> nrf_dfu_ble: Initializing BLE DFU transport
    <debug> nrf_dfu_ble: Setting up vector table: 0x000F1000
    <debug> nrf_dfu_ble: Enabling SoftDevice.
    <debug> nrf_dfu_ble: Configuring BLE stack.
    <debug> nrf_dfu_ble: Enabling the BLE stack.
    <debug> nrf_dfu_ble: No advertising name found
    <debug> nrf_dfu_ble: Using default advertising name
    <debug> nrf_dfu_ble: Advertising...
    <debug> nrf_dfu_ble: BLE DFU transport initialized.
    <debug> nrf_dfu_flash: Initializing nrf_fstorage_sd backend.
    <debug> app: Enter main loop

  • Hi I am using s140 soft device ver 7.2.0 will flash address remains same as you have posted above or there is any changes will be there

  • 1. Hi I need to write in flash address but my issue is before writing anything I should erase atleast 4kB data in flash address then only I can write 

    2. Is there any thing like we can erase only required bytes in flash 

Related