Skip to content

Commit bd2505f

Browse files
committed
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>
1 parent d694ac6 commit bd2505f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

ports/nrf/drivers/bluetooth/ble_drv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ uint32_t ble_drv_stack_enable(void) {
150150
.rc_temp_ctiv = 2,
151151
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
152152
};
153+
#elif BLUETOOTH_LFCLK_SYNTH
154+
nrf_clock_lf_cfg_t clock_config = {
155+
.source = NRF_CLOCK_LF_SRC_SYNTH,
156+
.rc_ctiv = 0,
157+
.rc_temp_ctiv = 0,
158+
.accuracy = NRF_CLOCK_LF_ACCURACY_50_PPM
159+
};
153160
#else
154161
nrf_clock_lf_cfg_t clock_config = {
155162
.source = NRF_CLOCK_LF_SRC_XTAL,

ports/nrf/mphalport.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,24 @@ void mp_nrf_start_lfclk(void) {
5555
// Check if the clock was recently stopped but is still running.
5656
#if USE_WORKAROUND_FOR_ANOMALY_132
5757
bool was_running = nrf_clock_lf_is_running(NRF_CLOCK);
58-
// If so, wait for it to stop. This ensures that the delay for anomaly 132 workaround does
59-
// not land us in the middle of the forbidden interval.
58+
#endif
59+
// If so, wait for it to stop, otherwise the source cannot be changed. This also ensures
60+
// that the delay for anomaly 132 workaround does not land us in the middle of the forbidden
61+
// interval.
6062
while (nrf_clock_lf_is_running(NRF_CLOCK)) {
6163
}
64+
// Use the same LFCLK source as for bluetooth so that enabling the softdevice will not cause
65+
// an interruption.
66+
nrf_clock_lf_src_set(NRF_CLOCK,
67+
#if BLUETOOTH_LFCLK_RC
68+
NRF_CLOCK_LFCLK_RC
69+
#elif BLUETOOTH_LFCLK_SYNTH
70+
NRF_CLOCK_LFCLK_Synth
71+
#else
72+
NRF_CLOCK_LFCLK_Xtal
73+
#endif
74+
);
75+
#if USE_WORKAROUND_FOR_ANOMALY_132
6276
// If the clock just stopped, we can start it again right away as we are certainly before
6377
// the forbidden 66-138us interval. Otherwise, apply a delay of 138us to make sure we are
6478
// after the interval.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy