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

Write to FLASH after BLE init

I am working in sdk14 nrf52832 I want to write flash after BLE initializing ,but write flash it has no action

while(sd_flash_page_erase(64) != NRF_SUCCESS){} //address = 0x40000
while(sd_flash_write((uint32_t *)0x40000,(uint32_t *)&ptr,((sizeof(TypedefBle)+3)/4))){}
NVIC_SystemReset();
Parents
  • Hi,

    Putting the function call inside a loop won't guarantee that the flash operation is finished after the loop.

    As in the documentation of sd_flash_page_erase and sd_flash_write, you need to wait for the flash callback event :

    NRF_EVT_FLASH_OPERATION_SUCCESS - The command was successfully completed.
    NRF_EVT_FLASH_OPERATION_ERROR - The command could not be started.
    

    Before you proceed to the next command. If you want to reset after you write, you need to wait for the NRF_EVT_FLASH_OPERATION_SUCCESS callback event of the write command.

  • NRF_EVT_FLASH_OPERATION_SUCCESS 's one of the system events. You need to register a callback function as an observer for system events by using NRF_SDH_SOC_OBSERVER

    But in ble_app_hids_keyboard example, we already use fstorage, I would suggest to register an application with fstorage and use the fstorage API to do flash operation. Read more about fstorage here, example included.

Reply Children
No Data
Related