espressif / esp-idf

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

ADC Continuous Readings Affected by NIMBLE Initialization (nimble_port_init()) Resulting in Erratic Readings (IDFGH-13155) #14096

Open filzek opened 4 months ago

filzek commented 4 months ago

Answers checklist.

IDF version.

v5.2.2-220-gaabb3699d1

Espressif SoC revision.

esp32 rev 3

Operating System used.

Windows

How did you build your project?

Command line with Make

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

None

Development Kit.

ESP32 V3 WROVER

Power Supply used.

External 5V

What is the expected behavior?

ADC readings should remain stable and accurate even after initializing NIMBLE with nimble_port_init().

What is the actual behavior?

After initializing NIMBLE, ADC readings become erratic, showing an offset of more than 24 from the correct central reading.

When reading ADC without enabling NIMBLE using nimble_port_init(), the ADC readings are very stable on the ESP32 v3.0. Everything works perfectly. However, as soon as nimble_port_init() is called, the ADC readings become erratic, with a significant number of spurious values showing an odd offset of more than 24 from the correct central reading.

Detailed Description

Steps to reproduce.

  1. Set up the ESP32 v3.0.
  2. Perform ADC readings without calling nimble_port_init().
  3. Observe the stable and accurate ADC readings.
  4. Initialize NIMBLE by calling nimble_port_init().
  5. Perform ADC readings again.
  6. Observe the erratic ADC readings with significant spurious values.

Debug Logs.

BEFORE ENABLE NIMBLE 
Channel [5] Min [1761] Max [1776] offset [15] adjusted [0.02]
Channel [7] Min [1775] Max [1790] offset [15] adjusted [0.02]
Channel [3] Min [1775] Max [1792] offset [17] adjusted [0.03]
Channel [5] Min [1759] Max [1776] offset [17] adjusted [0.03]
Channel [7] Min [1775] Max [1788] offset [13] adjusted [0.01]
Channel [3] Min [1775] Max [1791] offset [16] adjusted [0.02]
Channel [5] Min [1761] Max [1776] offset [15] adjusted [0.02]
Channel [7] Min [1773] Max [1789] offset [16] adjusted [0.02]
Channel [3] Min [1775] Max [1792] offset [17] adjusted [0.03]
Channel [5] Min [1761] Max [1776] offset [15] adjusted [0.02]
Channel [7] Min [1775] Max [1789] offset [14] adjusted [0.02]
Channel [3] Min [1776] Max [1792] offset [16] adjusted [0.02]

AFTER BLE INITIALIZED WITH  nimble_port_init().
Channel [5] Min [1728] Max [1787] offset [59] adjusted [0.20]
Channel [7] Min [1739] Max [1806] offset [67] adjusted [0.23]
Channel [3] Min [1742] Max [1808] offset [66] adjusted [0.23]
Channel [5] Min [1732] Max [1783] offset [51] adjusted [0.17]
Channel [7] Min [1749] Max [1795] offset [46] adjusted [0.15]
Channel [3] Min [1751] Max [1797] offset [46] adjusted [0.15]
Channel [5] Min [1729] Max [1782] offset [53] adjusted [0.17]
Channel [7] Min [1747] Max [1794] offset [47] adjusted [0.15]
Channel [3] Min [1750] Max [1821] offset [71] adjusted [0.25]

More Information.

This issue seems to be directly related to the initialization of NIMBLE. It would be helpful to investigate if there is a conflict between the ADC and NIMBLE subsystems or any shared resources that might be causing this instability.

filzek commented 4 months ago

Findings

We were able to significantly improve the erratic ADC readings by making the following configuration changes:

  1. Pin NIMBLE and Bluetooth to the Second Core:
  1. Disable Logging for NIMBLE:
  1. Disable Software Coexistence:

These changes resulted in more stable ADC readings, reducing the spurious values and improving overall accuracy.

Channel [5] Min [1751] Max [1776] offset [25] adjusted [0.06] Channel [7] Min [1771] Max [1789] offset [18] adjusted [0.03] Channel [3] Min [1774] Max [1792] offset [18] adjusted [0.03] Channel [5] Min [1751] Max [1777] offset [26] adjusted [0.06] Channel [7] Min [1771] Max [1792] offset [21] adjusted [0.04] Channel [3] Min [1773] Max [1795] offset [22] adjusted [0.05]

But this without enable anything else if enable the problems start to happen again with such options as:

nimble_port_freertos_init(ble_spp_server_host_task);

void ble_spp_server_host_task(void *param)
{
    /* This function will return only when nimble_port_stop() is executed */
    nimble_port_run();

    nimble_port_freertos_deinit();
}

Channel [5] Min [1719] Max [1805] offset [86] adjusted [0.31] Channel [7] Min [1737] Max [1891] offset [154] adjusted [0.58] Channel [3] Min [1535] Max [1817] offset [282] adjusted [1.10] Channel [5] Min [1718] Max [1803] offset [85] adjusted [0.30] Channel [7] Min [1736] Max [1811] offset [75] adjusted [0.26] Channel [3] Min [1738] Max [1814] offset [76] adjusted [0.27] Channel [5] Min [1717] Max [1804] offset [87] adjusted [0.31] Channel [7] Min [1734] Max [1810] offset [76] adjusted [0.27] Channel [3] Min [1738] Max [1813] offset [75] adjusted [0.26] Channel [5] Min [1715] Max [1807] offset [92] adjusted [0.33] Channel [7] Min [1522] Max [1811] offset [289] adjusted [1.12] Channel [3] Min [1738] Max [1818] offset [80] adjusted [0.28] Channel [5] Min [1717] Max [1873] offset [156] adjusted [0.59] Channel [7] Min [1737] Max [1811] offset [74] adjusted [0.26] Channel [3] Min [1739] Max [1813] offset [74] adjusted [0.26] Channel [5] Min [1716] Max [1854] offset [138] adjusted [0.52] Channel [7] Min [1735] Max [1811] offset [76] adjusted [0.27] Channel [3] Min [1738] Max [1813] offset [75] adjusted [0.26] Channel [5] Min [1719] Max [1805] offset [86] adjusted [0.31] Channel [7] Min [1738] Max [1812] offset [74] adjusted [0.26] Channel [3] Min [1517] Max [1814] offset [297] adjusted [1.16] Channel [5] Min [1718] Max [1805] offset [87] adjusted [0.31] Channel [7] Min [1737] Max [1810] offset [73] adjusted [0.25] Channel [3] Min [1605] Max [1814] offset [209] adjusted [0.80]

so the spourious reading become a real problem and this cannot be filtered at all.

filzek commented 4 months ago

Another problem found, it also corrupts the NIMBLE to allow devices to connect to it, broke the gatt to status 8 and later fasilled to status 133, this seens to runs only when adc continuous are enable.