This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

S120 Persistent storage initial clear command never executes

I am using S120 v2 with SDK 6. Initialization of the softdevice and device manager return no errors. However when I want to start a scan for devices, the function checks the status of pstorage with pstorage_access_status_get and finds that the initial storage clear operation initiated by device_manager_central in dm_init when the option clear_persistent_data is set to true, has not been processed yet!

Looking into the workings of pstorage shows that a queued operation is executed only when a system event occurs (pstorage_sys_event_handler). This does not happen between start of the application and my scan request.

I cannot find any flaw in the initialization code of the softdevice, device manager and pstorage.

I hope someone has a clue as to what I am doing wrong or what I am missing. It might make a difference, I am using the scheduler.

PS Because the scan actually does not run (as it waits for pstorage to finish), the scan_stop function that runs on timer expiration, results in an application error caught by app_error_handler. The error says WRONG STATE, which of course is correct while scanning is not running at the moment of the stop request. Should I keep track of state or is there some function to check state?

Parents
  • static void scan_start(void) { uint32_t err_code; uint32_t count; // Verify if there is any flash access pending, if yes delay starting scanning until // it's complete.

      err_code = pstorage_access_status_get(&count);
      APP_ERROR_CHECK(err_code);
    
    if (count != 0)
    {
        m_memory_access_in_progress = true;
        return;
    }
    	
    err_code = sd_ble_gap_scan_start(&m_scan_param);
    APP_ERROR_CHECK(err_code);
    

    }

    /**@brief Function for initializing the BLE stack. *

    • @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; ble_enable_params_t ble_enable_params;

      // Initialize the SoftDevice handler module. //SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false); //SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, false); SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, true);

      // Enable BLE stack memset(&ble_enable_params, 0, sizeof(ble_enable_params)); ble_enable_params.gap_enable_params.role = BLE_GAP_ROLE_CENTRAL; ble_enable_params.gatts_enable_params.service_changed = 0; err_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(err_code);

      // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code);

      // Register with the SoftDevice handler module for System events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }

    /**@brief Function for initializing the Device Manager. *

    • @details Device manager is initialized here. */ static void device_manager_init(void) { dm_application_param_t param; dm_init_param_t init_param;

      uint32_t err_code;

      err_code = pstorage_init(); APP_ERROR_CHECK(err_code);

      // Clear all bonded devices if user requests to. init_param.clear_persistent_data = true; // ((nrf_gpio_pin_read(BOND_DELETE_ALL_BUTTON_ID) == 0)? true: false);

      err_code = dm_init(&init_param); APP_ERROR_CHECK(err_code);

      memset(&param.sec_param, 0, sizeof (ble_gap_sec_params_t));

      // Event handler to be registered with the module. param.evt_handler = device_manager_event_handler;

      // Service or protocol context for device manager to load, store and apply on behalf of application. // Here set to client as application is a GATT client. param.service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID;

      // Secuirty parameters to be used for security procedures. param.sec_param.bond = SEC_PARAM_BOND; param.sec_param.mitm = SEC_PARAM_MITM; param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; param.sec_param.oob = SEC_PARAM_OOB; param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; param.sec_param.kdist_periph.enc = 1; param.sec_param.kdist_periph.id = 1;

      err_code = dm_register(&m_dm_app_id,&param); APP_ERROR_CHECK(err_code); }

    /**@brief Initialize the scheduler. */

    static void scheduler_init(void) { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); }

    /**@brief Function for application main entry. */ int main(void) { uint32_t err_code; memset(m_dlt_list, 0, sizeof(m_dlt_list));

    // Initialization of various modules.
    scheduler_init();
    
    ble_stack_init();
    client_handling_init();
    device_manager_init();
    
    	err_code = serial_port_init(on_serial_message);
    
      for (;;)
    {
        app_sched_execute();
    			err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
    

    }

Reply
  • static void scan_start(void) { uint32_t err_code; uint32_t count; // Verify if there is any flash access pending, if yes delay starting scanning until // it's complete.

      err_code = pstorage_access_status_get(&count);
      APP_ERROR_CHECK(err_code);
    
    if (count != 0)
    {
        m_memory_access_in_progress = true;
        return;
    }
    	
    err_code = sd_ble_gap_scan_start(&m_scan_param);
    APP_ERROR_CHECK(err_code);
    

    }

    /**@brief Function for initializing the BLE stack. *

    • @details Initializes the SoftDevice and the BLE event interrupt. */ static void ble_stack_init(void) { uint32_t err_code; ble_enable_params_t ble_enable_params;

      // Initialize the SoftDevice handler module. //SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false); //SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, false); SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, true);

      // Enable BLE stack memset(&ble_enable_params, 0, sizeof(ble_enable_params)); ble_enable_params.gap_enable_params.role = BLE_GAP_ROLE_CENTRAL; ble_enable_params.gatts_enable_params.service_changed = 0; err_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(err_code);

      // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code);

      // Register with the SoftDevice handler module for System events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); }

    /**@brief Function for initializing the Device Manager. *

    • @details Device manager is initialized here. */ static void device_manager_init(void) { dm_application_param_t param; dm_init_param_t init_param;

      uint32_t err_code;

      err_code = pstorage_init(); APP_ERROR_CHECK(err_code);

      // Clear all bonded devices if user requests to. init_param.clear_persistent_data = true; // ((nrf_gpio_pin_read(BOND_DELETE_ALL_BUTTON_ID) == 0)? true: false);

      err_code = dm_init(&init_param); APP_ERROR_CHECK(err_code);

      memset(&param.sec_param, 0, sizeof (ble_gap_sec_params_t));

      // Event handler to be registered with the module. param.evt_handler = device_manager_event_handler;

      // Service or protocol context for device manager to load, store and apply on behalf of application. // Here set to client as application is a GATT client. param.service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID;

      // Secuirty parameters to be used for security procedures. param.sec_param.bond = SEC_PARAM_BOND; param.sec_param.mitm = SEC_PARAM_MITM; param.sec_param.io_caps = SEC_PARAM_IO_CAPABILITIES; param.sec_param.oob = SEC_PARAM_OOB; param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE; param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE; param.sec_param.kdist_periph.enc = 1; param.sec_param.kdist_periph.id = 1;

      err_code = dm_register(&m_dm_app_id,&param); APP_ERROR_CHECK(err_code); }

    /**@brief Initialize the scheduler. */

    static void scheduler_init(void) { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); }

    /**@brief Function for application main entry. */ int main(void) { uint32_t err_code; memset(m_dlt_list, 0, sizeof(m_dlt_list));

    // Initialization of various modules.
    scheduler_init();
    
    ble_stack_init();
    client_handling_init();
    device_manager_init();
    
    	err_code = serial_port_init(on_serial_message);
    
      for (;;)
    {
        app_sched_execute();
    			err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
    

    }

Children
No Data
Related