Hi all,
I'm working on a project which I started from the multiperipheral example. I am using SDK 15.3.0 for this. I am developing the software on the nrf52840 DK using softdevice S140. This is my first C project (I used C++ until now) and I use the armgcc compiler. I want to store the device state to flash memory. Writing data works fine and I can read it back on a NRF_FSTORAGE_EVT_WRITE_RESULT event. However, I would like to make my write function block until writing is actually finished. For this I use a while loop which checks nrf_storage_is_busy() , however the nrf keeps stuck in this while loop until I reset it.
Some code snippets:
Initialization:
NRF_FSTORAGE_DEF(nrf_fstorage_t m_fstr);
void fstorage_init(void)
{
ret_code_t err_code;
m_fstr.evt_handler = fstorage_evt_handler;
m_fstr.start_addr = DEVICE_STATE_START_ADDRESS;
m_fstr.end_addr = DEVICE_STATE_START_ADDRESS + DEVICE_STATE_SIZE;
err_code = nrf_fstorage_init(&m_fstr, &nrf_fstorage_sd, NULL);
APP_ERROR_CHECK(err_code);
}
Write function:
static int write_flash(size_t addr, void *p_data, size_t size)
{
ret_code_t err_code;
if (is_section_within_bounds(addr, size))
{
err_code = nrf_fstorage_write(&m_fstr, addr, p_data, size, NULL);
if(err_code == NRF_SUCCESS)
{
while(nrf_fstorage_is_busy(&m_fstr))
{
sd_app_evt_wait();
}
return 1;
}
}
return -1;
}
When I uncomment the while loop it works fine. What I tried so far:
- Checked if fstorage backend was set to SD in sdk_config (it is).
- Changed what is executed in the while loop. (to nrf_pwr_mgmt_run(); for example, as nrf_pwr_mgmt is being used)
- Increasing this (If I understand correctly I should only do this when nrf_fstorage_write() is not returning NRF_SUCCESS all the time, but it is)
Could someone tell me what I am doing wrong?