I am experiencing a problem where behaviour after an sd_nvic_SystemReset() differs from behaviour after a power-on reset, and this difference causes failures in the softdevice when restarting throigh sd_nvic_SystemReset.
The device in question uses an nRF52811 with a custom boot loader, which normally simply confirms the loaded main app with an attached microprocessor and then jumps into it, without touching any hardware other than the UART and some GPIO. The main app, compiled against SDK 15.3.0, brings up the softdevice and BLE stack, with the only unusual aspect being that the LFCLK is provided as an external full-swing signal --- this requires manually getting the LFCLK started before calling nrf_sdh_enable_request().
The bootloader also supports a separate DFU mode, in which it brings up the BLE stack and allows a variety of (largely device-specific) operations to be performed through a bluetooth connection. Because the external 32kHz clock is not available yet at that point in the boot process (and to simplify things), the bootloader configures the LFCLK to be synthesised from the HFCLK:
static MBRCONST nrf_clock_lf_cfg_t clock_config = {
.source = NRF_CLOCK_LF_SRC_SYNTH,
.rc_ctiv = 0,
.rc_temp_ctiv = 0,
.accuracy = 0,
};
[...]
int res=sd_softdevice_enable(&clock_config,softdevice_assert_handler);
if (res!=NRF_SUCCESS && ERROR_REPORTING)
ELOG_NUM("sd_enable",res);
This works perfectly if run directly after power-up (i.e. if entering the DFU mode due to a button being pressed at startup time).
However, the main app can request a restart into DFU mode by (a) setting a specific flag, (b) disabling the softdevice, and (c) calling NVIC_SystemReset(). The expectation is that such a restart behaves identical to a power-up restart, with the exception of the flag having been set.
In reality, the bootloader's call to sd_softdevice_enable() hangs, which from both personal experience and research on the DevZone, suggests the LFCLK is not starting up?!?
If the main app does not shut down the softdevice before resetting (and using sd_nvic_SystemReset() to do so), sd_softdevice_enable() returns successfully, but soon afterwards, nrf_sdh_ble_enable() returns 8, "INVALID STATE".
I have tried resetting the CLOCK registers listed in 52811 erratum 36 at the start of the bootloader, but that made no difference to the behaviour.
We would like to understand why this is happening, because even in normal use, the main app may need to do a soft reset after an OTA firmware upgrade, and we need to be confident that the BLE stack will perform as expected after such a restart.