Skip to content

drivers: adc: esp32: fix oneshot read hang with wi-fi power save - #117346

Open
sylvioalves wants to merge 2 commits into
zephyrproject-rtos:mainfrom
sylvioalves:bugfix/adc-esp32-analog-clock
Open

drivers: adc: esp32: fix oneshot read hang with wi-fi power save#117346
sylvioalves wants to merge 2 commits into
zephyrproject-rtos:mainfrom
sylvioalves:bugfix/adc-esp32-analog-clock

Conversation

@sylvioalves

Copy link
Copy Markdown
Contributor

When Wi-Fi power saving is enabled, adc_read() can hang forever because the ADC shares an analog clock with the Wi-Fi modem and the hal waits for the conversion result in a loop with no timeout. While the modem sleeps the conversion can never finish.

The driver now holds the analog clock while reading and the hal wait is bounded, so instead of hanging the read returns ETIMEDOUT and the application can simply retry. The timeout is configurable through ADC_ESP32_CONVERSION_TIMEOUT_US.

Fixes #117247

The oneshot read path touched the analog calibration registers
and started conversions without holding the analog i2c master
clock. On SoCs where that clock is root gated it is shared with
the Wi-Fi modem, so the first modem sleep cycle gated it and the
conversion polling never returned.

Hold the reference counted analog clock across channel setup,
calibration load and conversion, and propagate a conversion
failure as -ETIMEDOUT so callers can retry when the shared
analog hardware is temporarily powered down by modem sleep. The
completion wait bound is adjustable through the new
ADC_ESP32_CONVERSION_TIMEOUT_US option.

Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The continuous acquisition path programs the analog calibration
registers and runs the shared front-end without holding the
analog i2c master clock, the same gap the oneshot path had.
Hold the reference counted clock from controller start until
stop so the acquisition does not depend on another user keeping
that clock enabled.

Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ADC Analog-to-Digital Converter (ADC) platform: ESP32 Espressif ESP32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drivers: adc: esp32c6: ADC hangs with Wi-Fi modem power saving enabled

2 participants