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

cpu/nrf5x_common: fix ztimer issue on warm-boot #20665

Merged
merged 1 commit into from
May 13, 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
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 @@
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where this function would be called more than once anyway?
I think we could easily drop that check.

It's only called in rtt_init() which is run once, the call in nimble_riot.c could be guarded with a if (!IS_USED(MODULE_PERIPH_RTT))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this check to a guard in nimble_riot.c moves logic to somewhere where it doesn't belong to. And the product specification explicitly mentions that changing clock parameters while the clock is running is not allowed.

return;
}

Expand All @@ -92,6 +100,7 @@
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 @@
{
NRF_CLOCK->TASKS_LFCLKSTOP = 1;
while (NRF_CLOCK->LFCLKSTAT & CLOCK_LFCLKSTAT_STATE_Msk) {}
clock_lf_running = false;
}
Loading