Hi Team,
We are using the NRF52840 Device with S140 Soft device for our BLE applications. As part of this we have enabled the flash storage as well.
We are unable to write to flash when ble is enabled. How to design the things which will work together. Is there any approach or any sample code which will handle the both with out effecting each other.
When we trying to write the flash Advertising is not happening. Here with sharing my current code how we are doing.
int main(void)
{
//Initializations
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
peer_manager_init();
fs_Init();
for (;;)
{
//Flash Data is updated ,writing to Flash sector based on runtime flag
if((true == m_fs_Data_Update) && (true == m_ble_idle_flage))
{
m_ble_idle_flage = false;
CRITICAL_REGION_ENTER();
Update_flash_Data();
CRITICAL_REGION_EXIT();
if(true == m_fs_Data_write)
{
m_fs_Data_Update = false;
m_fs_Data_write = false;
}
}
app_sched_execute();
idle_state_handle();
}
//BLE Idle flag we are updating at ble idle event. Based on this event we are writing the flash data. But we are not entering into BLE_ADV_EVT_IDLE at all.
static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
ret_code_t err_code;
switch (ble_adv_evt)
{
case BLE_ADV_EVT_FAST:
err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
APP_ERROR_CHECK(err_code);
break;
case BLE_ADV_EVT_IDLE:
m_ble_idle_flage = true;
//sleep_mode_enter();
break;
default:
break;
}
}
Can any one suggest me the design approach or sample code which handles flash and BLE synchronously without impacting each other.I tried couple of ways but succeed on this one. we are not calling any blocking calls in flash operations.See below code for flash write.
void Update_flash_Data(void)
{
ret_code_t rc;
uint32_t len = round_up_u32(sizeof(m_sffl_data));
rc = nrf_fstorage_erase(&fstorage, fstorage.start_addr, 1, NULL);
APP_ERROR_CHECK(rc);
//wait_for_flash_ready(&fstorage);
rc = nrf_fstorage_write(&fstorage,fstorage.start_addr, &m_sffl_data, len, NULL);
APP_ERROR_CHECK(rc);
//wait_for_flash_ready(&fstorage);
}
Regards,
Srinivas.V