Hi everyone.
I have an application using BLE and OpenThread dynamicaly.
I am working with nRF52840 chip with nRF5 SDK for Thread and Zigbee v4.1.0 (Release Date: Week 18, 2020)
In order to store the advertising data and some mesh parameters, I need to use the flash.
I first try to implement a solution with nrf_fstorage module, but I had a lot of issues with it so I changed for FDS module.
I manage to implement a working solution exept that the first time the chip is programmed (after a full erase), I need to do 3 to 4 resets befor the program starts.
I have been investigating in debug mode. It seems I am stuck somewhere into sd_app_evt_wait();
Here is my code to init the flash :
static bool volatile fdsInitialized; static bool writeTerminated; /************************************* fds_evt_handler ***************************************/ /** * @Brief Simple event handler to handle errors during initialization. */ static void fds_evt_handler(fds_evt_t const * p_evt) { switch (p_evt->id){ case FDS_EVT_INIT: if (p_evt->result == FDS_SUCCESS){ fdsInitialized = true; } break; case FDS_EVT_WRITE: if (p_evt->result == FDS_SUCCESS){ writeTerminated = true; } break; case FDS_EVT_UPDATE: if (p_evt->result == FDS_SUCCESS){ writeTerminated = true; if(netStr2Save.netReset == 1){ //Restar tne Mesh Network with the new name NVIC_SystemReset(); } } break; case FDS_EVT_DEL_RECORD: if (p_evt->result == FDS_SUCCESS){ } break; case FDS_EVT_GC: if (p_evt->result == FDS_SUCCESS){ flash_save_config(&netStr2Save); } break; default: break; } } void flash_init(void){ ret_code_t ret = fds_register(fds_evt_handler); if (ret != FDS_SUCCESS) { return ret; } ret = fds_init(); if (ret != FDS_SUCCESS) { return ret; } while (!fdsInitialized){ sd_app_evt_wait(); } writeTerminated = true; }
The flash init function is called after ble_stack_init in the main.
Here is the SDK config I have got :
/ <e> FDS_ENABLED - fds - Flash data storage module //========================================================== #ifndef FDS_ENABLED #define FDS_ENABLED 1 #endif // <h> Pages - Virtual page settings // <i> Configure the number of virtual pages to use and their size. //========================================================== // <o> FDS_VIRTUAL_PAGES - Number of virtual flash pages to use. // <i> One of the virtual pages is reserved by the system for garbage collection. // <i> Therefore, the minimum is two virtual pages: one page to store data and one page to be used by the system for garbage collection. // <i> The total amount of flash memory that is used by FDS amounts to @ref FDS_VIRTUAL_PAGES * @ref FDS_VIRTUAL_PAGE_SIZE * 4 bytes. #ifndef FDS_VIRTUAL_PAGES #define FDS_VIRTUAL_PAGES 3 #endif // <o> FDS_VIRTUAL_PAGE_SIZE - The size of a virtual flash page. // <i> Expressed in number of 4-byte words. // <i> By default, a virtual page is the same size as a physical page. // <i> The size of a virtual page must be a multiple of the size of a physical page. // <1024=> 1024 // <2048=> 2048 #ifndef FDS_VIRTUAL_PAGE_SIZE #define FDS_VIRTUAL_PAGE_SIZE 1024 #endif // <o> FDS_VIRTUAL_PAGES_RESERVED - The number of virtual flash pages that are used by other modules. // <i> FDS module stores its data in the last pages of the flash memory. // <i> By setting this value, you can move flash end address used by the FDS. // <i> As a result the reserved space can be used by other modules. #ifndef FDS_VIRTUAL_PAGES_RESERVED #define FDS_VIRTUAL_PAGES_RESERVED 4 #endif // </h> //========================================================== // <h> Backend - Backend configuration // <i> Configure which nrf_fstorage backend is used by FDS to write to flash. //========================================================== // <o> FDS_BACKEND - FDS flash backend. // <i> NRF_FSTORAGE_SD uses the nrf_fstorage_sd backend implementation using the SoftDevice API. Use this if you have a SoftDevice present. // <i> NRF_FSTORAGE_NVMC uses the nrf_fstorage_nvmc implementation. Use this setting if you don't use the SoftDevice. // <1=> NRF_FSTORAGE_NVMC // <2=> NRF_FSTORAGE_SD #ifndef FDS_BACKEND #define FDS_BACKEND 2 #endif
I found a few posts on the forum about similar issues, but none of them solved mine.
Would you have any ideas where it could come from ?
Best regards.