This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Hang on BLE connect - custom service SDK13 migration

I'm migrating from SDK11 to SDK13. My custom service is based off Heart Rate Service, so I started from the new SDK13 example of HRS, and updated all the initialization code following the new example.

Changed: ble_cg.common_cg.vs_uuid__cfg.vs_uuid_count = 2; and adjusted the linker script according to the forum post answer about this.

The issue that comes up appears to occur in the on_connect function within the service. If i comment it out, I can connect, discover services and receive write events. With it implemented, the firmware hangs right after the connection event.

The on_connect function is literally just assigning the conn_handle, is there anything going on behind the scenes in the softdevice at this point?

static void on_connect(ble_cgm_t * p_cgm, ble_evt_t * p_ble_evt)
{
        p_cgm->conn_handle = p_ble_evt->evt.evt.gap_evt.conn_handle;
}

The value of conn_handle is 0. I've tried manually setting p_cgm->conn_handle to 0 at this point as well, and the same thing occurs. Should conn_handle not be 0?

I have tried both with and without the new gatt_evt, just in case that was the issue, but doesn't appear to be it.

Thanks

EDIT: additional code Function where on_connect is called

void ble_cgm_on_ble_evt(ble_cgm_t * p_cgm, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_cgm, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_cgm, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_cgm, p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
        }
}

the ble_cgm_on_ble_evt handler is called from a higher level handler: cgm_on_ble_evt (shown below), which is called directly from ble_evt_dispatch

void cgm_on_ble_evt(ble_evt_t * p_ble_evt)
{
	switch (p_ble_evt->header.evt_id)
    {
		case BLE_GATTS_EVT_HVN_TX_COMPLETE: //depreciated: BLE_EVT_TX_COMPLETE:
			if (sending)
			{
				if(data_ready)
					continueDataSend();
			}
			else
			{
				if (backwards && (sendingStart-sendingLength) > sendingEnd)
				{
					sending = true;
					dataSyncSendBackward(sendingEnd, (sendingStart-sendingLength));
				}

				if (!backwards && (sendingStart+sendingLength) < sendingEnd)
				{
					sending = true;
					dataSyncSendForward((sendingStart+sendingLength), sendingEnd);
				}
			}
		break;
	}
	ble_cgm_on_ble_evt(&m_cgm, p_ble_evt);
}

This handler (cgm_on_ble_evt) is at the level where m_cgm is defined

ble_cgm_t m_cgm;				/**< Structure used to identify the CGM service. */

And the ble_cgm_t structure looks like this.

/**@brief Service structure. This contains various status information for the service. */
struct ble_cgm_s
{
    ble_cgm_evt_handler_t        evt_handler;          /**< Event handler to be called for handling events in the Service. */
    uint16_t                     service_handle;       /**< Handle of the CGM Service (as provided by the BLE stack). */
    ble_gatts_char_handles_t     lsm_handles;          /**< Handles related to the Live Stream characteristic. */
	ble_gatts_char_handles_t     data_handles;         /**< Handles related to the Data Sync characteristic. */
    ble_gatts_char_handles_t     cmd_handles;          /**< Handles related to the Command characteristic. */
	ble_gatts_char_handles_t     stat_handles;         /**< Handles related to the Status characteristic. */
    uint16_t                     conn_handle;          /**< Handle of the current connection (as provided by the BLE stack) */  
	uint8_t						 uuid_type;            /**< UUID type for the CGM Service. */
	ble_cgm_cmd_write_handler_t  cmd_write_handler;    /**< Event handler to be called when the CMD Characteristic is written. */
	//uint8_t                      max_cgm_len;          /**< Current maximum CGM Packet length, adjusted according to the current ATT MTU. */
};

Does ble_cg.common_cg.vs_uuid__cfg.vs_uuid_count need to account for each CHAR UUID?

Related