Skip to content

Commit e6bd66d

Browse files
committed
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.
1 parent f9b9716 commit e6bd66d

File tree

5 files changed

+81
-9
lines changed

5 files changed

+81
-9
lines changed

platformio.ini

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ build_flags =
134134
-D DECODE_SONY=true
135135
-D DECODE_SAMSUNG=true
136136
-D DECODE_LG=true
137+
-D DECODE_RC5=true
137138
; -Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library
138139
-DWLED_USE_MY_CONFIG
139140
; -D USERMOD_SENSORSTOMQTT
@@ -616,7 +617,7 @@ lib_deps_min =
616617

617618
build_flags_max =
618619
-D WLED_MAX_USERMODS=9 ; default only 4-6
619-
-D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4 ewowi to softhack: move to build_flags_min?
620+
;; -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
620621
-D WLED_USE_MY_CONFIG ; include custom my_config.h ewowi to softhack: redundant as also in build_flags_min?
621622
-D USERMOD_DALLASTEMPERATURE
622623
-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
874875
; RAM: [== ] 24.7% (used 80856 bytes from 327680 bytes)
875876
; Flash: [======= ] 66.9% (used 1403489 bytes from 2097152 bytes)
876877

878+
;; MM max for Adafruit QT Py ESP32-S2 -> 4MB flash, PSRAM, and tinyUF2 bootloader
879+
;; to ewowi - i'll optimize this entry later, as a few things can be inherited for sure
880+
[env:esp32s2_tinyUF2_PSRAM_max]
881+
extends = esp32_4MB_V4_min_base
882+
platform = ${esp32.platformV4}
883+
platform_packages = ${esp32.platformV4_packages}
884+
885+
board = adafruit_qtpy_esp32s2
886+
board_build.partitions = tools/partitions-4MB-tinyuf2_spiffs.csv ;; this is needed for tinyUF2 bootloader!
887+
board_build.f_flash = 80000000L
888+
board_build.flash_mode = qio
889+
upload_speed = 256000 ;; 921600
890+
build_unflags = ${common.build_unflags}
891+
-D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S2 (autodetect broken?)
892+
-D USE_ALT_DISPLAY ;; four line display seems to have problems with I2C - it hangs during usermod setup
893+
-D USERMOD_FOUR_LINE_DISPLAY ;; see above
894+
-D USERMOD_ROTARY_ENCODER_UI ;; see above
895+
-D WLED_ENABLE_DMX ;; disabled because it does not work with ESP-IDF 4.4.x (buggy driver in SparkFunDMX)
896+
897+
build_flags = ${common.build_flags} ${esp32.build_flagsV4} ${esp32s2.build_flags}
898+
-D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0
899+
${common_mm.build_flags_min} ${common_mm.build_flags_max}
900+
-Wno-misleading-indentation -Wno-format-truncation
901+
-D WLED_RELEASE_NAME=esp32S2_4MB_UF2_max
902+
-DARDUINO_USB_CDC_ON_BOOT=1 ;; mandatory, otherwise USB does not work!!
903+
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0
904+
-D SERVERNAME='"WLED-S2"'
905+
-D WLED_USE_PSRAM
906+
-D WLED_DISABLE_INFRARED ;; save flash space
907+
-D WLED_DISABLE_ALEXA ;; save flash space
908+
-D LEDPIN=39 ;; onboard neopixel LED. Attach your own LEDs to GPIO 7 or GPIO 6
909+
-D BTNPIN=0
910+
;-D RLYPIN=6
911+
;-D IRPIN=7
912+
-D HW_PIN_SCL=40
913+
-D HW_PIN_SDA=41
914+
-D HW_PIN_DATASPI=35
915+
-D HW_PIN_CLOCKSPI=36
916+
-D HW_PIN_MISOSPI=37
917+
-D AUDIOPIN=-1
918+
-D SR_DMTYPE=1
919+
-D I2S_SDPIN=9
920+
-D I2S_WSPIN=8
921+
-D I2S_CKPIN=17
922+
-D MCLK_PIN=18
923+
;-D STATUSLED=-1
924+
-D WLED_USE_MY_CONFIG
925+
; -D WLED_DEBUG_HOST='"192.168.xxx.xxx"' ;; to send debug messages over network to host 192.168.x.y - FQDN is also possible
926+
; -D WLED_DEBUG_NET_PORT=1768 ;; port for network debugging. default = 7868
927+
; -D WLED_DEBUG
928+
; -D SR_DEBUG
929+
; -D MIC_LOGGER
930+
lib_deps = ${env.lib_deps} ${esp32s2.lib_deps} ${common_mm.lib_deps_min} ${common_mm.lib_deps_max}
931+
paulstoffregen/OneWire@ ^2.3.7 ; used for USERMOD_DALLASTEMPERATURE -> need newer release with bugfixes for -S3; still requires TEMPERATURE_PIN < 46
932+
olikraus/U8g2@ ^2.34.5 ; used for USERMOD_FOUR_LINE_DISPLAY -> need newer version with bugfixes for arduino-esp32 v2.0.4 (Wire inititialization)
933+
ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU
934+
lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation
935+
monitor_filters = esp32_exception_decoder
936+
; RAM: [=== ] 25.6% (used 83796 bytes from 327680 bytes)
937+
; Flash: [==========] 97.7% (used 1408626 bytes from 1441792 bytes)
938+
877939
# ------------------------------------------------------------------------------
878940
# custom board configurations
879941
# ------------------------------------------------------------------------------

usermods/audioreactive/audio_reactive.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,14 @@ static float windowWeighingFactors[samplesFFT] = {0.0f};
264264
// Create FFT object
265265
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
266266
// lib_deps += https://github.com/kosme/arduinoFFT#develop @ 1.9.2
267+
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
268+
// these options actually cause slow-down on -S2 (-S2 doesn't have floating point hardware)
267269
#define FFT_SPEED_OVER_PRECISION // enables use of reciprocals (1/x etc), and an a few other speedups
268270
#define FFT_SQRT_APPROXIMATION // enables "quake3" style inverse sqrt
269-
#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION)
271+
#endif
272+
#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 10-50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION)
270273
#else
274+
// around 50% slower on -S2
271275
// lib_deps += https://github.com/blazoncek/arduinoFFT.git
272276
#endif
273277
#include <arduinoFFT.h>
@@ -1447,10 +1451,10 @@ class AudioReactive : public Usermod {
14471451
int userloopDelay = int(t_now - lastUMRun);
14481452
if (lastUMRun == 0) userloopDelay=0; // startup - don't have valid data from last run.
14491453

1450-
#ifdef WLED_DEBUG
1454+
#if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS)
14511455
// complain when audio userloop has been delayed for long time. Currently we need userloop running between 500 and 1500 times per second.
1452-
if ((userloopDelay > 23) && !disableSoundProcessing && (audioSyncEnabled == 0)) {
1453-
DEBUG_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay);
1456+
if ((userloopDelay > /*23*/ 30) && !disableSoundProcessing && (audioSyncEnabled == 0)) {
1457+
USER_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay);
14541458
}
14551459
#endif
14561460

usermods/audioreactive/audio_source.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
// see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/chip-series-comparison.html#related-documents
2525
// and https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/i2s.html#overview-of-all-modes
26-
#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)
26+
#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)
2727
// there are two things in these MCUs that could lead to problems with audio processing:
2828
// * 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)
2929
// * single core, so FFT task might slow down other things like LED updates
3030
#if !defined(SOC_I2S_NUM) || (SOC_I2S_NUM < 1)
31-
#error This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
31+
#error This audio reactive usermod does not support ESP32-C2 or ESP32-C3.
3232
#else
33-
#warning This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
33+
#warning This audio reactive usermod does not support ESP32-C2 and ESP32-C3.
3434
#endif
3535
#endif
3636

wled00/pin_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output)
538538
// 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.
539539
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
540540
// strapping pins: 0, 45 & 46
541+
if (gpio > 18 && gpio < 21) return false; // WLEDMM: 19 + 20 = USB HWCDC. Not recommended for other uses.
541542
if (gpio > 21 && gpio < 33) return false; // 22 to 32: not connected + SPI FLASH
542543
// JTAG: GPIO39-42 are usually used for inline debugging
543544
// GPIO46 is input only and pulled down

wled00/wled.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,13 @@ void WLED::setup()
282282

283283
#if ARDUINO_USB_CDC_ON_BOOT
284284
delay(2500); // WLEDMM: always allow CDC USB serial to initialise
285+
Serial.println("wait 1"); // waiting a bit longer ensures that a debug messages are shown in serial monitor
286+
delay(2500);
287+
Serial.println("wait 2");
288+
delay(2500);
289+
285290
Serial.flush();
286-
//Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later
291+
Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later
287292
// WLEDMM: redirect debug output to HWCDC
288293
Serial0.setDebugOutput(false);
289294
Serial.setDebugOutput(true);

0 commit comments

Comments
 (0)