From ec15fa9e4baf3136c6aee7156d3b742f152c9095 Mon Sep 17 00:00:00 2001 From: gaoxu Date: Tue, 31 Dec 2024 11:37:20 +0800 Subject: [PATCH 1/2] fix(adc): fix adc oneshot error after continuous v5.4 closes https://github.com/espressif/esp-idf/issues/14506 --- components/esp_adc/adc_oneshot.c | 4 ++++ components/hal/adc_oneshot_hal.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index 782a1c5338..abdf36e2c8 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -238,6 +238,10 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle) bool success_free = s_adc_unit_free(handle->unit_id); ESP_RETURN_ON_FALSE(success_free, ESP_ERR_NOT_FOUND, TAG, "adc%"PRId32" isn't in use", handle->unit_id + 1); +#if ADC_LL_POWER_MANAGE_SUPPORTED + adc_ll_set_power_manage(handle->unit_id, ADC_LL_POWER_SW_OFF); +#endif + _lock_acquire(&s_ctx.mutex); s_ctx.units[handle->unit_id] = NULL; _lock_release(&s_ctx.mutex); diff --git a/components/hal/adc_oneshot_hal.c b/components/hal/adc_oneshot_hal.c index 00e9be9de3..096fbcfb89 100644 --- a/components/hal/adc_oneshot_hal.c +++ b/components/hal/adc_oneshot_hal.c @@ -58,6 +58,10 @@ void adc_oneshot_hal_setup(adc_oneshot_hal_ctx_t *hal, adc_channel_t chan) s_disable_dac(hal, chan); #endif +#if ADC_LL_POWER_MANAGE_SUPPORTED + adc_ll_set_power_manage(unit, ADC_LL_POWER_SW_ON); +#endif + #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED adc_ll_digi_clk_sel(hal->clk_src); adc_ll_digi_controller_clk_div(ADC_LL_CLKM_DIV_NUM_DEFAULT, ADC_LL_CLKM_DIV_A_DEFAULT, ADC_LL_CLKM_DIV_B_DEFAULT); From 6771e388f4ed062121cf129a7f09ccf18779e198 Mon Sep 17 00:00:00 2001 From: gaoxu Date: Tue, 31 Dec 2024 11:39:32 +0800 Subject: [PATCH 2/2] fix(adc): fix adc oneshot apb cnts incosistency v5.4 closes https://github.com/espressif/esp-idf/issues/14502 --- components/esp_adc/adc_oneshot.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index abdf36e2c8..440940674e 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -125,6 +125,7 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a }; adc_oneshot_hal_init(&(unit->hal), &config); +#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED //To enable the APB_SARADC periph if needed _lock_acquire(&s_ctx.mutex); s_ctx.apb_periph_ref_cnts++; @@ -132,6 +133,7 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a adc_apb_periph_claim(); } _lock_release(&s_ctx.mutex); +#endif if (init_config->ulp_mode == ADC_ULP_MODE_DISABLE) { sar_periph_ctrl_adc_oneshot_power_acquire();