Problem with fstorage and ble init


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();

// 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);

// Enable BLE stack.
err_code = nrf_sdh_ble_enable(&ram_start);

// 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)){
(void) sd_app_evt_wait();

void test(void){
ret_code_t ret = nrf_fstorage_init(&my_instance, &nrf_fstorage_sd, NULL);
uint8_t msg = 0;
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.


for (;;){idle_state_handle();}


I would appreciate any help that you can supply to me.


Paulo Matos

No Data
  • Hi,

    Which SDK version are you using? I will assume SDK 15.2 for now.

    Which of the fstorage implementations are you using? I ask because there are several implementation files:

    • nrf_fstorage_nvmc.c works without the SoftDevice (which is the situation before you call ble_stack_init ())
    • nrf_fstorage_sd.c works with the SoftDevice (which is the situation after you call ble_stack_init ())

    When you use the SoftDevice you should initialize it first, then initialize fstorage after, using the SoftDevice compatible implementation.