Skip to content

Commit

Permalink
Merge pull request #20665 from mguetschow/nrf-softreset-clock-static
Browse files Browse the repository at this point in the history
cpu/nrf5x_common: fix ztimer issue on warm-boot
  • Loading branch information
benpicco authored May 13, 2024
2 parents 1f5e2c7 + 350399d commit bea466f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cpu/nrf5x_common/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ void clock_hfxo_release(void)
irq_restore(state);
}

/**
* True if the low frequency clock (LFCLK) has been started by RIOT.
* We don't rely on NRF_CLOCK->LFCLKSTAT since that register appears to be latched
* for a short amount of time after a soft reset on at least nRF52832 and nRF52840.
* @see https://devzone.nordicsemi.com/f/nordic-q-a/35792/nrf_clock--lfclkstat-register-contents-are-not-properly-evaluated-after-a-system-reset-if-rtc-compare-event-1-or-2-are-used/138995

Check warning on line 85 in cpu/nrf5x_common/clock.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*/
static bool clock_lf_running = false;

void clock_start_lf(void)
{
/* abort if LF clock is already running */
if (NRF_CLOCK->LFCLKSTAT & CLOCK_LFCLKSTAT_STATE_Msk) {
if (clock_lf_running) {
return;
}

Expand All @@ -92,6 +100,7 @@ void clock_start_lf(void)
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}
clock_lf_running = true;

/* calibrate the RC LF clock if applicable */
#if (CLOCK_HFCLK && (CLOCK_LFCLK == 0))
Expand All @@ -105,4 +114,5 @@ void clock_stop_lf(void)
{
NRF_CLOCK->TASKS_LFCLKSTOP = 1;
while (NRF_CLOCK->LFCLKSTAT & CLOCK_LFCLKSTAT_STATE_Msk) {}
clock_lf_running = false;
}

0 comments on commit bea466f

Please sign in to comment.