From cf5912412d8ada86c55080e066747eebb08c3664 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Tue, 21 Apr 2026 12:55:57 -0500 Subject: [PATCH] runtime/esp32s3: wait for TIMG0 update register to clear before reading timer registers --- src/runtime/runtime_esp32sx.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/runtime_esp32sx.go b/src/runtime/runtime_esp32sx.go index 4f8c75dcc..28c46eee7 100644 --- a/src/runtime/runtime_esp32sx.go +++ b/src/runtime/runtime_esp32sx.go @@ -58,7 +58,10 @@ func initTimer() { func ticks() timeUnit { // First, update the LO and HI register pair by writing any value to the // register. This allows reading the pair atomically. - esp.TIMG0.T0UPDATE.Set(0) + esp.TIMG0.T0UPDATE.Set(1) + for esp.TIMG0.T0UPDATE.Get() != 0 { + // Register is cleared when the update is complete. + } // Then read the two 32-bit parts of the timer. return timeUnit(uint64(esp.TIMG0.T0LO.Get()) | uint64(esp.TIMG0.T0HI.Get())<<32) }