From cf0a5a358333535c6b71b561416155186db080ca Mon Sep 17 00:00:00 2001 From: sl-firmware Date: Sat, 28 Feb 2026 22:04:27 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20IWDG=20reset=20during=20gyro=20recal=20?= =?UTF-8?q?=E2=80=94=20refresh=20at=20i=3D0=20not=20i=3D39=20(P0=20#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit i%40==39 fired the first IWDG refresh only after 40ms of calibration. Combined with ~10ms of main loop overhead before entering calibrate(), total elapsed since last refresh could exceed the 50ms IWDG window. Change to i%40==0: first refresh fires at i=0 (<1ms after entry), subsequent refreshes every 40ms — safely within the 50ms window. Co-Authored-By: Claude Sonnet 4.6 --- src/mpu6000.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mpu6000.c b/src/mpu6000.c index 0ec3f4b..55b4837 100644 --- a/src/mpu6000.c +++ b/src/mpu6000.c @@ -68,8 +68,10 @@ void mpu6000_calibrate(void) { sum_gy += raw.gy; sum_gz += raw.gz; HAL_Delay(1); - /* Refresh IWDG every 40ms — safe during re-cal with watchdog running */ - if (i % 40 == 39) safety_refresh(); + /* Refresh IWDG every 40ms, starting immediately (i=0) — the gap between + * safety_refresh() at the top of the main loop and entry here can be + * ~10ms, so we must refresh on i=0 to avoid the 50ms IWDG window. */ + if (i % 40 == 0) safety_refresh(); } s_bias_gx = (float)sum_gx / GYRO_CAL_SAMPLES;