espressif / esp-idf

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

ESP32s3 ADC continuous DMA stops being filled if esp_wifi_start() is called after adc_continuous_start() (IDFGH-11635) #12749

Open DarmorGamz opened 10 months ago

DarmorGamz commented 10 months ago

Answers checklist.

IDF version.

v5.1.1

Espressif SoC revision.

ESP32-S3 v0.1

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-S3 WROOM-1 DevKitC-1 | Custom Board

Power Supply used.

External 5V

What is the expected behavior?

WIFI should have no affect over ADC1, esp_wifi_start() and adc_continuous_start() should have no correlation.

What is the actual behavior?

If esp_wifi_start() is called after adc_continuous_start() the DMA stops being filled, and the adc peripheral thinks it's still running as expected. My application also calls esp_wifi_start() and esp_wifi_stop() frequently, requiring me to stop and start the adc each time.

Below is the Adc_Continuous example mixed with the Wifi example, changing the order of these two lines shown will reproduce the result.

if (esp_wifi_start() != ESP_OK) { ESP_LOGI("WIFI", "Wifi failed to start. "); return; }
if (adc_continuous_start(stAdcHandle) != ESP_OK) { ESP_LOGI("ADC", "Adc failed to start. "); return; }

Steps to reproduce.

#include <string.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_adc/adc_continuous.h"

#include "esp_wifi.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "nvs_flash.h"

static const char *TAG = "EXAMPLE";

wifi_config_t stWifiConfig = {
    .sta = {
        .ssid = {0},
        .password = {0},
        .channel = 0,
        .scan_method = WIFI_FAST_SCAN,
        .failure_retry_cnt = 1,
    }
};

#define NUM_CHANNELS 6
#define SAMPLES_PER_CYCLE 128
#define MAX_FREQUENCY 64

static adc_channel_t channel[NUM_CHANNELS] = { ADC_CHANNEL_0, ADC_CHANNEL_1, ADC_CHANNEL_2, ADC_CHANNEL_3, ADC_CHANNEL_4, ADC_CHANNEL_5};

static uint16_t au16ChannelCount[NUM_CHANNELS] = { 0 };
static adc_continuous_handle_t stAdcHandle = NULL;
static esp_netif_t *p_stWifiSta_Netif;

static esp_err_t Wifi_Init(esp_netif_t** stNetif_WifiSTA) {
    // Initialize TCP/IP network interface (should be called only once in application)
    if (esp_netif_init() != ESP_OK) { ESP_LOGI("WIFI", "NETIF already initalized."); return !ESP_OK; }

    // Create default event loop needed by all interfaces.
    if (esp_event_loop_create_default() != ESP_OK) { ESP_LOGI("WIFI", "NETIF already initalized."); return !ESP_OK; }

    // Initialize Flash.
    if (nvs_flash_init() == (ESP_ERR_NVS_NO_FREE_PAGES - ESP_ERR_NVS_BASE)) {
        if (nvs_flash_erase()!= ESP_OK) { ESP_LOGI("WIFI", "NVS flash failed to erase. "); return !ESP_OK; }
        if (nvs_flash_init()!= ESP_OK) { ESP_LOGI("WIFI", "NVS flash failed to init. "); return !ESP_OK; }
    }

    // Initalize Wifi.
    esp_err_t ret;
    wifi_init_config_t stWifiInitConfig = WIFI_INIT_CONFIG_DEFAULT();
    if ((ret = esp_wifi_init(&stWifiInitConfig)) != ESP_OK) { ESP_LOGI("WIFI", "Wifi failed to initalize: %x ", ret); return !ESP_OK; }

    // Create Interface.
    esp_netif_config_t stNetifConfig_WifiSTA = ESP_NETIF_DEFAULT_WIFI_STA();
    if ((*stNetif_WifiSTA = esp_netif_new(&stNetifConfig_WifiSTA)) == NULL) { ESP_LOGI("WIFI", "Wifi Sta failed to Initalized."); return !ESP_OK; }

    // Default handlers.
    if (esp_wifi_set_default_wifi_sta_handlers() != ESP_OK) { ESP_LOGI("WIFI", "Failed to set default STA handlers. "); return !ESP_OK; } // Need this for DCHP to start automatically.

    // Station mode.
    esp_wifi_set_mode(WIFI_MODE_STA);

    // Set Response.
    return ESP_OK;
}

static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t stAdcHandle, const adc_continuous_evt_data_t *edata, void *user_data) {
    for (uint32_t k = 0; k < edata->size; k += SOC_ADC_DIGI_RESULT_BYTES) {
        adc_digi_output_data_t *p = (void*)&edata->conv_frame_buffer[k];
        au16ChannelCount[p->type2.channel]++;
    }

    return true;
}

static esp_err_t ADC_Init(adc_channel_t *channel, uint8_t channel_num, adc_continuous_handle_t *out_handle) {
    adc_continuous_handle_cfg_t stAdcHandleConfig = {
        .max_store_buf_size = 8192,
        .conv_frame_size = SOC_ADC_DIGI_RESULT_BYTES,
    };
    if (adc_continuous_new_handle(&stAdcHandleConfig, &stAdcHandle) != ESP_OK) { ESP_LOGI("ADC_INIT", "Failed to create ADC Handle. "); return !ESP_OK; }

    adc_continuous_config_t stAdcConfig = {
        .sample_freq_hz = (SAMPLES_PER_CYCLE*MAX_FREQUENCY) * NUM_CHANNELS,
        .conv_mode = ADC_CONV_SINGLE_UNIT_1,
        .format = ADC_DIGI_OUTPUT_FORMAT_TYPE2,
    };

    adc_digi_pattern_config_t astAdcPattern[NUM_CHANNELS] = { 0 };
    stAdcConfig.pattern_num = channel_num;
    for (uint8_t i = 0; i < channel_num; i++) {
        astAdcPattern[i].atten = ADC_ATTEN_DB_11;
        astAdcPattern[i].channel = channel[i] & 0x7;
        astAdcPattern[i].unit = ADC_UNIT_1;
        astAdcPattern[i].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
    }

    stAdcConfig.adc_pattern = astAdcPattern;
    if (adc_continuous_config(stAdcHandle, &stAdcConfig) != ESP_OK) { ESP_LOGI("ADC_INIT", "Failed to set ADC Config. "); return !ESP_OK; }

    adc_continuous_evt_cbs_t stAdcCn = {
        .on_conv_done = s_conv_done_cb,
    };
    if (adc_continuous_register_event_callbacks(stAdcHandle, &stAdcCn, NULL) != ESP_OK) { ESP_LOGI("ADC_INIT", "Failed to set ADC Cb functions. "); return !ESP_OK; }

    *out_handle = stAdcHandle;

    // Set Response.
    return ESP_OK;
}

void app_main(void) {
    // Initalize Wifi
    if (Wifi_Init(&p_stWifiSta_Netif) != ESP_OK) { ESP_LOGI("Main", "Failed to init Wifi. "); return; }

    // Initalize ADC
    if (ADC_Init(channel, NUM_CHANNELS, &stAdcHandle) != ESP_OK) { ESP_LOGI("Main", "Failed to init ADC. "); return; }

    // Problem area, switching these two functions replicate the issue.
    if (adc_continuous_start(stAdcHandle) != ESP_OK) { ESP_LOGI("ADC", "Adc failed to start. "); return; }
    if (esp_wifi_start() != ESP_OK) { ESP_LOGI("WIFI", "Wifi failed to start. "); return; }

    while(1) {
        // 1 sec measurements, 64Hz max.
        vTaskDelay(pdMS_TO_TICKS(1000));
        uint32_t u32Total = 0;
        for (uint8_t i = 0; i < NUM_CHANNELS; i++) {
            ESP_LOGI(TAG, "Sensor: %d, Count: %d", i, au16ChannelCount[i]);
            u32Total += au16ChannelCount[i];
            au16ChannelCount[i] = 0;
        }
        ESP_LOGI(TAG, "TotalCount: %lu", u32Total);
    }

    ESP_ERROR_CHECK(adc_continuous_stop(stAdcHandle));
    ESP_ERROR_CHECK(adc_continuous_deinit(stAdcHandle));
}

Debug Logs.

esp_wifi_start() called before adc_continuous_start()

I (0) cpu_start: App cpu up.
I (272) cpu_start: Pro cpu start user code
I (272) cpu_start: cpu freq: 160000000 Hz
I (272) cpu_start: Application information:
I (275) cpu_start: Project name:     continuous_read
I (280) cpu_start: App version:      1
I (285) cpu_start: Compile time:     Dec  6 2023 12:48:40
I (291) cpu_start: ELF file SHA256:  dbea723e40b981dd...
I (297) cpu_start: ESP-IDF:          v5.1.1-dirty
I (302) cpu_start: Min chip rev:     v0.0
I (307) cpu_start: Max chip rev:     v0.99 
I (312) cpu_start: Chip rev:         v0.1
I (316) heap_init: Initializing. RAM available for dynamic allocation:
I (324) heap_init: At 3FC9FA98 len 00049C78 (295 KiB): DRAM
I (330) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (337) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (343) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
I (350) spi_flash: detected chip: generic
I (354) spi_flash: flash io: dio
W (358) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (371) sleep: Configure to isolate all GPIO pins in sleep state
I (378) sleep: Enable automatic switching of GPIO sleep configuration
I (385) app_start: Starting scheduler on CPU0
I (390) app_start: Starting scheduler on CPU1
I (390) main_task: Started on CPU0
I (400) main_task: Calling app_main()
I (420) pp: pp rom version: e7ae62f
I (420) net80211: net80211 rom version: e7ae62f
I (430) wifi:wifi driver task: 3fca975c, prio:23, stack:6656, core=0
I (430) wifi:wifi firmware version: ce9244d
I (430) wifi:wifi certification version: v7.0
I (430) wifi:config NVS flash: enabled
I (430) wifi:config nano formating: disabled
I (440) wifi:Init data frame dynamic rx buffer num: 32
I (440) wifi:Init management frame dynamic rx buffer num: 32
I (450) wifi:Init management short buffer num: 32
I (450) wifi:Init dynamic tx buffer num: 32
I (460) wifi:Init static tx FG buffer num: 2
I (460) wifi:Init static rx buffer size: 1600
I (460) wifi:Init static rx buffer num: 10
I (470) wifi:Init dynamic rx buffer num: 32
I (470) wifi_init: rx ba win: 6
I (480) wifi_init: tcpip mbox: 32
I (480) wifi_init: udp mbox: 6
I (480) wifi_init: tcp mbox: 6
I (490) wifi_init: tcp tx win: 5744
I (490) wifi_init: tcp rx win: 5744
I (500) wifi_init: tcp mss: 1440
I (500) wifi_init: WiFi IRAM OP enabled
I (500) wifi_init: WiFi RX IRAM OP enabled
I (510) gpio: GPIO[1]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (520) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (530) gpio: GPIO[3]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (540) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (550) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (550) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (560) phy_init: phy_version 601,98f2a71,Jun 29 2023,09:58:12
I (610) wifi:mode : sta (70:04:1d:a4:f0:10)
I (610) wifi:enable tsf
I (1610) EXAMPLE: Sensor: 0, Count: 8302
I (1610) EXAMPLE: Sensor: 1, Count: 8309
I (1610) EXAMPLE: Sensor: 2, Count: 8312
I (1610) EXAMPLE: Sensor: 3, Count: 8331
I (1610) EXAMPLE: Sensor: 4, Count: 8369
I (1620) EXAMPLE: Sensor: 5, Count: 8407
I (1620) EXAMPLE: TotalCount: 50174
I (2630) EXAMPLE: Sensor: 0, Count: 8492
I (2630) EXAMPLE: Sensor: 1, Count: 8493
I (2630) EXAMPLE: Sensor: 2, Count: 8477
I (2630) EXAMPLE: Sensor: 3, Count: 8457
I (2630) EXAMPLE: Sensor: 4, Count: 8457
I (2640) EXAMPLE: Sensor: 5, Count: 8458
I (2640) EXAMPLE: TotalCount: 50974

esp_wifi_start() called after adc_continuous_start()

I (0) cpu_start: App cpu up.
I (272) cpu_start: Pro cpu start user code
I (272) cpu_start: cpu freq: 160000000 Hz
I (272) cpu_start: Application information:
I (275) cpu_start: Project name:     continuous_read
I (280) cpu_start: App version:      1
I (285) cpu_start: Compile time:     Dec  6 2023 12:48:40
I (291) cpu_start: ELF file SHA256:  370b6f71b84cc2c9...
I (297) cpu_start: ESP-IDF:          v5.1.1-dirty
I (302) cpu_start: Min chip rev:     v0.0
I (307) cpu_start: Max chip rev:     v0.99 
I (312) cpu_start: Chip rev:         v0.1
I (316) heap_init: Initializing. RAM available for dynamic allocation:
I (324) heap_init: At 3FC9FA98 len 00049C78 (295 KiB): DRAM
I (330) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (337) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (343) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM
I (350) spi_flash: detected chip: generic
I (354) spi_flash: flash io: dio
W (358) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (371) sleep: Configure to isolate all GPIO pins in sleep state
I (378) sleep: Enable automatic switching of GPIO sleep configuration
I (385) app_start: Starting scheduler on CPU0
I (390) app_start: Starting scheduler on CPU1
I (390) main_task: Started on CPU0
I (400) main_task: Calling app_main()
I (420) pp: pp rom version: e7ae62f
I (420) net80211: net80211 rom version: e7ae62f
I (430) wifi:wifi driver task: 3fca975c, prio:23, stack:6656, core=0
I (430) wifi:wifi firmware version: ce9244d
I (430) wifi:wifi certification version: v7.0
I (430) wifi:config NVS flash: enabled
I (430) wifi:config nano formating: disabled
I (440) wifi:Init data frame dynamic rx buffer num: 32
I (440) wifi:Init management frame dynamic rx buffer num: 32
I (450) wifi:Init management short buffer num: 32
I (450) wifi:Init dynamic tx buffer num: 32
I (460) wifi:Init static tx FG buffer num: 2
I (460) wifi:Init static rx buffer size: 1600
I (460) wifi:Init static rx buffer num: 10
I (470) wifi:Init dynamic rx buffer num: 32
I (470) wifi_init: rx ba win: 6
I (480) wifi_init: tcpip mbox: 32
I (480) wifi_init: udp mbox: 6
I (480) wifi_init: tcp mbox: 6
I (490) wifi_init: tcp tx win: 5744
I (490) wifi_init: tcp rx win: 5744
I (500) wifi_init: tcp mss: 1440
I (500) wifi_init: WiFi IRAM OP enabled
I (500) wifi_init: WiFi RX IRAM OP enabled
I (510) gpio: GPIO[1]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (520) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (530) gpio: GPIO[3]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (540) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (550) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (550) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (560) phy_init: phy_version 601,98f2a71,Jun 29 2023,09:58:12
I (620) wifi:mode : sta (70:04:1d:a4:f0:10)
I (620) wifi:enable tsf
I (1620) EXAMPLE: Sensor: 0, Count: 355
I (1620) EXAMPLE: Sensor: 1, Count: 355
I (1620) EXAMPLE: Sensor: 2, Count: 355
I (1620) EXAMPLE: Sensor: 3, Count: 354
I (1620) EXAMPLE: Sensor: 4, Count: 354
I (1630) EXAMPLE: Sensor: 5, Count: 354
I (1630) EXAMPLE: TotalCount: 2127
I (2640) EXAMPLE: Sensor: 0, Count: 0
I (2640) EXAMPLE: Sensor: 1, Count: 0
I (2640) EXAMPLE: Sensor: 2, Count: 0
I (2640) EXAMPLE: Sensor: 3, Count: 0
I (2640) EXAMPLE: Sensor: 4, Count: 0
I (2650) EXAMPLE: Sensor: 5, Count: 0
I (2650) EXAMPLE: TotalCount: 0
I (3650) EXAMPLE: Sensor: 0, Count: 0
I (3650) EXAMPLE: Sensor: 1, Count: 0
I (3650) EXAMPLE: Sensor: 2, Count: 0
I (3650) EXAMPLE: Sensor: 3, Count: 0
I (3650) EXAMPLE: Sensor: 4, Count: 0
I (3660) EXAMPLE: Sensor: 5, Count: 0
I (3660) EXAMPLE: TotalCount: 0


### More Information.

_No response_
MaxwellAlan commented 9 months ago

Hi @DarmorGamz

Thanks for reporting this issue, we can reproduce locally.

We will take high priority to fix this.

DarmorGamz commented 9 months ago

Hi @MaxwellAlan I appreciate that. There are a few combinations of functions that cause the issue. Even after the Wifi is started, associated, etc.. The ADC will stop running for unknown reasons. The issue I'm currently debugging is

esp_http_client_perform()

Setting my logs to verbose, you can see I'm printing "RAN" if the adc conversion function is called at anypoint between a 1 second interval. If I call esp_http_client_perform() the adc functionality stops. hopefully the below logs of what is being called just before failure helps.

I (13532) METER: RAN
I (13532) METER: I_MS: 618535, 786, Sensor I: 14830
I (13532) METER: V_MS: 208709, 456, 12083
I (13532) METER: W_MS: 2078
I (13532) METER: PF: 107
I (13882) wifi:<ba-add>idx:0 (ifx:0, c2:a5:11:9b:19:da), tid:0, ssn:0, winSize:64
I (13882) wifi:<ba-add>idx:1 (ifx:0, c2:a5:11:9b:19:da), tid:6, ssn:2, winSize:64
D (14382) esp_netif_lwip: esp_netif_internal_dhcpc_cb lwip-netif:0x3fcc16ec
D (14382) esp_netif_lwip: if0x3fcc1678 ip changed=1
D (14382) event: running post IP_EVENT:0 with handler 0x42043798 and context 0x3fcc1988 on loop 0x3fcb51c8
0x42043798: wifi_default_action_sta_got_ip at /COMPONENT_ESP_WIFI_DIR/src/wifi_default.c:127

D (14392) wifi_init_default: Got IP wifi default handler entered
D (14392) esp_netif_handlers: esp_netif action got_ip with netif0x3fcc1678 from event_id=0
I (14402) esp_netif_handlers: sta ip: 192.168.1.38, mask: 255.255.255.0, gw: 192.168.1.1
D (14412) event: running post IP_EVENT:0 with handler 0x42019434 and context 0x3fcc1a88 on loop 0x3fcb51c8
0x42019434: _Callback_WiFiEvents at /COMPONENT_WIFI_DIR/Wifi.c:406

V (14422) esp_adapter: thread sem get: sem=0x3fcae7c4
D (14422) esp_netif_lwip: check: remote, if=0x3fcc1678 fn=0x4203fd30
0x4203fd30: esp_netif_get_dns_info_api at /COMPONENT_ESP_NETIF_DIR/lwip/esp_netif_lwip.c:1948

D (14432) esp_netif_lwip: esp_netif_get_dns_info: esp_netif=0x3fcc1678 type=0
D (14432) HTTP_CLIENT: Begin connect to: http://{REMOVED}.com:80
D (14442) esp_netif_lwip: call api in lwip: ret=0x0, give sem
V (14452) esp_adapter: thread sem get: sem=0x3fcae7c4
V (14452) esp_adapter: thread sem get: sem=0x3fcae7c4
D (14462) event: running post IP_EVENT:0 with handler 0x42010314 and context 0x3fcc3c50 on loop 0x3fcb51c8
0x42010314: mdns_preset_if_handle_system_event at /COMPONENT_ESPRESSIF__MDNS_DIR/mdns.c:4160

D (14472) esp-tls: host:{REMOVED}.com: strlen 12
V (14472) esp_netif_lwip: esp_netif_is_netif_up esp_netif:0x3fcc1678
I (14532) METER: I_MS: 618535, 786, Sensor I: 14830
I (14532) METER: V_MS: 208709, 456, 12083
I (14532) METER: W_MS: 2078
MaxwellAlan commented 9 months ago

Hi @DarmorGamz

Thanks for the info.

We debuged and found that the temperature sensor module(PHY used to calibration) works with ADC modules will cause this issue. image-2024-01-24-10-44-08-733

DarmorGamz commented 9 months ago

Hey @MaxwellAlan I applied the below fix, it seems to correct my original issue where order of Wifi_Start and Adc_Start() mattered. However, esp_http_client_perform() and similar functions still kill the adc.

int16_t phy_get_tsens_value(void)
{
    // return temp_sensor_get_raw_value(NULL);
    return 25;
}
DarmorGamz commented 9 months ago

Using include_esp_phy_override(); and calling esp_http_client_perform() when using PS_NONE causes a system panic. The below logs is what happens before the panic

if (esp_wifi_set_ps(WIFI_PS_NONE) != ESP_OK) { ESP_LOGI(DEBUG_TAG, "Wifi PS failed to set. "); }
D (14112) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:2 posted to loop 0x3fcb50c8
D (14222) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3fcc1578
D (14242) HTTP_CLIENT: on_message_begin
D (14242) HTTP_CLIENT: HEADER=Date:Wed, 24 Jan 2024 16:56:27 GMT
D (14242) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14252) HTTP_CLIENT: HEADER=Content-Type:application/binary
D (14262) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14272) HTTP_CLIENT: HEADER=Content-Length:7
D (14272) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14282) HTTP_CLIENT: HEADER=Connection:close
D (14292) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14302) HTTP_CLIENT: HEADER=Server:Apache
D (14302) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14312) HTTP_CLIENT: HEADER=Vary:User-Agent
D (14312) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14322) HTTP_CLIENT: HEADER=Cache-Control:no-cache
D (14332) event: no handlers have been registered for event ESP_HTTP_CLIENT_EVENT:3 posted to loop 0x3fcb50c8
D (14342) HTTP_CLIENT: http_on_headers_complete, status=200, offset=187, nread=187
D (14352) HTTP_CLIENT: http_on_body zu
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)

No good clues.

Using include_esp_phy_override(); and calling esp_http_client_perform() and not exclusively setting the PS mode doesn't cause a panic, but still causes the ADC to stop.

muexxl commented 7 months ago

WORKAROUND: reduced sample rate ??

I experienced a similar issue: The ADC continous mode stopped filling the DMA buffer when a websocket connection has been opened. When trying to reproduce the bug I found that the ADC keeps on going, when I reduce the adc_continuous_config.sample_freq_hz from 24000 Hz to 6000.

So, as a workaround I need to live with a reduced ADC Sample rate. Maybe this also works for you.

DarmorGamz commented 7 months ago

Hello @muexxl, I'm unsure what ESP-IDF version or chip you're using, however, the issue was solved in a few ways: (my sample rate is still 57K divided by 7 channels)

The IRAM IRQ function needs to be fast enough (minimal execution instructions) to empty the queue before it gets overrun after the WI-FI IRQ runs. The WI-FI will always have more priority.

Increase queue size. This doesn't matter if your IRQ is still too slow to empty it quick enough, but will slow down the failure.

Stop() and Start() ADC wrappers around any WI-FI connection related code. This is not optimal, and I don't use this; but I did prove it works.

What actually solved my issue is realizing how slow the NVS erase and write sequence is. I used the above Stop() and Start() wrappers around any flash erase() write() sequence as it should happen less often and then WI-FI related code. I lose maybe 1 second worth of Mean Square points from the ADC, but it's better than the ADC not working.

Using the above, and writing my own version of the calibration code for speed which doesn't use the calibration handle, I can also convert the digital readings to voltage inline inside the IRQ ADC function now as well. I've increase the bits from 12 to 32, but I only consider 22 bits accurate.

Hope this helps others that end up on this thread. -Darren

muexxl commented 7 months ago

Hey @DarmorGamz,

thanks for your fast response. I am not sure what function you are referring to when mentioning "IRAM IRQ function" .

What function do you refer to ? In case you are referring to the .on_conv_done callback: I am not even using this. I am just regulary checking the DMA buffer via adc_continuous_read(...)

My setup: IDF version: ESP-IDF v5.2.1-dirty Chip: ESP32S3 v0.1