From a8927f5db61b5e7514362b8c5b0346d5f03ece75 Mon Sep 17 00:00:00 2001 From: EminY <57416756+emincan2000@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:08:46 +0300 Subject: [PATCH] raspberrypi: round the rp2pio clock divider up when the division is not exact The check used frequency256 % div256 instead of the remainder of the division that produced div256, so some frequencies kept the rounded down divider and ran faster than requested. --- ports/raspberrypi/common-hal/rp2pio/StateMachine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 4bc82bee6e3..0219b395aaa 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -500,7 +500,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, } uint64_t frequency256 = ((uint64_t)clock_get_hz(clk_sys)) * 256; uint64_t div256 = frequency256 / frequency; - if (frequency256 % div256 > 0) { + if (frequency256 % frequency > 0) { div256 += 1; } self->actual_frequency = frequency256 / div256; @@ -903,7 +903,7 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *sel } uint64_t frequency256 = ((uint64_t)clock_get_hz(clk_sys)) * 256; uint64_t div256 = frequency256 / frequency; - if (frequency256 % div256 > 0) { + if (frequency256 % frequency > 0) { div256 += 1; } // 0 is interpreted as 0x10000 so it's valid.