Description
Board
ESP32 Dev Module
Device Description
Since this is a software issue, the hardware configuration is not particularly important.
Hardware Configuration
Since this is a software issue, the hardware configuration is not particularly important.
Version
v3.0.7
IDE Name
ArduinoIDE
Operating System
Windows11
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
115200
Description
Starting with ESP-IDF v5, new drivers have appeared, including for ADC and I2S, and the previous drivers are now called legacy drivers.
Mixing new and legacy drivers can cause malfunctions, so if you use a legacy driver, an announcement will be displayed strongly recommending that you switch to the new driver.
However, I feel that the conflict detection is overly excessive. I have written some code to reproduce a specific example, so please take a look.
Sketch
1_src.ino
#include "2_base.h"
use_class_t instance;
void setup() {
instance.virtual_function();
}
void loop() {}
2_base.h
#pragma once
struct base_t {
virtual int virtual_function(void) = 0;
};
// This class is used at runtime.
struct use_class_t : base_t {
int virtual_function(void) override;
};
// This class is not used at runtime.
struct no_use_class_t : base_t {
int virtual_function(void) override;
};
3_no_use_class.cpp
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If this file exists, the project will go into a reboot loop on startup with an ADC CONFLICT error.
However, if you delete this file, the project will run normally.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
#include <driver/i2s.h>
#include "2_base.h"
// This function is not called at runtime
int no_use_class_t::virtual_function(void)
{
// For example, suppose there is a program that uses a legacy I2S driver.
i2s_write(I2S_NUM_0, nullptr, 0, nullptr, 0);
return 0;
}
4_use_class.cpp
#include <Arduino.h>
#include "2_base.h"
// This function is called at runtime
int use_class_t::virtual_function(void)
{
// use the analog readout.
return analogRead(GPIO_NUM_26);
}
Debug Message
ELF file SHA256: 2fade869ee262244
E (148) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0
E (156) esp_core_dump_elf: Elf write init failed!
E (161) esp_core_dump_common: Core dump write failed with error=-1
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_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:1
load:0x3fff0030,len:4832
load:0x40078000,len:16460
load:0x40080400,len:4
load:0x40080404,len:3504
entry 0x400805cc
E (128) ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver
abort() was called at PC 0x400d536f on core 0
Backtrace: 0x400820cd:0x3ffe3b30 0x400876b9:0x3ffe3b50 0x4008c259:0x3ffe3b70 0x400d536f:0x3ffe3bf0 0x400d795a:0x3ffe3c10 0x4008241e:0x3ffe3c40 0x400797e5:0x3ffe3c80 |<-CORRUPTED
Decoding stack results
0x400820cd: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system\panic.c:466
0x400876b9: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port\esp_system_chip.c:84
0x4008c259: abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib\abort.c:38
0x400d536f: check_adc_oneshot_driver_conflict at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/driver/deprecated\adc_legacy.c:930
0x400d795a: start_cpu0_default at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system\startup.c:205
0x4008241e: call_start_cpu0 at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/xtensa/include\xt_utils.h:40
Other Steps to Reproduce
The important thing here is that although there are derived classes that use the legacy driver, these derived classes are not used at all.
Despite this, the project cannot be started due to a conflict check.
The reason is that the function that checks for conflicts has the __attribute__((constructor))
assigned, which forces a reboot before app_main.
Let me explain a specific situation in which this occurs.
This time, I tried to create a project using a library called ESP8266Audio.
This library contains numerous class definitions, such as the decoder part of the audio codec and the signal output part.
This library also contains a derived class for the signal output part that uses the legacy I2S driver.
I only used the decoder part of this. For the signal output part, I created my own derived class that uses the new I2S driver.
Therefore, I did not use any signal output parts that use the legacy I2S driver.
However, as shown in the example above, it failed to start.
I understand that this is a safety mechanism to prevent mixing of ESP-IDF's legacy driver and the new driver,
and that it is not essentially an issue with ArduinoESP32.
And I also understand that I should advise the ESP8266Audio repository to migrate to the new driver.
(I intend to report this to the ESP-IDF and ESP8266Audio repositories if necessary.)
However, similar problems will likely occur with other products besides ESP8266Audio.
Also, if an abort occurs immediately after startup due to a legacy driver that is not used at runtime, it can be very difficult to identify the cause.
Even if you decode the backtrace, it will be impossible to identify the cause.
Fortunately, it seems that ESP-IDF has recently added a feature to skip conflict checks for legacy drivers.
espressif/esp-idf@c80fa61
I strongly hope that this will be included in the ArduinoESP32 CONFIG.
It should be sufficient to check for conflicts with legacy drivers when initializing the legacy driver.
If a conflict error is output to the log and aborted during initialization, the cause of the problem will also be shown in the backtrace.
I expect that this will be at least more helpful for users than the current situation.
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.