Hello,
I am trying to erase a page on the internal flash memory of the nRF52840. I am doing this as a BLE peripheral with 1 active connection. The problem I'm facing is that I am not getting any resulting feedback from fstorage after running (queuing) the erase operation (on one page). I have checked the S140 specification, and increased the connection interval significantly (testing on min: 500ms and max: 700ms), with a supervision timeout of 4200ms, and still facing this problem.
Essentially, what I'm trying to say, is that the event handler I have configured with NRF_FSTORAGE_DEF is not even fired after I have executed nrf_fstorage_erase(). By the way, nrf_fstorage_erase() does return NRF_SUCCESS, and so does the initialization of the fstorage API.
I will provide some code below. I am running the code on an nRF52840-DK, with nRF5 SDK v17.0.2 and S140 7.2.0. Compiled and flashed on a Mac with gcc-arm-none-eabi-9-2019-q4-major.
#define STORAGE_STATE_IDLE (0U)
#define STORAGE_STATE_WRITING (1U)
#define STORAGE_STATE_ERROR (2U)
static void fs_evt_handler(nrf_fstorage_evt_t * evt);
NRF_FSTORAGE_DEF(nrf_fstorage_t m_fs_config) =
{
.start_addr = (const uint32_t )START_ADDR,
.end_addr = (const uint32_t )END_ADDR,
.evt_handler = fs_evt_handler, // Function for event callbacks.
};
static volatile uint32_t m_storage_state = STORAGE_STATE_IDLE;
void hal_erase(uint8_t *start_page, uint32_t num_pages)
{
m_storage_state = STORAGE_STATE_WRITING;
uint32_t err_code = nrf_fstorage_erase(&m_fs_config, (const uint32_t) start_page, num_pages, NULL);
if (err_code != NRF_SUCCESS)
{
m_storage_state = STORAGE_STATE_IDLE;
NRF_LOG_ERROR("Could not request erase flash page (0x%02x).\r\n", m_fs_err_code);
}
while (m_storage_state == STORAGE_STATE_WRITING)
{
/* Feed watch dog while waiting for fstorage result */
/* TODO: Why does fs_evt_handler not get fired */
bsp_wdt_feed();
}
}
static void fs_evt_handler(nrf_fstorage_evt_t * evt)
{
if (evt->result != NRF_SUCCESS)
{
NRF_LOG_ERROR("result: 0x%02x\r\n", evt->result);
/* Write failed, go to error state. */
m_storage_state = STORAGE_STATE_ERROR;
}
else
{
/* Write succeeded, go to idle state again. */
m_storage_state = STORAGE_STATE_IDLE;
}
}
I am calling hal_erase() with num_pages=1 and a start address for a page in the flash memory. I get stuck in the while loop that feeds the watchdog due to the event handler of fstorage never being fired so m_storage_state is never modified. I have verified that I am indeed stuck in that particular loop (with logging) and not some other higher priority context.