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?

  • 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);
    }
    

    }

  • @Leon: Do you have the same issue when testing with our stock example (ble_app_hrs_c project for example) ?

    When holding button 1 when start up, we will try to clear the bond information page. There should be an system event after the page is erased. As I'm testing here I got an system event back (pstorage_sys_event_handler()) with NRF_EVT_FLASH_OPERATION_SUCCESS code and op_code = 0x04 means PSTORAGE_CLEAR_OP_CODE.

    And the nRF51 continued to scan and report the advertising packet back.

    Please make sure you have update the API header files for S120 v2.0 to the SDK. Because SDK v6.x came with the API for the S120 v1.0.

  • Thank you for looking into this.

    I have copied the ble_app_hrs_c project from the SDK I copied the include files from S120 include folder to the project include folder for s120 I changed device_manager_central because the interface for sd_ble_gatts_sys_attr_set /get has changed. I have added value 0 as last parameter. I have added call to sd_ble_enable in main\ble_stack_init and changed the SOFTDEVICE_HANDLER_INIT to use my clock I have also added app_scheduler to the project (was missing).

    I cannot flash this project from Keil. Using NrfGo shows why

    image description I made no other changes than the ones mentioned above. The same holds for my actual project. I just added my application code.

    Hope you can help me

  • I made an error in the build. I can flash now and debug. It turns out that this results in exact the same error!

    In scan_start, pstorage_access_status_get(&count) returns count=1. And also no sys_evt NRF_EVT_FLASH_OPERATION_SUCCESS or NRF_EVT_FLASH_OPERATION_ERROR occurs

  • @Leon: Which board are you testing on ? Could you read the laser marking on top of the chip ? Would the S120 run if you don't press button 1 (no flash erasing) when booting up ? Have you experience any issue with the examples for S110 ?

Related