This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding whitelist causes crash

I'm still learning about whitelisting, advertising, ect. My project originated as a copy of the ble_hrs example provided by nordic. I wanted to add the ble_cts_c service client to my project, so I began integrating the relevant parts from ble_cts_c example (also from nordic).

After erasing the device and flashing the softdevice and code, the program works as expected. On every subsequent run, there is a soft device crash immediately after advertising_start(). Only erasing and reflashing everything clears the error.

Here is my code for advertising_init():

static void advertising_init(void)
{
    ret_code_t             err_code;
    ble_advdata_t          advdata;
    ble_adv_modes_config_t options;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));
    advdata.name_type               = BLE_ADVDATA_SHORT_NAME; //BLE_ADVDATA_FULL_NAME;
    advdata.short_name_len 			= 1;
    advdata.include_appearance      = true;
    advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    //advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    //advdata.uuids_complete.p_uuids  = m_adv_uuids;
    advdata.uuids_solicited.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_solicited.p_uuids  = m_adv_uuids;

    memset(&options, 0, sizeof(options));
    options.ble_adv_whitelist_enabled 	= true;
    options.ble_adv_fast_enabled  		= true;
    options.ble_adv_fast_interval 		= APP_ADV_FAST_INTERVAL;
    options.ble_adv_fast_timeout  		= APP_ADV_FAST_TIMEOUT;
    options.ble_adv_slow_enabled        = true;
    //options.ble_adv_directed_enabled	= true;
    options.ble_adv_slow_interval     	= APP_ADV_SLOW_INTERVAL;
    options.ble_adv_slow_timeout      	= APP_ADV_SLOW_TIMEOUT;

    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(CONN_CFG_TAG);
}

Here is advertising_start:

void advertising_start(bool erase_bonds)
{
    if (erase_bonds == true)
    {
        delete_bonds();
        // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
    }
    else
    {
        ret_code_t err_code;

        memset(m_whitelist_peers, PM_PEER_ID_INVALID, sizeof(m_whitelist_peers));
        m_whitelist_peer_cnt = (sizeof(m_whitelist_peers) / sizeof(pm_peer_id_t));

        peer_list_get(m_whitelist_peers, &m_whitelist_peer_cnt);

        err_code = pm_whitelist_set(m_whitelist_peers, m_whitelist_peer_cnt);
        APP_ERROR_CHECK(err_code);

        // Setup the device identies list.
        // Some SoftDevices do not support this feature.
        err_code = pm_device_identities_list_set(m_whitelist_peers, m_whitelist_peer_cnt);
        if (err_code != NRF_ERROR_NOT_SUPPORTED)
        {
            APP_ERROR_CHECK(err_code);
        }

        m_is_wl_changed = false;

        err_code = ble_advertising_start(BLE_ADV_MODE_FAST); //BLE_ADV_MODE_FAST
        APP_ERROR_CHECK(err_code);
    }
}

Here is peer_list_get():

static void peer_list_get(pm_peer_id_t * p_peers, uint32_t * p_size) { pm_peer_id_t peer_id; uint32_t peers_to_copy;

peers_to_copy = (*p_size < BLE_GAP_WHITELIST_ADDR_MAX_COUNT) ?
                 *p_size : BLE_GAP_WHITELIST_ADDR_MAX_COUNT;

peer_id = pm_next_peer_id_get(PM_PEER_ID_INVALID);
*p_size = 0;

while ((peer_id != PM_PEER_ID_INVALID) && (peers_to_copy--))
{
    p_peers[(*p_size)++] = peer_id;
    peer_id = pm_next_peer_id_get(peer_id);
}

}

Any idea what might be causing the crash, or how I can try to further debug the problem?

Thanks

SDK13 PCA10040 nRF52832

Related