Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcu/nrf51: Fix low frequency clock selection #3161

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions hw/mcu/nordic/nrf51xxx/src/hal_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,28 @@ hal_debugger_connected(void)
void
hal_system_clock_start(void)
{
#if MYNEWT_VAL(XTAL_32768) || MYNEWT_VAL(XTAL_RC) || \
MYNEWT_VAL(XTAL_32768_SYNTH)
#if MYNEWT_VAL(MCU_LFCLK_SOURCE)
uint32_t regmsk;
uint32_t regval;
uint32_t clksrc;

regmsk = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Msk;
regval = CLOCK_LFCLKSTAT_STATE_Running << CLOCK_LFCLKSTAT_STATE_Pos;

#if MYNEWT_VAL(XTAL_32768)
#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFXO)
regval |= CLOCK_LFCLKSTAT_SRC_Xtal << CLOCK_LFCLKSTAT_SRC_Pos;
clksrc = CLOCK_LFCLKSRC_SRC_Xtal;
#endif

#if MYNEWT_VAL(XTAL_32768_SYNTH)
#elif MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFSYNTH)
regval |= CLOCK_LFCLKSTAT_SRC_Synth << CLOCK_LFCLKSTAT_SRC_Pos;
clksrc = CLOCK_LFCLKSRC_SRC_Synth;
#endif

#if MYNEWT_VAL(XTAL_RC)
#elif MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFRC)
regval |= CLOCK_LFCLKSTAT_SRC_RC << CLOCK_LFCLKSTAT_SRC_Pos;
clksrc = CLOCK_LFCLKSRC_SRC_RC;
#else
#error Unknown LFCLK source selected
#endif


#if MYNEWT_VAL(XTAL_32768_SYNTH)
#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFSYNTH)
/* Must turn on HFLCK for synthesized 32768 crystal */
if ((NRF_CLOCK->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) !=
(CLOCK_HFCLKSTAT_STATE_Running << CLOCK_HFCLKSTAT_STATE_Pos)) {
Expand Down
Loading