hw/mcu/nordic: Waiting for HFCLK to settle
Checking both STATE and SRC of HFCLK if refcount is 0
@@ -44,7 +44,16 @@ nrf52_clock_hfxo_request(void)
__HAL_DISABLE_INTERRUPTS(ctx);
assert(nrf52_clock_hfxo_refcnt < 0xff);
if (nrf52_clock_hfxo_refcnt == 0) {
+ /* Check the current STATE and SRC of HFCLK */
+ if ((NRF_CLOCK->HFCLKSTAT &
+ (CLOCK_HFCLKSTAT_SRC_Msk | CLOCK_HFCLKSTAT_STATE_Msk)) !=
+ (CLOCK_HFCLKSTAT_SRC_Xtal << CLOCK_HFCLKSTAT_SRC_Pos |
+ CLOCK_HFCLKSTAT_STATE_Running << CLOCK_HFCLKSTAT_STATE_Pos)) {
+ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
+ while (!NRF_CLOCK->EVENTS_HFCLKSTARTED) {
+ }
+ }
started = 1;
}
++nrf52_clock_hfxo_refcnt;
