Merge branch 'bugfix/channel_resolution_calculation_v5.4' into 'release/v5.4'

fix(rmt): channel resolution divider rounding issue (v5.4)

See merge request espressif/esp-idf!36032
This commit is contained in:
Jiang Jiang Jian 2025-01-09 11:38:53 +08:00
commit db6e451f14
2 changed files with 4 additions and 4 deletions

View File

@ -278,8 +278,8 @@ esp_err_t rmt_new_rx_channel(const rmt_rx_channel_config_t *config, rmt_channel_
// select the clock source // select the clock source
ESP_GOTO_ON_ERROR(rmt_select_periph_clock(&rx_channel->base, config->clk_src), err, TAG, "set group clock failed"); ESP_GOTO_ON_ERROR(rmt_select_periph_clock(&rx_channel->base, config->clk_src), err, TAG, "set group clock failed");
// set channel clock resolution // set channel clock resolution, find the divider to get the closest resolution
uint32_t real_div = group->resolution_hz / config->resolution_hz; uint32_t real_div = (group->resolution_hz + config->resolution_hz / 2) / config->resolution_hz;
rmt_ll_rx_set_channel_clock_div(hal->regs, channel_id, real_div); rmt_ll_rx_set_channel_clock_div(hal->regs, channel_id, real_div);
// resolution loss due to division, calculate the real resolution // resolution loss due to division, calculate the real resolution
rx_channel->base.resolution_hz = group->resolution_hz / real_div; rx_channel->base.resolution_hz = group->resolution_hz / real_div;

View File

@ -333,8 +333,8 @@ esp_err_t rmt_new_tx_channel(const rmt_tx_channel_config_t *config, rmt_channel_
#endif #endif
// select the clock source // select the clock source
ESP_GOTO_ON_ERROR(rmt_select_periph_clock(&tx_channel->base, config->clk_src), err, TAG, "set group clock failed"); ESP_GOTO_ON_ERROR(rmt_select_periph_clock(&tx_channel->base, config->clk_src), err, TAG, "set group clock failed");
// set channel clock resolution // set channel clock resolution, find the divider to get the closest resolution
uint32_t real_div = group->resolution_hz / config->resolution_hz; uint32_t real_div = (group->resolution_hz + config->resolution_hz / 2) / config->resolution_hz;
rmt_ll_tx_set_channel_clock_div(hal->regs, channel_id, real_div); rmt_ll_tx_set_channel_clock_div(hal->regs, channel_id, real_div);
// resolution lost due to division, calculate the real resolution // resolution lost due to division, calculate the real resolution
tx_channel->base.resolution_hz = group->resolution_hz / real_div; tx_channel->base.resolution_hz = group->resolution_hz / real_div;