nrf: Allow boards to choose LFCLK source.

Board definitions could already define BLUETOOTH_LFCLK_RC or not to choose
whether to use the internal RC oscillator or an external 32kHz crystal as
the source for LFCLK, but that setting was only applied when the softdevice
was enabled by ble.enable(). Apply it from the start, so that the functions
of the time module always have the specified accuracy and run without
interruption when the softdevice is enabled.

Also add an option for the third LFCLK source, synthesized from the HFCLK,
by defining BLUETOOTH_LFCLK_SYNTH.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
pull/13340/head
Christian Walther 2024-01-01 18:25:04 +01:00
rodzic 87d821ab49
commit 6fa8becff5
2 zmienionych plików z 23 dodań i 2 usunięć

Wyświetl plik

@ -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,

Wyświetl plik

@ -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.