1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #20665 from mguetschow/nrf-softreset-clock-static

cpu/nrf5x_common: fix ztimer issue on warm-boot
This commit is contained in:
benpicco 2024-05-13 13:45:12 +00:00 committed by GitHub
commit bea466faf0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
*/
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;
}
@ -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))
@ -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;
}