espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.38k stars 7.22k forks source link

ULP ADC reading not working after deep sleep + esp_wifi_stop() (IDFGH-9068) #10471

Open NikLeberg opened 1 year ago

NikLeberg commented 1 year ago

Answers checklist.

IDF version.

v5.1-dev-2658-g0025915dc4

Operating System used.

Linux

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32-WROOM-32

Power Supply used.

USB

What is the expected behavior?

The ULP is configured to put ADC measurement into shared global variable. I'd expect that after correct configuration the ULP will continue to put ADC data into variable. This should also work after deep sleep and wifi start/stop.

What is the actual behavior?

The ULP outputs the ADC values happily before the wifi stack is stopped. But after a deep sleep and a wifi stop the values are frozen in time and won't update anymore. It does not happen if there is no deep sleep in-between.

Steps to reproduce.

  1. Build & flash attached minimal example project: ulp-wifi-stop-ex.zip
  2. Attach some analog circuitry (like a LDR) to the ADC1 channel 6 pad (GPIO34 on ESP32) or leave it floating so that the ADC reads some random values.
  3. Observe output (see below)
  4. It will:
    • setup ULP & ADC,
    • enter deep sleep,
    • be woken up by ULP,
    • set up WLAN,
    • stop WLAN

At every step ADC values are written to output. After call to esp_wifi_stop() and before second call to ulp_adc_init() the ADC value is frozen and will not update.

Debug Logs.

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6972
ho 0 tail 12 room 4
load:0x40078000,len:15492
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (29) boot: ESP-IDF v5.1-dev-2658-g0025915dc4 2nd stage bootloader
I (29) boot: compile time Jan  1 2023 23:04:29
I (31) boot: chip revision: v0.0
I (35) boot.esp32: SPI Speed      : 40MHz
I (39) boot.esp32: SPI Mode       : DIO
I (44) boot.esp32: SPI Flash Size : 2MB
I (48) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (79) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot: End of partition table
I (91) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=20ac8h (133832) map
I (148) esp_image: segment 1: paddr=00030af0 vaddr=3ff80063 size=00008h (     8) load
I (148) esp_image: segment 2: paddr=00030b00 vaddr=3ffb0000 size=03438h ( 13368) load
I (159) esp_image: segment 3: paddr=00033f40 vaddr=40080000 size=0c0d8h ( 49368) load
I (183) esp_image: segment 4: paddr=00040020 vaddr=400d0020 size=7c010h (507920) map
I (366) esp_image: segment 5: paddr=000bc038 vaddr=4008c0d8 size=099a8h ( 39336) load
I (383) esp_image: segment 6: paddr=000c59e8 vaddr=400c0000 size=00064h (   100) load
I (383) esp_image: segment 7: paddr=000c5a54 vaddr=50000200 size=00004h (     4) load
I (399) boot: Loaded app from partition at offset 0x10000
I (399) boot: Disabling RNG early entropy source...
I (411) cpu_start: Pro cpu up.
I (411) cpu_start: Starting app cpu, entry point is 0x40081400
0x40081400: call_start_cpu1 at /home/niklaus/esp/esp-idf/components/esp_system/port/cpu_start.c:149

I (0) cpu_start: App cpu up.
I (428) cpu_start: Pro cpu start user code
I (428) cpu_start: cpu freq: 160000000 Hz
I (428) cpu_start: Application information:
I (433) cpu_start: Project name:     ulp-wifi-stop-ex
I (438) cpu_start: App version:      1
I (443) cpu_start: Compile time:     Jan  1 2023 23:04:10
I (449) cpu_start: ELF file SHA256:  39db82a3e2ba7f1f...
I (455) cpu_start: ESP-IDF:          v5.1-dev-2658-g0025915dc4
I (461) cpu_start: Min chip rev:     v0.0
I (466) cpu_start: Max chip rev:     v3.99 
I (471) cpu_start: Chip rev:         v0.0
I (476) heap_init: Initializing. RAM available for dynamic allocation:
I (483) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (489) heap_init: At 3FFB7048 len 00028FB8 (163 KiB): DRAM
I (495) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (501) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (508) heap_init: At 40095A80 len 0000A580 (41 KiB): IRAM
I (516) spi_flash: detected chip: gd
I (518) spi_flash: flash io: dio
W (522) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (537) app_start: Starting scheduler on CPU0
I (540) app_start: Starting scheduler on CPU1
I (540) main_task: Started on CPU0
I (550) main_task: Calling app_main()
I (550) example: ADC values before deepsleep
I (750) example: Value: 2046
I (950) example: Value: 2045
I (1150) example: Value: 2055
I (1350) example: Value: 2054
I (1550) example: Value: 2099
I (1750) example: Value: 2047
I (1950) example: Value: 2044
I (2150) example: Value: 2058
I (2350) example: Value: 2064
I (2550) example: Value: 2064
I (2750) example: Value: 2064
I (2950) example: Value: 2064
I (3150) example: Value: 2062
I (3350) example: Value: 2064
I (3550) example: Value: 2062
I (3750) example: Value: 2075
I (3950) example: Value: 2062
I (4150) example: Value: 2064
I (4350) example: Value: 2064
I (4550) example: Value: 2064
I (4750) example: Value: 2067
I (4950) example: Value: 2064
I (5150) example: Value: 2064
I (5350) example: Value: 2059
I (5550) example: Value: 2064
I (5750) example: Value: 2064
I (5950) example: Value: 2064
I (6150) example: Value: 2064
I (6350) example: Value: 2063
I (6550) example: Value: 2067
I (6750) example: Value: 2066
I (6950) example: Value: 2071
I (7150) example: Value: 2071
I (7350) example: Value: 2070
I (7550) example: Value: 2069
I (7750) example: Value: 2066
I (7950) example: Value: 2069
I (8150) example: Value: 2064
I (8350) example: Value: 2068
I (8550) example: Value: 2069
I (8750) example: Value: 2081
I (8950) example: Value: 2069
I (9150) example: Value: 2073
I (9350) example: Value: 2071
I (9550) example: Value: 2069
I (9750) example: Value: 2074
I (9950) example: Value: 2076
I (10150) example: Value: 2082
I (10350) example: Value: 2080
I (10550) example: Value: 2080
I (10550) example: Entering deep sleep.
ets Jun  8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6972
ho 0 tail 12 room 4
load:0x40078000,len:15492
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (29) boot: ESP-IDF v5.1-dev-2658-g0025915dc4 2nd stage bootloader
I (29) boot: compile time Jan  1 2023 23:04:29
I (31) boot: chip revision: v0.0
I (35) boot.esp32: SPI Speed      : 40MHz
I (40) boot.esp32: SPI Mode       : DIO
I (44) boot.esp32: SPI Flash Size : 2MB
I (49) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (58) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (80) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot: End of partition table
I (92) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=20ac8h (133832) map
I (148) esp_image: segment 1: paddr=00030af0 vaddr=3ff80063 size=00008h (     8) 
I (149) esp_image: segment 2: paddr=00030b00 vaddr=3ffb0000 size=03438h ( 13368) load
I (159) esp_image: segment 3: paddr=00033f40 vaddr=40080000 size=0c0d8h ( 49368) load
I (183) esp_image: segment 4: paddr=00040020 vaddr=400d0020 size=7c010h (507920) map
I (366) esp_image: segment 5: paddr=000bc038 vaddr=4008c0d8 size=099a8h ( 39336) load
I (383) esp_image: segment 6: paddr=000c59e8 vaddr=400c0000 size=00064h (   100) 
I (383) esp_image: segment 7: paddr=000c5a54 vaddr=50000200 size=00004h (     4) 
I (399) boot: Loaded app from partition at offset 0x10000
I (399) boot: Disabling RNG early entropy source...
I (411) cpu_start: Pro cpu up.
I (411) cpu_start: Starting app cpu, entry point is 0x40081400
0x40081400: call_start_cpu1 at /home/niklaus/esp/esp-idf/components/esp_system/port/cpu_start.c:149

I (0) cpu_start: App cpu up.
I (427) cpu_start: Pro cpu start user code
I (427) cpu_start: cpu freq: 160000000 Hz
I (427) cpu_start: Application information:
I (432) cpu_start: Project name:     ulp-wifi-stop-ex
I (438) cpu_start: App version:      1
I (442) cpu_start: Compile time:     Jan  1 2023 23:04:10
I (448) cpu_start: ELF file SHA256:  39db82a3e2ba7f1f...
I (454) cpu_start: ESP-IDF:          v5.1-dev-2658-g0025915dc4
I (461) cpu_start: Min chip rev:     v0.0
I (465) cpu_start: Max chip rev:     v3.99 
I (470) cpu_start: Chip rev:         v0.0
I (475) heap_init: Initializing. RAM available for dynamic allocation:
I (482) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (488) heap_init: At 3FFB7048 len 00028FB8 (163 KiB): DRAM
I (494) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (501) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (507) heap_init: At 40095A80 len 0000A580 (41 KiB): IRAM
I (515) spi_flash: detected chip: gd
I (518) spi_flash: flash io: dio
W (522) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (536) app_start: Starting scheduler on CPU0
I (540) app_start: Starting scheduler on CPU1
I (540) main_task: Started on CPU0
I (550) main_task: Calling app_main()
I (550) example: Coming from deep sleep.
I (550) example: ADC values after deepsleep
I (760) example: Value: 2058
I (960) example: Value: 2064
I (1160) example: Value: 2064
I (1360) example: Value: 2068
I (1560) example: Value: 2096
I (1760) example: Value: 2097
I (1960) example: Value: 2097
I (2160) example: Value: 2096
I (2360) example: Value: 2096
I (2560) example: Value: 2096
I (2760) example: Value: 2100
I (2960) example: Value: 2096
I (3160) example: Value: 2097
I (3360) example: Value: 2096
I (3560) example: Value: 2097
I (3760) example: Value: 2097
I (3960) example: Value: 2099
I (4160) example: Value: 2098
I (4360) example: Value: 2101
I (4560) example: Value: 2102
I (4760) example: Value: 2097
I (4960) example: Value: 2101
I (5160) example: Value: 2102
I (5360) example: Value: 2099
I (5560) example: Value: 2101
I (5760) example: Value: 2101
I (5960) example: Value: 2103
I (6160) example: Value: 2106
I (6360) example: Value: 2064
I (6560) example: Value: 2106
I (6760) example: Value: 2107
I (6960) example: Value: 2108
I (7160) example: Value: 2109
I (7360) example: Value: 2112
I (7560) example: Value: 2111
I (7760) example: Value: 2105
I (7960) example: Value: 2105
I (8160) example: Value: 2101
I (8360) example: Value: 2103
I (8560) example: Value: 2107
I (8760) example: Value: 2096
I (8960) example: Value: 2096
I (9160) example: Value: 2096
I (9360) example: Value: 2096
I (9560) example: Value: 2096
I (9760) example: Value: 2093
I (9960) example: Value: 2096
I (10160) example: Value: 2090
I (10360) example: Value: 2098
I (10560) example: Value: 2086
W (10600) wifi: [pp.c,3473] wifi driver task: 3ffbef30, prio:23, stack:6656, core=0
W (10620) wifi: [ieee80211_ioctl.c,2088] wifi firmware version: 34dba92
W (10620) wifi: [ieee80211_ioctl.c,2089] wifi certification version: v7.0
W (10620) wifi: [ieee80211_ioctl.c,2090] config NVS flash: enabled
W (10630) wifi: [ieee80211_ioctl.c,2091] config nano formating: disabled
W (10630) wifi: [esf_buf.c,423] Init data frame dynamic rx buffer num: 32
W (10640) wifi: [esf_buf.c,430] Init management frame dynamic rx buffer num: 32
W (10650) wifi: [esf_buf.c,437] Init management short buffer num: 32
W (10650) wifi: [esf_buf.c,455] Init dynamic tx buffer num: 32
W (10660) wifi: [wdev.c,2332] Init static rx buffer size: 1600
W (10660) wifi: [wdev.c,2339] Init static rx buffer num: 10
W (10670) wifi: [wdev.c,2340] Init dynamic rx buffer num: 32
I (10670) wifi_init: rx ba win: 6
I (10680) wifi_init: tcpip mbox: 32
I (10680) wifi_init: udp mbox: 6
I (10690) wifi_init: tcp mbox: 6
I (10690) wifi_init: tcp tx win: 5744
I (10690) wifi_init: tcp rx win: 5744
I (10700) wifi_init: tcp mss: 1440
I (10700) wifi_init: WiFi IRAM OP enabled
I (10710) wifi_init: WiFi RX IRAM OP enabled
I (10710) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
W (10730) wifi: [hal_mac.c,606] WDEVBBRXHUNG:0xc00000f0, en:1, timer:240(3840 us)
W (10730) wifi: [hal_mac.c,608] WDEVBBTXHUNG:0x800000f0, en:1, timer:240(3840 us)
W (10740) wifi: [hal_mac.c,610] WDEVBBCCAHUNG:0x800000f0, en:1, timer:240(3840 us)
W (10750) wifi: [hal_mac.c,615] WDEVHUNGRECOVER:0xffff0fff, rxHungRecover[en:1, timer:32767 cycles(409 us)], txHungRecover[en:0, timer:4095 cycles(51 us)]
W (10760) wifi: [ieee80211.c,471] mode : sta (24:0a:c4:06:e7:bc)
W (10760) wifi: [ieee80211_sta.c,3030] enable tsf
I (10770) example: ADC values after esp_wifi_start()
W (10780) wifi: [ieee80211_ht.c,2089] new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (12230) example: Value: 2064
W (12240) wifi: [ieee80211_sta.c,205] state: init -> auth (b0)
W (12250) wifi: [ieee80211_sta.c,205] state: auth -> assoc (0)
W (12250) wifi: [ieee80211_sta.c,205] state: assoc -> run (10)
W (12260) wifi: [hal_ampdu.c,45] <ba-add>idx:0 (ifx:0, ec:6c:9a:1a:cc:ba), tid:5, ssn:0, winSize:64
W (12260) wifi: [hal_ampdu.c,45] <ba-add>idx:1 (ifx:0, ec:6c:9a:1a:cc:ba), tid:0, ssn:0, winSize:64
W (12270) wifi: [wl_cnx.c,3118] connected with Some_SSID, aid = 1, channel 1, BW20, bssid = ec:ff:ff:ff:ff:ff
W (12280) wifi: [wl_cnx.c,3128] security: WPA2-PSK, phy: bgn, rssi: -58
W (12290) wifi: [pm.c,3240] pm start, type: 1

W (12360) wifi: [pm.c,479] AP's beacon interval = 102400 us, DTIM period = 3
I (12430) example: Value: 2064
I (12630) example: Value: 2064
I (12830) example: Value: 2064
I (13030) example: Value: 2039
I (13230) example: Value: 2043
I (13430) example: Value: 2043
I (13630) example: Value: 2032
I (13830) example: Value: 2055
I (14030) example: Value: 2061
I (14230) example: Value: 2035
I (14430) example: Value: 2061
I (14630) example: Value: 2063
I (14830) example: Value: 2060
I (15030) example: Value: 2032
I (15230) example: Value: 2039
I (15430) example: Value: 2057
I (15630) example: Value: 2046
I (15790) esp_netif_handlers: sta ip: 192.168.1.6, mask: 255.255.255.0, gw: 192.168.1.1
I (15830) example: Value: 2059
I (16030) example: Value: 2035
I (16230) example: Value: 2035
I (16430) example: Value: 2034
I (16630) example: Value: 2065
I (16830) example: Value: 2060
I (17030) example: Value: 2060
I (17230) example: Value: 2063
I (17430) example: Value: 2063
I (17630) example: Value: 2079
I (17830) example: Value: 2065
I (18030) example: Value: 2065
I (18230) example: Value: 2076
I (18430) example: Value: 2096
I (18630) example: Value: 2096
I (18830) example: Value: 2079
I (19030) example: Value: 2087
I (19230) example: Value: 2087
I (19430) example: Value: 2112
I (19630) example: Value: 2112
I (19830) example: Value: 2119
I (20030) example: Value: 2102
I (20230) example: Value: 2102
I (20430) example: Value: 2114
I (20630) example: Value: 2108
I (20830) example: Value: 2108
I (21030) example: Value: 2107
I (21230) example: Value: 2111
I (21430) example: Value: 2111
I (21630) example: Value: 2128
I (21830) example: Value: 2113
I (22030) example: Value: 2113
W (22030) wifi: [ieee80211_sta.c,205] state: run -> init (0)
W (22030) wifi: [pm.c,3365] pm stop, total sleep time: 8043211 us / 9736502 us

W (22030) wifi: [hal_ampdu.c,127] <ba-del>idx:1, tid:0
W (22040) wifi: [hal_ampdu.c,127] <ba-del>idx:0, tid:5
W (22040) wifi: [ieee80211_ht.c,2089] new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
W (22050) wifi: [ieee80211_ioctl.c,1778] flush txq
W (22050) wifi: [if_hwctrl.c,731] stop sw txq
W (22060) wifi: [lmac.c,2465] lmac stop hw txq
I (22060) example: ADC values after esp_wifi_stop()
I (22270) example: Value: 2129
I (22470) example: Value: 2129
I (22670) example: Value: 2129
I (22870) example: Value: 2129
I (23070) example: Value: 2129
I (23270) example: Value: 2129
I (23470) example: Value: 2129
I (23670) example: Value: 2129
I (23870) example: Value: 2129
I (24070) example: Value: 2129
I (24270) example: Value: 2129
I (24470) example: Value: 2129
I (24670) example: Value: 2129
I (24870) example: Value: 2129
I (25070) example: Value: 2129
I (25270) example: Value: 2129
I (25470) example: Value: 2129
I (25670) example: Value: 2129
I (25870) example: Value: 2129
I (26070) example: Value: 2129
I (26270) example: Value: 2129
I (26470) example: Value: 2129
I (26670) example: Value: 2129
I (26870) example: Value: 2129
I (27070) example: Value: 2129
I (27270) example: Value: 2129
I (27470) example: Value: 2129
I (27670) example: Value: 2129
I (27870) example: Value: 2129
I (28070) example: Value: 2129
I (28270) example: Value: 2129
I (28470) example: Value: 2129
I (28670) example: Value: 2129
I (28870) example: Value: 2129
I (29070) example: Value: 2129
I (29270) example: Value: 2129
I (29470) example: Value: 2129
I (29670) example: Value: 2129
I (29870) example: Value: 2129
I (30070) example: Value: 2129
I (30270) example: Value: 2129
I (30470) example: Value: 2129
I (30670) example: Value: 2129
I (30870) example: Value: 2129
I (31070) example: Value: 2129
I (31270) example: Value: 2129
I (31470) example: Value: 2129
I (31670) example: Value: 2129
I (31870) example: Value: 2129
I (32070) example: Value: 2129
I (32070) example: ADC values after fix with ulp_adc_init()
I (32270) example: Value: 2067
I (32470) example: Value: 2066
I (32670) example: Value: 2065
I (32870) example: Value: 2066
I (33070) example: Value: 2064
I (33270) example: Value: 2064
I (33470) example: Value: 2065
I (33670) example: Value: 2065
I (33870) example: Value: 2064
I (34070) example: Value: 2065
I (34270) example: Value: 2064
I (34470) example: Value: 2064
I (34670) example: Value: 2064
I (34870) example: Value: 2065
I (35070) example: Value: 2065
I (35270) example: Value: 2065
I (35470) example: Value: 2069
I (35670) example: Value: 2070
I (35870) example: Value: 2070
I (36070) example: Value: 2071
I (36270) example: Value: 2069
I (36470) example: Value: 2071
I (36670) example: Value: 2074
I (36870) example: Value: 2066
I (37070) example: Value: 2069
I (37270) example: Value: 2069
I (37470) example: Value: 2064
I (37670) example: Value: 2066
I (37870) example: Value: 2071
I (38070) example: Value: 2073
I (38270) example: Value: 2067
I (38470) example: Value: 2081
I (38670) example: Value: 2079
I (38870) example: Value: 2079
I (39070) example: Value: 2096
I (39270) example: Value: 2075
I (39470) example: Value: 2083
I (39670) example: Value: 2062
I (39870) example: Value: 2085
I (40070) example: Value: 2090
I (40270) example: Value: 2094
I (40470) example: Value: 2096
I (40670) example: Value: 2096
I (40870) example: Value: 2101
I (41070) example: Value: 2107
I (41270) example: Value: 2126
I (41470) example: Value: 2112
I (41670) example: Value: 2112
I (41870) example: Value: 2112
I (42070) example: Value: 2107
I (42070) main_task: Returned from app_main()

More Information.

As seen in the example code, if the ADC is initialized again with a call to ulp_adc_init(), then the ULP starts spitting out fresh and correct values again.

I noticed this bug after the ULP could no longer wake the SoC in one of my project. I'm assuming it got stuck on the adc instruction while reading the ADC that was miss configured (or erroneously de initialized by the wifi library?) and could never continue from that instruction.

I have read that Wifi can influence ADC operation. But that should only be the case for ADC2, or isn't it? I'm also not sure if I'm not supposed to initialize the ADC after every deep sleep anyway. So if I'm using the API wrong I'm happy to be corrected.

NikLeberg commented 1 year ago

I did some debugging and compared the HW registers before and after the call to esp_wifi_stop(). The main difference observed was, that the ADC peripheral gets powered down, i.e. in the register SENS_SAR_MEAS_WAIT2_REG the field SENS_FORCE_XPD_SAR is set to a value SENS_FORCE_XPD_SAR_PD. To operate with the ULP this needs to be set to SENS_FORCE_XPD_SAR_FSM or at least that is what ulp_adc_init() does.

Setting the register manually to SENS_FORCE_XPD_SAR_FSM solves the issue for me.

I then debugged with GDB to see what piece of code changes this register. I found the set of functions adc_power_acquire() and adc_power_release() that seem to manage the power to the ADC peripheral. They manage a reference count of the ADC usages and power it down if no code uses it any more. PD is done differently for the ESP32 than for the other ESP modules:


static void adc_power_off_internal(void)
{
#if CONFIG_IDF_TARGET_ESP32
    adc_hal_set_power_manage(ADC_POWER_SW_OFF);
#else
    adc_hal_set_power_manage(ADC_POWER_BY_FSM);
#endif
}

The ADC_POWER_BY_FSM would be equivalent to the required SENS_FORCE_XPD_SAR_FSM to solve the issue in my case.

This precompiler switch was added in commit cc6bfcd but I sadly could not find a reason for the special handling of ESP32. If I remove the ESP32 special case and always let it set ADC_POWER_BY_FSM then the ADC usage with ULP works.

I'm assuming, that initially that reference count is incremented with the use of ulp_adc_init(). But then after the deep sleep the count is obviously lost and the HAL no longer knows that the ULP is using it. As such after the last module (the wifi stack in this case) stops to use the ADC, the ADC is powered down.

Am I supposed to use the ADC API in a different way? What is the specific reason for the special handling of original ESP32 module?

Xiehanxin commented 1 year ago

hi @NikLeberg sorry for late reply, thanks for your feedback, we will take a test