Our nRF52832 setup is:
SDK15.0.0
S132 V6.0.0
We have a setup where we are using BLE for various purposes, in both the central and peripheral roles. We upgrade our uC via I2C rather than over the air, and when we do so we erase the flash from the address 0x1000 to 0x77000 and then write a concatenated image containing both the soft device and our application with the padded regions padded by 0xFF.
We have a situation where pm_init() is failing on a number of devices but not others. All devices have the same image written upon upgrade. A previous question mentioned that the flash became corrupt and a nrfjprog --chiperase would sort out the issue, however the nRF52832 chips is not easily accessible when in the field and performing the above upgrade does not resolve the issue.
The order of initialisation is as follows:
uint32_t ret = app_timer_init(); APP_ERROR_CHECK(ret); ret = nrf_sdh_enable_request(); APP_ERROR_CHECK(ret); 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); err_code = nrf_sdh_ble_enable(&ram_start); APP_ERROR_CHECK(err_code); NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL); /* Set the sec_mode config */ err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)"", strlen("")); /* Set the gap_con_params config */ err_code = sd_ble_gap_ppcp_set(&gap_conn_params); APP_ERROR_CHECK(err_code); ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL); APP_ERROR_CHECK(err_code); /* set the conn_params_init_t config */ err_code = ble_conn_params_init(&cp_init); APP_ERROR_CHECK(err_code); /* Set up the UUID for a custom service which our device connects to */ err_code = sd_ble_uuid_vs_add(&base_uuid, &uuid_type); APP_ERROR_CHECK(err_code); err_code = pm_init(); /* This now fails on some devices */ APP_ERROR_CHECK(err_code);
All other calls to the peer manager, in particular pm_conn_secure() fails with the INVALID_STATE error.
A few questions regarding this issue:
- What is the correct flash initialisation value?
- Which section of flash needs to be erased in order to remove the bond data when performing an upgrade?
- Assuming the flash is corrupt and pm_init() fails leading to pm_peers_delete() being unusable, what is the correct way to recover from this situation?
- Is there a specific environment that pm_init() requires in order to initialise?