Skip to content

Commit abbbb91

Browse files
committed
Add state machine divisor check
This causes an exception when setting a state machine too slow or too fast. Fixes #4222
1 parent 360475e commit abbbb91

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t* sel
489489
if (frequency256 % div256 > 0) {
490490
div256 += 1;
491491
}
492+
// 0 is interpreted as 0x10000 so it's valid.
493+
if (div256 / 256 > 0x10000 || frequency > clock_get_hz(clk_sys)) {
494+
mp_raise_ValueError_varg(translate("%q out of range"), MP_QSTR_frequency);
495+
}
492496
self->actual_frequency = frequency256 / div256;
493497

494498
pio_sm_set_clkdiv_int_frac(self->pio, self->state_machine, div256 / 256, div256 % 256);

0 commit comments

Comments
 (0)