Skip to content

Commit f194e0d

Browse files
committed
fix(mcpwm): fix division by zero error in prescale
Closes espressif#17665
1 parent 93603cd commit f194e0d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

components/esp_driver_mcpwm/src/mcpwm_com.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ esp_err_t mcpwm_set_prescale(mcpwm_group_t *group, uint32_t expect_module_resolu
246246
}
247247
module_prescale = fit_module_prescale;
248248
group_prescale = fit_group_prescale;
249+
ESP_RETURN_ON_FALSE(group_prescale > 0 && group_prescale <= MCPWM_LL_MAX_GROUP_PRESCALE, ESP_ERR_INVALID_STATE, TAG,
250+
"set group prescale failed, group clock cannot match the resolution");
249251
group_resolution_hz = periph_src_clk_hz / group_prescale;
250252
}
251253

252254
ESP_LOGD(TAG, "group (%d) calc prescale:%"PRIu32", module calc prescale:%"PRIu32"", group_id, group_prescale, module_prescale);
253-
ESP_RETURN_ON_FALSE(group_prescale > 0 && group_prescale <= MCPWM_LL_MAX_GROUP_PRESCALE, ESP_ERR_INVALID_STATE, TAG,
254-
"set group prescale failed, group clock cannot match the resolution");
255255

256256
// check if we need to update the group prescale, group prescale is shared by all mcpwm modules
257257
bool prescale_conflict = false;

0 commit comments

Comments
 (0)