Hi,
I want to write flash using received data in BLE interrupt handler(on_ble_evt()). When i received some data from BLE, i try to write it to flash and wait until done.
- But, It's waiting forever... what's the problem?
- How much data can be written in flash without pending?
- Is there any good example, writing (ble received)data in on_ble_evt ?
Here is my flash write function
void write_flash(...) {
// erase
app_flash_erase((uint32_t *)dst, num_pages));
// store
app_flash_store(ptr_dest, ptr_src, FS_MAX_WRITE_SIZE_WORDS)
// wait
app_flash_wait();
}
In app_flash_wait(), there are some flags for operation done & check it until done
static fs_ret_t app_flash_wait(void)
{
if ((m_flags & FLASH_FLAG_SD_ENABLED) != 0)
{
while ((m_flags & FLASH_FLAG_OPER) != 0)
{
(void)sd_app_evt_wait();
}
if ((m_flags & FLASH_FLAG_FAILURE_SINCE_LAST) != 0)
{
return FS_ERR_FAILURE_SINCE_LAST;
}
}
return FS_SUCCESS;
}
and make a callback(app_fs_event_handler) to set flags done & register it like this
// Our fstorage configuration.
FS_REGISTER_CFG(fs_config_t app_fs_config) =
{
.callback = app_fs_event_handler,
.num_pages = 3,
.priority = 0xFE // 1 lower than the peer manager
};
edit 1
AS-IS
on_evt_ble() {
// receive some data
// write received data to flash
(before call library, We should guarantee flash operation has done)
// call 3rd party library
}
TO-BE (is this ok?)
on_evt_ble() {
// receive some data
// put event
app_sched_event_put(p_event_data, event_size, handler)
}
handler() {
// write received data to flash
(before call library, We should guarantee flash operation has done)
// call 3rd party library
}
main()
{
while() {
app_sched_execute()
}
}