So as part of my system I have something much like the Nordic UART service in that I need to send a notification when something arrives from the UART. Mine is a little bit different from NUS as it doesn't wait for a newline before sending to BLE, instead the notification is triggered either by a buffer full or a timeout so is called from either the UART handler or timer handler.
The notification itself is packaged into a separate routine, which I tested by calling it in my main loop along with a 1 second delay - works absolutely fine.
BUT - if I try to call the same routine from either the UART handler or timer handler the system crashes. No debug or anything, just a complete crash.
The only real difference I can see between my code and NUS code is that I'm not using the link context storage, instead I'm just using the stored connection & attribute handles.
Can you offer any ideas? This is the actual notify code:
uint32_t uartrx_notify(uint8_t * p_data,uint16_t *p_length) { if(m_conn_handle != BLE_CONN_HANDLE_INVALID) { NRF_LOG_INFO("Sending UART notify: handles %d, %d",m_conn_handle,m_bushub_service.uartrx_char_handles.value_handle); ble_gatts_hvx_params_t params; memset(¶ms, 0, sizeof(params)); params.type = BLE_GATT_HVX_NOTIFICATION; params.handle = m_bushub_service.uartrx_char_handles.value_handle; params.p_data = p_data; params.p_len = p_length; return sd_ble_gatts_hvx(m_conn_handle, ¶ms); } else { NRF_LOG_INFO("UART notify - not connected"); } }