Hey everyone,
I've got an nRF52840 DK on my hands. There's an interesting crash occurring when the return value from ble_nus_data_send() is passed to APP_ERROR_CHECK(). Here's what's going on.
The device (nRF52840 DK) is collecting some information and passing it on through Nordic UART Service (NUS); I've basically modified the ble_app_uart example that came with SDK 15.2 and mashed it with peripheral_long_range example (from 15.0, I think). NUS service is initialized at the beginning before the main loop. There's also a timer that is initialized to execute every second and its timeout handler sends data using ble_nus_data_send(). The code compiles ok and runs well on the first instance that a device connects to it. There are no random disconnection issues.
However, when the connected device disconnects and tries to reconnect, nRF52840 crashes and resets. I've managed to trace back the issue with the debugger to the timeout handler of the mentioned timer. Here's the Call Stack:
void app_error_fault_handler(unsigned int id=0x00000000, unsigned int pc = 0x3ff00000, unsigned int info = 0x00000000) void app_error_handler_bare(unsigned int error_code = 0x00003401) void packet_tx_event_handler(void* p_context = 0x00000000) void RTC1_IRQHandler()
Specifically, the APP_ERROR_CHECK(err_code) line in the following code block is what causes the hardfault_interrupt to be invoked:
do { uint16_t length = (uint16_t)strlen((char *)output_data); err_code = ble_nus_data_send(&m_nus, output_data, &length, m_conn_handle); if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_RESOURCES) && (err_code != NRF_ERROR_NOT_FOUND)) { APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_RESOURCES);
Interestingly, if I comment out the APP_ERROR_CHECK(err_code) line, the crash goes away and the device works just fine on reconnection.
Here are additional information on the development environment:
- IDE: SES
- SDK: 15.2
- Mobile Device: Samsung S10+ (for Coded PHY / Long Range)
What's causing the crash? Debugging shows that the usual value of err_code is 0x00 which I think is the same as NRF_SUCCESS. So, I can't understand why commenting out APP_ERROR_CHECK() would cause this behavior on reconnection.