diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 49062d3811..d52010453f 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -456,7 +456,10 @@ void ztimer_sleep(ztimer_clock_t *clock, uint32_t duration); */ static inline void ztimer_spin(ztimer_clock_t *clock, uint32_t duration) { uint32_t end = ztimer_now(clock) + duration; - while ((end - ztimer_now(clock)) < duration) {} + + /* Rely on integer overflow. `end - now` will be smaller than `duration`, + * counting down, until it underflows to UINT32_MAX. Loop ends then. */ + while ((end - ztimer_now(clock)) <= duration) {} } /**