From e6bd66d35d00be5f2ef7ff50e12ebdc2188af169 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 22 Dec 2022 23:22:58 +0100 Subject: [PATCH] improve support for -S2 got myself an adafruit "qt py -S2" with tinyUF2 bootloader. So I wanted to get that working. And it does work :-). FFT time = 10ms (instead of 2ms on classic ESP32) is a very good result, also virtual USB runs much better now. --- platformio.ini | 64 ++++++++++++++++++++++++- usermods/audioreactive/audio_reactive.h | 12 +++-- usermods/audioreactive/audio_source.h | 6 +-- wled00/pin_manager.cpp | 1 + wled00/wled.cpp | 7 ++- 5 files changed, 81 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7919956f83..c8dd7b51b1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -134,6 +134,7 @@ build_flags = -D DECODE_SONY=true -D DECODE_SAMSUNG=true -D DECODE_LG=true + -D DECODE_RC5=true ; -Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library -DWLED_USE_MY_CONFIG ; -D USERMOD_SENSORSTOMQTT @@ -616,7 +617,7 @@ lib_deps_min = build_flags_max = -D WLED_MAX_USERMODS=9 ; default only 4-6 - -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4 ewowi to softhack: move to build_flags_min? + ;; -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4 ewowi to softhack: move to build_flags_min? - We need a different solution -D WLED_USE_MY_CONFIG ; include custom my_config.h ewowi to softhack: redundant as also in build_flags_min? -D USERMOD_DALLASTEMPERATURE -D USE_ALT_DISPLAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI @@ -874,6 +875,67 @@ board_build.flash_mode = qio ; RAM: [== ] 24.7% (used 80856 bytes from 327680 bytes) ; Flash: [======= ] 66.9% (used 1403489 bytes from 2097152 bytes) +;; MM max for Adafruit QT Py ESP32-S2 -> 4MB flash, PSRAM, and tinyUF2 bootloader +;; to ewowi - i'll optimize this entry later, as a few things can be inherited for sure +[env:esp32s2_tinyUF2_PSRAM_max] +extends = esp32_4MB_V4_min_base +platform = ${esp32.platformV4} +platform_packages = ${esp32.platformV4_packages} + +board = adafruit_qtpy_esp32s2 +board_build.partitions = tools/partitions-4MB-tinyuf2_spiffs.csv ;; this is needed for tinyUF2 bootloader! +board_build.f_flash = 80000000L +board_build.flash_mode = qio +upload_speed = 256000 ;; 921600 +build_unflags = ${common.build_unflags} + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S2 (autodetect broken?) + -D USE_ALT_DISPLAY ;; four line display seems to have problems with I2C - it hangs during usermod setup + -D USERMOD_FOUR_LINE_DISPLAY ;; see above + -D USERMOD_ROTARY_ENCODER_UI ;; see above + -D WLED_ENABLE_DMX ;; disabled because it does not work with ESP-IDF 4.4.x (buggy driver in SparkFunDMX) + +build_flags = ${common.build_flags} ${esp32.build_flagsV4} ${esp32s2.build_flags} + -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 + ${common_mm.build_flags_min} ${common_mm.build_flags_max} + -Wno-misleading-indentation -Wno-format-truncation + -D WLED_RELEASE_NAME=esp32S2_4MB_UF2_max + -DARDUINO_USB_CDC_ON_BOOT=1 ;; mandatory, otherwise USB does not work!! + -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 + -D SERVERNAME='"WLED-S2"' + -D WLED_USE_PSRAM + -D WLED_DISABLE_INFRARED ;; save flash space + -D WLED_DISABLE_ALEXA ;; save flash space + -D LEDPIN=39 ;; onboard neopixel LED. Attach your own LEDs to GPIO 7 or GPIO 6 + -D BTNPIN=0 + ;-D RLYPIN=6 + ;-D IRPIN=7 + -D HW_PIN_SCL=40 + -D HW_PIN_SDA=41 + -D HW_PIN_DATASPI=35 + -D HW_PIN_CLOCKSPI=36 + -D HW_PIN_MISOSPI=37 + -D AUDIOPIN=-1 + -D SR_DMTYPE=1 + -D I2S_SDPIN=9 + -D I2S_WSPIN=8 + -D I2S_CKPIN=17 + -D MCLK_PIN=18 + ;-D STATUSLED=-1 + -D WLED_USE_MY_CONFIG + ; -D WLED_DEBUG_HOST='"192.168.xxx.xxx"' ;; to send debug messages over network to host 192.168.x.y - FQDN is also possible + ; -D WLED_DEBUG_NET_PORT=1768 ;; port for network debugging. default = 7868 + ; -D WLED_DEBUG + ; -D SR_DEBUG + ; -D MIC_LOGGER +lib_deps = ${env.lib_deps} ${esp32s2.lib_deps} ${common_mm.lib_deps_min} ${common_mm.lib_deps_max} + paulstoffregen/OneWire@ ^2.3.7 ; used for USERMOD_DALLASTEMPERATURE -> need newer release with bugfixes for -S3; still requires TEMPERATURE_PIN < 46 + olikraus/U8g2@ ^2.34.5 ; used for USERMOD_FOUR_LINE_DISPLAY -> need newer version with bugfixes for arduino-esp32 v2.0.4 (Wire inititialization) + ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU +lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +monitor_filters = esp32_exception_decoder +; RAM: [=== ] 25.6% (used 83796 bytes from 327680 bytes) +; Flash: [==========] 97.7% (used 1408626 bytes from 1441792 bytes) + # ------------------------------------------------------------------------------ # custom board configurations # ------------------------------------------------------------------------------ diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 3f41033c3d..8ea181b40e 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -264,10 +264,14 @@ static float windowWeighingFactors[samplesFFT] = {0.0f}; // Create FFT object #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT // lib_deps += https://github.com/kosme/arduinoFFT#develop @ 1.9.2 +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// these options actually cause slow-down on -S2 (-S2 doesn't have floating point hardware) #define FFT_SPEED_OVER_PRECISION // enables use of reciprocals (1/x etc), and an a few other speedups #define FFT_SQRT_APPROXIMATION // enables "quake3" style inverse sqrt -#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION) +#endif +#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 10-50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION) #else + // around 50% slower on -S2 // lib_deps += https://github.com/blazoncek/arduinoFFT.git #endif #include @@ -1447,10 +1451,10 @@ class AudioReactive : public Usermod { int userloopDelay = int(t_now - lastUMRun); if (lastUMRun == 0) userloopDelay=0; // startup - don't have valid data from last run. - #ifdef WLED_DEBUG + #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) // complain when audio userloop has been delayed for long time. Currently we need userloop running between 500 and 1500 times per second. - if ((userloopDelay > 23) && !disableSoundProcessing && (audioSyncEnabled == 0)) { - DEBUG_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay); + if ((userloopDelay > /*23*/ 30) && !disableSoundProcessing && (audioSyncEnabled == 0)) { + USER_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay); } #endif diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 0af7979f25..62ded98dbe 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -23,14 +23,14 @@ // see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/chip-series-comparison.html#related-documents // and https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/i2s.html#overview-of-all-modes -#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(ESP8266) || defined(ESP8265) +#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(ESP8266) || defined(ESP8265) // there are two things in these MCUs that could lead to problems with audio processing: // * no floating point hardware (FPU) support - FFT uses float calculations. If done in software, a strong slow-down can be expected (between 8x and 20x) // * single core, so FFT task might slow down other things like LED updates #if !defined(SOC_I2S_NUM) || (SOC_I2S_NUM < 1) - #error This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2. + #error This audio reactive usermod does not support ESP32-C2 or ESP32-C3. #else - #warning This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2. + #warning This audio reactive usermod does not support ESP32-C2 and ESP32-C3. #endif #endif diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index 302f6c5a51..3aa0b650ac 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -538,6 +538,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) // 38 to 48 are for general use. Be careful about straping pins GPIO45 and GPIO46 - these may be pull-up or pulled-down on your board. #elif defined(CONFIG_IDF_TARGET_ESP32S2) // strapping pins: 0, 45 & 46 + if (gpio > 18 && gpio < 21) return false; // WLEDMM: 19 + 20 = USB HWCDC. Not recommended for other uses. if (gpio > 21 && gpio < 33) return false; // 22 to 32: not connected + SPI FLASH // JTAG: GPIO39-42 are usually used for inline debugging // GPIO46 is input only and pulled down diff --git a/wled00/wled.cpp b/wled00/wled.cpp index b9120f1a0a..c6cb48b028 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -282,8 +282,13 @@ void WLED::setup() #if ARDUINO_USB_CDC_ON_BOOT delay(2500); // WLEDMM: always allow CDC USB serial to initialise + Serial.println("wait 1"); // waiting a bit longer ensures that a debug messages are shown in serial monitor + delay(2500); + Serial.println("wait 2"); + delay(2500); + Serial.flush(); - //Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later + Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later // WLEDMM: redirect debug output to HWCDC Serial0.setDebugOutput(false); Serial.setDebugOutput(true);