Skip to content

Commit f9b9716

Browse files
committed
Improvements for -S2
- new partition table for boards with UF2 boot (Adafruit qt py S2) - better treatment of debug out using "USBCDC" native port - workarounds for watchdog crashes on -S2 - Add missing but mandatory build flags for -S2 and -C3
1 parent 028b12c commit f9b9716

File tree

7 files changed

+57
-11
lines changed

7 files changed

+57
-11
lines changed

platformio.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ build_flagsV4 = -g
260260
-DARDUINO_ARCH_ESP32 -DESP32
261261
-DCONFIG_LITTLEFS_FOR_IDF_3_2 -DLFS_THREADSAFE
262262
-D CONFIG_ASYNC_TCP_USE_WDT=0
263+
; -DARDUINO_USB_CDC_ON_BOOT=0 ;; mandatory for "classic ESP32" when builing with arduino-esp32 >=2.0.3
263264
;;; V4.4.x libraries (without LOROL_LITTLEFS; with newer NeoPixelBus)
264265
lib_depsV4 =
265266
${env.lib_deps}
@@ -274,10 +275,11 @@ build_flags = -g
274275
-DCONFIG_IDF_TARGET_ESP32S2
275276
-D CONFIG_ASYNC_TCP_USE_WDT=0
276277
-DCO
278+
-DARDUINO_USB_MODE=0 ;; WLEDMM - mandatory for ESP32-S2 when builing with arduino-esp32 >=2.0.3
277279

278280
lib_deps =
279281
${env.lib_deps}
280-
makuna/NeoPixelBus @ 2.6.9
282+
makuna/NeoPixelBus @ 2.7.1 ;; WLEDMM - new version is more stable on -S2
281283
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
282284

283285
[esp32c3]
@@ -287,6 +289,7 @@ build_flags = -g
287289
-DCONFIG_IDF_TARGET_ESP32C3
288290
-D CONFIG_ASYNC_TCP_USE_WDT=0
289291
-DCO
292+
-DARDUINO_USB_MODE=1 ;; WLEDMM - mandatory for ESP32-C3 when builing with arduino-esp32 >=2.0.3
290293

291294
lib_deps =
292295
${env.lib_deps}

tools/ESP32-Chip_info.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,16 @@ void showRealSpeed() {
545545
Serial.print("FLASH SIZE (magic byte): "); Serial.print(ESP.getFlashChipSize() / (1024.0 * 1024), 2); Serial.println(" MB");
546546
Serial.print("FLASH MODE (magic byte): "); Serial.print(ESP.getFlashChipMode()); Serial.println(" ; 0=QIO, 1=QOUT, 2=DIO, 3=DOUT or other\n");
547547

548+
Serial.flush();
548549
Serial.print("FLASH CHIP ID: 0x"); Serial.println(my_ESP_getFlashChipId(), HEX);
549-
Serial.print("FLASH CHIP FREQ: "); Serial.print(my_ESP_getFlashChipSpeed() / 1000000.0, 1); Serial.println(" MHz");
550+
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
551+
//Serial.print("FLASH CHIP FREQ: "); Serial.print(my_ESP_getFlashChipSpeed() / 1000000.0, 1); Serial.println(" MHz"); // this seems to crash on -S2
552+
#endif
550553
Serial.print("FLASH REAL SIZE: "); Serial.print(my_ESP_getFlashChipRealSize() / (1024.0 * 1024), 2); Serial.println(" MB");
551554
Serial.print("FLASH REAL MODE: "); Serial.println(my_ESP_getFlashChipMode());
552555

553556
Serial.println(F("\n------------------------------------"));
557+
Serial.flush();
554558
Serial.print( "RAM HEAP SIZE: "); Serial.print(ESP.getHeapSize() / 1024.0, 2); Serial.println(" KB");
555559
Serial.print( " FREE RAM: "); Serial.print(ESP.getFreeHeap() / 1024.0, 2); Serial.println(" KB");
556560
Serial.print( " MAX RAM alloc: "); Serial.print(ESP.getMaxAllocHeap() / 1024.0, 2); Serial.println(" KB");
@@ -566,6 +570,7 @@ void showRealSpeed() {
566570
Serial.println();
567571
show_psram_info_part2();
568572
}
573+
Serial.flush();
569574
#endif
570575

571576
Serial.println();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ESP-IDF Partition Table
2+
# Name, Type, SubType, Offset, Size, Flags
3+
# bootloader.bin,, 0x1000, 32K
4+
# partition table, 0x8000, 4K
5+
6+
nvs, data, nvs, 0x9000, 20K,
7+
otadata, data, ota, 0xe000, 8K,
8+
ota_0, 0, ota_0, 0x10000, 1408K,
9+
ota_1, 0, ota_1, 0x170000, 1408K,
10+
uf2, app, factory,0x2d0000, 256K,
11+
spiffs, data, spiffs, 0x310000, 960K,

usermods/audioreactive/audio_reactive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static float fftAddAvg(int from, int to) {
309309
//
310310
void FFTcode(void * parameter)
311311
{
312-
DEBUGSR_PRINT("FFT started on core: "); DEBUGSR_PRINTLN(xPortGetCoreID());
312+
// DEBUGSR_PRINT("FFT started on core: "); DEBUGSR_PRINTLN(xPortGetCoreID()); // causes trouble on -S2
313313

314314
// see https://www.freertos.org/vtaskdelayuntil.html
315315
const TickType_t xFrequency = FFT_MIN_CYCLE * portTICK_PERIOD_MS;

wled00/pin_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN in
114114

115115
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
116116
// ESP32-S2
117-
if (gpio > 38 && gpio < 43) return (F("USB (CDC) / JTAG"));
117+
//if (gpio > 38 && gpio < 43) return (F("USB (CDC) / JTAG")); // note to self: this seems to be wrong. need to fix later.
118118
if (gpio == 46) return (F("pulled-down, input only"));
119119
//if (gpio == 0 || gpio == 45 || gpio == 46) return (F("(strapping pin)"));
120120

wled00/wled.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,22 @@ void WLED::setup()
276276
#endif
277277

278278
Serial.begin(115200);
279-
Serial.setTimeout(50);
280279
#if defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT)
281280
delay(2500); // allow CDC USB serial to initialise
282281
#endif
282+
283+
#if ARDUINO_USB_CDC_ON_BOOT
284+
delay(2500); // WLEDMM: always allow CDC USB serial to initialise
285+
Serial.flush();
286+
//Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later
287+
// WLEDMM: redirect debug output to HWCDC
288+
Serial0.setDebugOutput(false);
289+
Serial.setDebugOutput(true);
290+
#else
291+
Serial.setTimeout(50);
292+
#endif
293+
294+
//Serial0.setDebugOutput(false);
283295
//Serial.setDebugOutput(true);
284296
USER_FLUSH(); delay(100);
285297
USER_PRINTLN();
@@ -362,14 +374,26 @@ void WLED::setup()
362374
pinManager.allocatePin(2, true, PinOwner::DMX);
363375
#endif
364376

377+
// WLEDMM experimental: support for single neoPixel on Adafruit boards
378+
#if 0
379+
//#ifdef PIN_NEOPIXEL
380+
//pinManager.allocatePin(PIN_NEOPIXEL, true, PinOwner::BusDigital);
381+
//#endif
382+
#ifdef NEOPIXEL_POWER
383+
pinManager.allocatePin(NEOPIXEL_POWER, true, PinOwner::Relay); // just to ensure this GPIO will not get used for other purposes
384+
pinMode(NEOPIXEL_POWER, OUTPUT);
385+
digitalWrite(NEOPIXEL_POWER, HIGH);
386+
#endif
387+
#endif
388+
365389
USER_PRINTLN();
366390
DEBUG_PRINTLN(F("Registering usermods ..."));
367391
registerUsermods();
368392

369393
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) btnPin[i] = -1;
370394

371395
bool fsinit = false;
372-
DEBUG_PRINTLN(F("Mount FS"));
396+
USER_PRINTLN(F("Mount FS"));
373397
#ifdef ARDUINO_ARCH_ESP32
374398
fsinit = WLED_FS.begin(true);
375399
#else
@@ -386,6 +410,8 @@ void WLED::setup()
386410
#endif
387411
updateFSInfo();
388412

413+
USER_PRINTLN(F("done Mounting FS"));
414+
389415
// generate module IDs must be done before AP setup
390416
escapedMac = WiFi.macAddress();
391417
escapedMac.replace(":", "");

wled00/wled.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include <user_interface.h>
7272
}
7373
#else // ESP32
74+
#include <HardwareSerial.h> // WLEDMM: needed to get Serial and HWCDC when using arduino-esp32 v2.0.x
7475
#include <WiFi.h>
7576
#include <ETH.h>
7677
#include "esp_wifi.h"
@@ -744,7 +745,7 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
744745

745746
// WLEDMM: macros to print "user messages" to Serial
746747
// cannot do this on -S2, due to buggy USBCDC serial driver
747-
#if defined(WLED_DEBUG) || defined(WLED_DEBUG_HOST) || defined(CONFIG_IDF_TARGET_ESP32S2)
748+
#if defined(WLED_DEBUG) || defined(WLED_DEBUG_HOST)
748749
// use DEBUG_PRINT
749750
#define USER_PRINT(x) DEBUG_PRINT(x)
750751
#define USER_PRINTLN(x) DEBUG_PRINTLN(x)
@@ -756,10 +757,10 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
756757
#endif
757758
#else
758759
// if serial is availeable, we use Serial.print directly
759-
#define USER_PRINT(x) { if (canUseSerial()) Serial.print(x); }
760-
#define USER_PRINTLN(x) { if (canUseSerial()) Serial.println(x); }
761-
#define USER_PRINTF(x...) { if (canUseSerial()) Serial.printf(x); }
762-
#define USER_FLUSH() {Serial.flush();}
760+
#define USER_PRINT(x) { if (canUseSerial()) DEBUGOUT.print(x); }
761+
#define USER_PRINTLN(x) { if (canUseSerial()) DEBUGOUT.println(x); }
762+
#define USER_PRINTF(x...) { if (canUseSerial()) DEBUGOUT.printf(x); }
763+
#define USER_FLUSH() {DEBUGOUT.flush();}
763764
#endif
764765
// WLEDMM end
765766

0 commit comments

Comments
 (0)