summaryrefslogtreecommitdiff
path: root/ports/nrf/peripherals
diff options
context:
space:
mode:
authorBenny Meisels <benny.meisels@gmail.com>2019-08-18 09:11:16 +0300
committerBenny Meisels <benny.meisels@gmail.com>2019-08-20 23:30:21 +0300
commitfe2ec6c887a5c4d8414fa19879dd5a1b083d0240 (patch)
treeeb4cf2909339d020d6a511af464cf77196779fa3 /ports/nrf/peripherals
parent3f7321af0074456f11c7614d8c29d91b787411f6 (diff)
Add support for nrf boards that don't have an external crystal
Diffstat (limited to 'ports/nrf/peripherals')
-rw-r--r--ports/nrf/peripherals/nrf/clocks.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/ports/nrf/peripherals/nrf/clocks.c b/ports/nrf/peripherals/nrf/clocks.c
index 4acb878db..de9eec6b5 100644
--- a/ports/nrf/peripherals/nrf/clocks.c
+++ b/ports/nrf/peripherals/nrf/clocks.c
@@ -26,11 +26,21 @@
*/
#include "nrfx.h"
+#include "mpconfigboard.h" // for BOARD_HAS_CRYSTAL
+
+static inline bool board_has_crystal(void) {
+#ifdef BOARD_HAS_CRYSTAL
+ return BOARD_HAS_CRYSTAL == 1;
+#else
+ return false;
+#endif
+}
void nrf_peripherals_clocks_init(void) {
- // Set low-frequency clock source to be crystal. If there's a crystalless board, this will need to be
- // generalized.
- NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
+ // Set low-frequency clock source to be either an external 32.768kHz crystal if one exists on the board
+ // or an internal 32.768 kHz RC oscillator otherwise
+ uint32_t clock_src = board_has_crystal() ? CLOCK_LFCLKSRC_SRC_Xtal : CLOCK_LFCLKSRC_SRC_RC;
+ NRF_CLOCK->LFCLKSRC = (uint32_t)((clock_src << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
// Wait for clocks to start.