I have been trying to integrate support for multiperipherals into my application, but am continuing to get errors when attempting to start advertising after the first connection.
I'm running S332 v4.0.2 + SDK13.1
The difference between my application and the SDK13.1 MultiPeripheral example is that I'm setting some custom configuration information prior to calling softdevice_enable ... so I decided to take the multipheripheral example and modify it to see if it worked with other than the default tag configuration, and it doesn't seem happy...
The only changes I've made to the SDK13.1 MultiPheripheral example are below.
I'm getting NRF_ERROR_INVALID_PARAM if I call this with anything other than 0 for CONN_CFG_TAG : err_code = sd_ble_gap_adv_start(&adv_params, CONN_CFG_TAG);
#define CONN_CFG_TAG 1
static void ble_stack_init(void)
{
ret_code_t err_code;
nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
// Initialize the SoftDevice handler module.
SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
// Fetch the start address of the application RAM.
uint32_t ram_start = 0;
err_code = softdevice_app_ram_start_get(&ram_start);
APP_ERROR_CHECK(err_code);
// Overwrite some of the default configurations for the BLE stack.
ble_cfg_t ble_cfg;
memset(&ble_cfg, 0, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = CONN_CFG_TAG;
ble_cfg.gap_cfg.role_count_cfg.periph_role_count = PERIPHERAL_LINK_COUNT;
ble_cfg.gap_cfg.role_count_cfg.central_role_count = 0;
ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 0;
err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);
// Enable BLE stack.
err_code = softdevice_enable(&ram_start);
APP_ERROR_CHECK(err_code);
// Subscribe for BLE events.
err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
APP_ERROR_CHECK(err_code);
}
I'm then calling advertising_start - which references the CONN_CFG_TAG
static void advertising_start(void)
{
ret_code_t err_code;
ble_gap_adv_params_t adv_params;
// Start advertising
memset(&adv_params, 0, sizeof(adv_params));
adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
adv_params.p_peer_addr = NULL;
adv_params.fp = BLE_GAP_ADV_FP_ANY;
adv_params.interval = APP_ADV_INTERVAL;
adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS;
err_code = sd_ble_gap_adv_start(&adv_params, CONN_CFG_TAG);
APP_ERROR_CHECK(err_code);
bsp_board_led_on(ADVERTISING_LED);
}
... and ... setting it after advertising init, but before advertising_start
static void advertising_init(void)
{
ret_code_t err_code;
ble_advdata_t advdata;
ble_advdata_t scanrsp;
ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};
// Build and set advertising data
memset(&advdata, 0, sizeof(advdata));
advdata.name_type = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance = true;
advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
memset(&scanrsp, 0, sizeof(scanrsp));
scanrsp.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
scanrsp.uuids_complete.p_uuids = adv_uuids;
err_code = ble_advdata_set(&advdata, &scanrsp);
APP_ERROR_CHECK(err_code);
ble_advertising_conn_cfg_tag_set(CONN_CFG_TAG);
}