From c504a85ecc5cb7c6b623f0a60ad19a09a755e313 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 13 Jul 2021 18:22:02 -0400 Subject: [PATCH] Add shared bindings check for invalid frequency --- shared-bindings/pwmio/PWMOut.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index f6d8d37b41..2a1bda2d38 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -231,7 +231,11 @@ STATIC mp_obj_t pwmio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t freque "PWM frequency not writable when variable_frequency is False on " "construction.")); } - common_hal_pwmio_pwmout_set_frequency(self, mp_obj_get_int(frequency)); + mp_int_t freq = mp_obj_get_int(frequency); + if (freq == 0) { + mp_raise_ValueError(translate("Invalid PWM frequency")); + } + common_hal_pwmio_pwmout_set_frequency(self, freq); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(pwmio_pwmout_set_frequency_obj, pwmio_pwmout_obj_set_frequency);