Skip to content

Commit 0c95b8c

Browse files
committed
fix(mcpwm): fix division by zero error in prescale
Closes #17665
1 parent 5086184 commit 0c95b8c

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
@@ -248,12 +248,12 @@ esp_err_t mcpwm_set_prescale(mcpwm_group_t *group, uint32_t expect_module_resolu
248248
}
249249
module_prescale = fit_module_prescale;
250250
group_prescale = fit_group_prescale;
251+
ESP_RETURN_ON_FALSE(group_prescale > 0 && group_prescale <= MCPWM_LL_MAX_GROUP_PRESCALE, ESP_ERR_INVALID_STATE, TAG,
252+
"set group prescale failed, group clock cannot match the resolution");
251253
group_resolution_hz = periph_src_clk_hz / group_prescale;
252254
}
253255

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

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

0 commit comments

Comments
 (0)