Software Development Aspects:
- nRF52805
- Nordic SDK V 17.1.0
- Softdevice 113 V 7.2.0
- Segger Studio 6.40
I want to store some small user configuration (< 50 Bytes) to flash. So I used fstorage.h, which works perfectly. However sometimes it stops working, sometimes `app_error_fault_handler()` gets called during `nrf_fstorage_write()`, sometimes `nrf_fstorage_read()` returns `NRF_ERROR_INVALID_ADDR`.
So I took a closer look to used global variable `fstorage`.
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
/* Set a handler for fstorage events. */
.evt_handler = fstorage_evt_handler,
/* These below are the boundaries of the flash space assigned to this instance of fstorage.
* You must set these manually, even at runtime, before nrf_fstorage_init() is called.
* The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
* last page of flash available to write data. */
.start_addr = 0x3e000,
.end_addr = 0x3ffff,
};Everytime an error occurs, global variable `fstorage` isn't initialized correctly. After some tests I saw `fstorage` variable is persistent meaning values survice a chip reset. A closer look shows:
nrf_fstorage_t fstorage __attribute__ ((section(".fs_data"))) __attribute__((used)) = ...This means variable `fstorage` resists in section .fs_data, which confuses me a lot.
A further test. I set `fstorage.start_addr` to a value, stopped execution on next statement via debugger and removed power source. After waiting a few seconds I started chip again and looked at `fstorage.start_addr` which remains unchanged.
Does this mean reading values via fstorage.h means writing persistent data three times (see `nrf_fstorage_init()`, `nrf_fstorage_uninit()`)?
When will variable `fstorage` be initialized? I guess only if section .fs_data is empty. In this case I may explain above initialization error.
Why do I need Macro NRF_FSTORAGE_DEF?
PS:
I removed NRF_FSTORAGE_DEF for test purposes and it worked.
