There are a bunch of questions (1, 2, 3) about handling the NRF_ERROR_INVALID_STATE
code returned by the soft-device. This code is returned when the stack is in an "Invalid state to perform operation", e.g. start-scan while scanning, disconnect while disconnected, etc.
Most answers recommend to rely on SD events to keep track of its state, and only call methods proper for the given stack state. However, in some cases, race conditions are inevitable. For example, a master calls sd_ble_gap_disconnect()
from the main tread, while at the same time its peer disconnected.
Sample code examples will call APP_ERROR_CHECK()
on the faulty return code, which will ultimately call the weak app_error_fault_handler()
and soft-reset the device, aborting the application.
I don't think aborting the application in those cases is a reasonable action.
Some questions:
- Am I correct in stating that some race conditions, related to the soft-device are inevitable (though may be unlikely)?
- If so, can I program fine-grained exception rules for
APP_ERROR_CHECK()
, e.g. by overridingapp_error_fault_handler()
? - Is there sample code for achieving this?