diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2021-02-23 16:25:02 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2021-02-23 16:30:46 -0800 |
| commit | abbbb91fa8813ac332e7a6618c45a2ebc2d82803 (patch) | |
| tree | 51f09259a78337b8223c370d9b1f25170494094e | |
| parent | 360475e26618cba98522d5dd86d0051d3a296fb3 (diff) | |
Add state machine divisor check
This causes an exception when setting a state machine too slow or
too fast.
Fixes #4222
| -rw-r--r-- | ports/raspberrypi/common-hal/rp2pio/StateMachine.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index f0ee842ef..5973f47a2 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -489,6 +489,10 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t* sel if (frequency256 % div256 > 0) { div256 += 1; } + // 0 is interpreted as 0x10000 so it's valid. + if (div256 / 256 > 0x10000 || frequency > clock_get_hz(clk_sys)) { + mp_raise_ValueError_varg(translate("%q out of range"), MP_QSTR_frequency); + } self->actual_frequency = frequency256 / div256; pio_sm_set_clkdiv_int_frac(self->pio, self->state_machine, div256 / 256, div256 % 256); |
