Skip to content

Commit 2db113f

Browse files
authored
esp32-s2: Don't set PWMOut frequency to 0
FeatherS2 crashes if you set the PWMOut frequency to 0. This change will raise `ValueError: Invalid PWM frequency` if the requested frequency is 0. (Lifted from the atmel-samd port)
1 parent e6dc3e4 commit 2db113f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ports/esp32s2/common-hal/pwmio/PWMOut.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
128128
if (ledc_channel_config(&(self->chan_handle))) {
129129
return PWMOUT_INITIALIZATION_ERROR;
130130
}
131-
131+
132+
// check the frequency -- 0 is not valid
133+
// maybe also want to reject frequency > system_clock / 2 ??
134+
if (frequency == 0) {
135+
return PWMOUT_INVALID_FREQUENCY;
136+
}
137+
132138
// Make reservations
133139
reserved_timer_freq[timer_index] = frequency;
134140
reserved_channels[channel_index] = timer_index;

0 commit comments

Comments
 (0)