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

Calling on_connect causes problems in SDK 14

Hi

I'm migrating to SDK14 currently. My program seems to hit an infinite loop (or something of the sort) after I call my_service_on_connect() from my_service_on_ble_evt. Here are the two functions:

void ble_my_service_on_ble_evt(ble_evt_t const *p_ble_evt, void *context) {
	ble_my_service_t *p_my_service = (ble_my_service_t *) p_my_service;
	switch (p_ble_evt->header.evt_id)
	{
	    case BLE_GAP_EVT_CONNECTED:
	    	ble_my_service_on_connect(p_my_service, p_ble_evt);
	        break;
	    case BLE_GAP_EVT_DISCONNECTED:
	    	ble_my_service_on_disconnect(p_my_service, p_ble_evt);
	        break;
	    default:
	        // No implementation needed.
	        break;
	}
}

static void ble_my_service_on_connect(ble_my_service_t *p_my_service, ble_evt_t const *p_ble_evt)
{
    p_my_service->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
}

Immediately after I hit connect on the phone, the program is unresponsive and does not output any other messages to the terminal that it usually does. I'm not calling any characteristic update functions.

If I comment out ble_my_service_on_connect(), the program works fine. This would imply that my_service_init() is working fine.

Any ideas?

SDK14.0 nrf52832 sd132

  • That sounds really strange, ble_my_service_on_connect() doesn't do much. Have you tried to use the debugger? Are you able to get past ble_my_service_on_connect()? Or what happens if you print something after ble_my_service_on_connect()? Or inside?

  • From nrf_log statements I can tell that it's returning from my_service_on_connect() and reaching the end of my_service_on_ble_evt(), but I can't step past that function without crashing the ble stack. I'll do some more debugging and see if I can find out 1) where else the program is reaching before it stalls or 2) where it might be accessing p_my_service->conn_handle = p_ble_evt->evt.gap_evt.conn_handle.

    For what it's worth, I'm declaring the observer like so: NRF_SDH_BLE_OBSERVER(m_my_service_ble_observer, APP_BLE_OBSERVER_PRIO, ble_my_service_on_ble_evt, (void*) &m_my_service);

    ^^Does that look correct?

  • Found my problem:

    ble_my_service_t *p_my_service = (ble_my_service_t *) p_my_service
    

    should be

    ble_my_service_t *p_my_service = (ble_my_service_t *) context;
    
Related