diff --git a/ports/nrf/drivers/bluetooth/ble_drv.c b/ports/nrf/drivers/bluetooth/ble_drv.c index b1caa187d5..1c150b5d71 100644 --- a/ports/nrf/drivers/bluetooth/ble_drv.c +++ b/ports/nrf/drivers/bluetooth/ble_drv.c @@ -150,6 +150,13 @@ uint32_t ble_drv_stack_enable(void) { .rc_temp_ctiv = 2, .accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM }; + #elif BLUETOOTH_LFCLK_SYNTH + nrf_clock_lf_cfg_t clock_config = { + .source = NRF_CLOCK_LF_SRC_SYNTH, + .rc_ctiv = 0, + .rc_temp_ctiv = 0, + .accuracy = NRF_CLOCK_LF_ACCURACY_50_PPM + }; #else nrf_clock_lf_cfg_t clock_config = { .source = NRF_CLOCK_LF_SRC_XTAL, diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index 06c6ba5cc2..a8be2bd6e9 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -55,10 +55,24 @@ void mp_nrf_start_lfclk(void) { // Check if the clock was recently stopped but is still running. #if USE_WORKAROUND_FOR_ANOMALY_132 bool was_running = nrf_clock_lf_is_running(NRF_CLOCK); - // If so, wait for it to stop. This ensures that the delay for anomaly 132 workaround does - // not land us in the middle of the forbidden interval. + #endif + // If so, wait for it to stop, otherwise the source cannot be changed. This also ensures + // that the delay for anomaly 132 workaround does not land us in the middle of the forbidden + // interval. while (nrf_clock_lf_is_running(NRF_CLOCK)) { } + // Use the same LFCLK source as for bluetooth so that enabling the softdevice will not cause + // an interruption. + nrf_clock_lf_src_set(NRF_CLOCK, + #if BLUETOOTH_LFCLK_RC + NRF_CLOCK_LFCLK_RC + #elif BLUETOOTH_LFCLK_SYNTH + NRF_CLOCK_LFCLK_Synth + #else + NRF_CLOCK_LFCLK_Xtal + #endif + ); + #if USE_WORKAROUND_FOR_ANOMALY_132 // If the clock just stopped, we can start it again right away as we are certainly before // the forbidden 66-138us interval. Otherwise, apply a delay of 138us to make sure we are // after the interval.