以下问题在使用platformio的ARDUINO框架开发ESP32-S3时发现
在drive/ledc.c的
Code:
Select all
uint32_t ledc_get_freq(ledc_mode_t speed_mode, ledc_
timer_t timer_num)
{
LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode");
LEDC_ARG_CHECK(timer_num < LEDC_TIMER_MAX, "timer_num");
LEDC_CHECK(p_ledc_obj[speed_mode] != NULL, LEDC_NOT_INIT, ESP_ERR_INVALID_STATE);
portENTER_CRITICAL(&ledc_spinlock);
uint32_t clock_divider = 0;
uint32_t duty_resolution = 0;
ledc_clk_cfg_t clk_cfg = LEDC_USE_APB_CLK;
ledc_hal_get_clock_divider(&(p_ledc_obj[speed_mode]->ledc_hal), timer_num, &clock_divider);
ledc_hal_get_duty_resolution(&(p_ledc_obj[speed_mode]->ledc_hal), timer_num, &duty_resolution);
ledc_hal_get_clk_cfg(&(p_ledc_obj[speed_mode]->ledc_hal), timer_num, &clk_cfg);
uint32_t precision = (0x1 << duty_resolution);
uint32_t src_clk_freq = ledc_get_src_clk_freq(clk_cfg);
portEXIT_CRITICAL(&ledc_spinlock);
return ((uint64_t) src_clk_freq << 8) / precision / clock_divider;
}
函数中
利用
Code:
Select all
ledc_hal_get_clock_divider(&(p_ledc_obj[speed_mode]->ledc_hal), timer_num, &clock_divider);
获取到clock_divider的值为0
在随后的频率计算时
Code:
Select all
return ((uint64_t) src_clk_freq << 8) / precision / clock_divider;
会作为分母使用,导致系统报错 IntegerDivideByZero 后重启
望及时修复
0