From 5f2fde996b00a379a13b8839036fb4ac9220d1d7 Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Tue, 30 Sep 2025 12:21:26 +0800 Subject: [PATCH] fix(mcpwm): fix division by zero error in prescale Closes https://github.com/espressif/esp-idf/issues/17665 --- components/driver/mcpwm/mcpwm_com.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/driver/mcpwm/mcpwm_com.c b/components/driver/mcpwm/mcpwm_com.c index 3f8d92949c..9be40d8c3b 100644 --- a/components/driver/mcpwm/mcpwm_com.c +++ b/components/driver/mcpwm/mcpwm_com.c @@ -202,12 +202,12 @@ esp_err_t mcpwm_set_prescale(mcpwm_group_t *group, uint32_t expect_module_resolu } module_prescale = fit_module_prescale; group_prescale = fit_group_prescale; + ESP_RETURN_ON_FALSE(group_prescale > 0 && group_prescale <= MCPWM_LL_MAX_GROUP_PRESCALE, ESP_ERR_INVALID_STATE, TAG, + "set group prescale failed, group clock cannot match the resolution"); group_resolution_hz = periph_src_clk_hz / group_prescale; } ESP_LOGD(TAG, "group (%d) calc prescale:%"PRIu32", module calc prescale:%"PRIu32"", group_id, group_prescale, module_prescale); - ESP_RETURN_ON_FALSE(group_prescale > 0 && group_prescale <= MCPWM_LL_MAX_GROUP_PRESCALE, ESP_ERR_INVALID_STATE, TAG, - "set group prescale failed, group clock cannot match the resolution"); // check if we need to update the group prescale, group prescale is shared by all mcpwm modules bool prescale_conflict = false;