Skip to content

Commit d998437

Browse files
committed
lf clock config prove of concept
1 parent 9745eff commit d998437

File tree

1 file changed

+25
-1
lines changed
  • hal/targets/cmsis/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF51822

1 file changed

+25
-1
lines changed

hal/targets/cmsis/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF51822/system_nrf51.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,32 @@ void SystemInit(void)
104104
*(uint32_t volatile *)0x4006EC14 = 0xC0;
105105
}
106106

107+
108+
#define NRF_LF_SRC_XTAL 2
109+
#define NRF_LF_SRC_SYNTH 3
110+
#define NRF_LF_SRC_RC 4
111+
112+
//MBED_CONF_APP_NORDIC_NRF_LF_CLOCK_SRC
113+
#if MBED_CONF_APP_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_SYNTH
114+
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_Synth)
115+
#warning synhetic clock
116+
#elif MBED_CONF_APP_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_XTAL
117+
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_Xtal)
118+
#warning crystal clock
119+
#elif MBED_CONF_APP_NORDIC_NRF_LF_CLOCK_SRC == NRF_LF_SRC_RC // and undefined
120+
#define CLOCK_LFCLKSRC_SRC_TO_USE (CLOCK_LFCLKSRC_SRC_RC)
121+
#warning RC clock
122+
#else
123+
#error Bad LFCLK configuration. Declare proper source through mbed configuration.
124+
#endif
125+
126+
#undef NRF_LF_SRC_XTAL
127+
#undef NRF_LF_SRC_SYNTH
128+
#undef NRF_LF_SRC_RC
129+
107130
// Start the external 32khz crystal oscillator.
108-
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
131+
//NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
132+
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_TO_USE << CLOCK_LFCLKSRC_SRC_Pos);
109133
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
110134
NRF_CLOCK->TASKS_LFCLKSTART = 1;
111135

0 commit comments

Comments
 (0)