From 5cab5b34aa2365a575a31ac3c5aad981108712a6 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 8 Oct 2025 19:06:46 -0700 Subject: [PATCH] Fix div/0 error after WDT in ULP (#778) Fixes #399 rtc_clk_cal can return 0 while calibration is underway. If that happens busy-wait until it returns a valid period. --- src/AudioOutputULP.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AudioOutputULP.cpp b/src/AudioOutputULP.cpp index 93b3143..0fd66e1 100644 --- a/src/AudioOutputULP.cpp +++ b/src/AudioOutputULP.cpp @@ -58,6 +58,11 @@ bool AudioOutputULP::begin() { //calculate the actual ULP clock unsigned long rtc_8md256_period = rtc_clk_cal(RTC_CAL_8MD256, 1000); + // If that failed, (return 0) then we need to wait for calibration to happen... + while (!rtc_8md256_period) { + delay(20); // Don't hog the CPU + rtc_8md256_period = rtc_clk_cal(RTC_CAL_8MD256, 1000); + } unsigned long rtc_fast_freq_hz = 1000000ULL * (1 << RTC_CLK_CAL_FRACT) * 256 / rtc_8md256_period; //initialize DACs