We develop BLE server application on nRF52840 with SDK 1.5 using nRF52840-Preview-DK.
The application is built as multi tasks with freeRTOS where BLE is one of the tasks.
The implementation of BLE task was migrated from another application which was developed on nRF52832 with SDK 1.4 and based on sample code of hrs + freeRTOS from SDK.
Unlike nRF52832+ SDK 1.4 implementation, with nRF52840 + SDK 1.5 I can't start advertising as part of BLE task (calling ble_start function) and required to use nrf_sdh_freertos_init API
From debug print (see log below) I can observe that freeRTOS initilized advertising and using nRF connect mobile application I can detect the device but I wasn't able to connect to it.
Seems that connect request event wasn't detect by SD or wasn't transfer to ble_evt_handler function.
1) Why there are differences between nRF52832 (SDK 1.4) and nRF52840 (SDK 1.5) regarding start advertising code?
If I use nRF52832 code and call ble_start() function I receive exception of freeRTOS
0> <error> app: ERROR 3735928559 [Unknown error code] at ...\freertos\source\tasks.c:1837
0> PC at: 0x0002B6BD
0> <error> app: End of error report
2) How can I debug connect request path from SD to ble_evt_handler () function?
Thanks in advance for any lead or clue
0> <info> app: BLE : BLETask()
0> <info> app: BLE : ble_init()
0> <info> app: BLE : ble_stack_init()
0> <info> app: BLE : gap_params_init()
0> <info> app: BLE : gatt_init()
0> <info> app: BLE : services_init()
0> <info> app: BLE : advertising_init()
0> <info> app: BLE : conn_params_init()
0> <info> app: BLE : BLETask() - BLE_ENABLE
0> <debug> nrf_sdh_freertos: Creating a SoftDevice task.
0> <debug> nrf_sdh_freertos: Enter softdevice_task.
0> <info> app: BLE :ble_adv_evtvt(BLE_ADV_EVT_FAST)
0> <info> app: BLE : on_adv_evt(BLE_ADV_EVT_IDLE)
//__________________________________________________________
void main ()
{
...
if (pdPASS != xTaskCreate(BLETask, "BLETask", BLE_TASK_STACK_DEPTH, NULL, BLE_TASK_PRIORITY, &m_oBLETaskHandle))
{
NRF_LOG_WARNING("Init - BLE task creation failed");
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
...
}
void BLETask (void * pvParameter)
{
UNUSED_PARAMETER(pvParameter);
NRF_LOG_INFO("BLE : BLETask()");
ble_init();
#ifdef BLE_ENABLE
NRF_LOG_INFO("BLE : BLETask() - BLE_ENABLE");
bool erase_bonds;
nrf_sdh_freertos_init(advertising_start, &erase_bonds);
// ble_start();
#endif
while (true)
{
ble_queue_service ();
taskYIELD();
}
}
void ble_init (void)
{
NRF_LOG_INFO("BLE : ble_init()");
ble_stack_init();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
}
uint32_t ble_start ()
{
NRF_LOG_INFO("BLE : ble_start() - BLE enable - start advertising");
return (ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST));
}
static void delete_bonds(void)
{
ret_code_t err_code;
NRF_LOG_INFO("BLE : delete_bonds () - Erase bonds!");
// err_code = pm_peers_delete();
APP_ERROR_CHECK(err_code);
}
/**@brief Function for starting advertising. */
static void advertising_start(void * p_erase_bonds)
{
bool erase_bonds = *(bool*)p_erase_bonds;
if (erase_bonds)
{
delete_bonds();
// Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
}
else
{
ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
}
}
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("BLE : ble_evt_handler() -Connected");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
break;
case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("BLE : ble_evt_handler() - Disconnected");
m_conn_handle = BLE_CONN_HANDLE_INVALID;
break;
...