Hi:
I am having a problem with the fstorage and ble_stack_init. When fstorage is used before the ble_stack_init it works fine. If used after ble_stack_init, the fstorage handler is not called. I tried several combinations among test() and ble_stack_init and even replace the erase by the write and read operations, but the problem is always the same. Apparently, after the ble_stack_init, the handler of the fstorage module is not longer called and the program crashes (app_error_fault_handler is called). I am using the ble_app_hids_mouse as base project.
static void ble_stack_init(void)
{
ret_code_t err_code;
err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);
// Configure the BLE stack using the default settings.
// Fetch the start address of the application RAM.
uint32_t ram_start = 0;
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);
// Enable BLE stack.
err_code = nrf_sdh_ble_enable(&ram_start);
APP_ERROR_CHECK(err_code);
// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}
uint32_t fs_callback_flag=0;
void fs_evt_handler(nrf_fstorage_evt_t * evt){
if(evt->result == NRF_SUCCESS){
fs_callback_flag= 0;
}
}
NRF_FSTORAGE_DEF(nrf_fstorage_t my_instance) = {
.evt_handler = fs_evt_handler,
.start_addr = 0x00078000,
.end_addr = 0x0007FFFF,
};
void wait_for_flash_ready(){
/* While fstorage is busy, sleep and wait for an event. */
while (nrf_fstorage_is_busy(&my_instance)){
#ifdef SOFTDEVICE_PRESENT
(void) sd_app_evt_wait();
#else
__WFE();
#endif
}
}
void test(void){
ret_code_t ret = nrf_fstorage_init(&my_instance, &nrf_fstorage_sd, NULL);
uint8_t msg = 0;
wait_for_flash_ready();
fs_callback_flag = 1;
ret = nrf_fstorage_erase(&my_instance, my_instance.start_addr, 1, &msg);
if (ret == NRF_SUCCESS) while(fs_callback_flag) nrf_delay_ms(25);
}
int main(void){
// Initialize.
log_init();
test();
ble_stack_init();
test();
...
for (;;){idle_state_handle();}
}
I would appreciate any help that you can supply to me.
Thanks,
Paulo Matos