Skip to content

Commit c85f65e

Browse files
committed
better handling of esp32 PICO-D2 and PICO-V3
including PICO models with PSRAM
1 parent fef8de0 commit c85f65e

3 files changed

Lines changed: 45 additions & 36 deletions

File tree

wled00/json.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,8 @@ void serializeInfo(JsonObject root)
11341134
root[F("freestack")] = uxTaskGetStackHighWaterMark(NULL); //WLEDMM
11351135
root[F("minfreeheap")] = ESP.getMinFreeHeap();
11361136
#endif
1137-
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
1137+
#if defined(ARDUINO_ARCH_ESP32)
1138+
#if defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3) // V4 can auto-detect PSRAM
11381139
if (psramFound()) {
11391140
root[F("tpsram")] = ESP.getPsramSize(); //WLEDMM
11401141
root[F("psram")] = ESP.getFreePsram();
@@ -1147,11 +1148,7 @@ void serializeInfo(JsonObject root)
11471148
#endif
11481149
#endif
11491150
}
1150-
#else
1151-
// for testing
1152-
// root[F("tpsram")] = 4194304; //WLEDMM
1153-
// root[F("psram")] = 4193000;
1154-
// root[F("psusedram")] = 3083000;
1151+
#endif
11551152
#endif
11561153

11571154
// begin WLEDMM

wled00/pin_manager.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -756,30 +756,32 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) const
756756
// JTAG: GPIO39-42 are usually used for inline debugging
757757
// GPIO46 is input only and pulled down
758758
#else
759-
if ((gpio > 5 && gpio < 12) && // WLEDMM slightly faster to first check for "potentially reserved pins" and then call ESP.getChipModel()
760-
((strncmp_P(PSTR("ESP32-U4WDH"), ESP.getChipModel(), 11) == 0) || // this is the correct identifier, but....
761-
(strncmp_P(PSTR("ESP32-PICO-D2"), ESP.getChipModel(), 13) == 0))) // https://github.com/espressif/arduino-esp32/issues/10683
762-
{
763-
// this chip has 4 MB of internal Flash and different packaging, so available pins are different!
764-
if (((gpio > 5) && (gpio < 9)) || (gpio == 11))
765-
return false;
766-
} else {
767-
// for classic ESP32 (non-mini) modules, these are the SPI flash pins
768-
if (gpio > 5 && gpio < 12) return false; //SPI flash pins
759+
// WLEDMM slightly faster to first check for "potentially reserved pins" and then call ESP.getChipModel()
760+
if (gpio > 5 && gpio < 12) {
761+
if ((strncmp_P(PSTR("ESP32-U4WDH"), ESP.getChipModel(), 11) == 0) || // this is the correct identifier, but....
762+
(strncmp_P(PSTR("ESP32-PICO-D"), ESP.getChipModel(), 12) == 0)) { // https://github.com/espressif/arduino-esp32/issues/10683
763+
// this chip has 4 MB of internal Flash and different packaging, so available pins are different!
764+
if ((gpio > 5 && gpio < 9) || gpio == 11) return false; // U4WDH/PICO-D2 & PICO-D4: GPIO 6, 7, 8, 11 are used for SPI flash; 9 & 10 are free
765+
// if (gpio == 16 || gpio == 17) return false; // U4WDH/PICO-D?: GPIO 16 and 17 are used for PSRAM --> WLEDMM handled by WLED::setup()
766+
} else {
767+
if (strncmp_P(PSTR("ESP32-PICO-V3"), ESP.getChipModel(), 13) == 0) {
768+
if (gpio == 6 || gpio == 11) return false; // PICO-V3: uses GPIO 6 and 11 for flash
769+
if (strstr_P(ESP.getChipModel(), PSTR("V3-02")) != nullptr && (gpio == 9 || gpio == 10)) return false; // PICO-V3-02: uses GPIO 9 and 10 for PSRAM; 7, 8 are free
770+
} else
771+
// for classic ESP32 (non-mini) modules, these are the SPI flash pins
772+
return false; //SPI flash = pins 6, 7, 8, 9, 10, 11
773+
}
769774
}
770-
// WLEDMM gpio 16/17 (PSRAM or SPI FLASH) are handled differently !
771-
//
772-
// if (((strncmp_P(PSTR("ESP32-PICO"), ESP.getChipModel(), 10) == 0) ||
773-
// (strncmp_P(PSTR("ESP32-U4WDH"), ESP.getChipModel(), 11) == 0))
774-
// && (gpio == 16 || gpio == 17)) return false; // PICO-D4/U4WDH: gpio16+17 are in use for onboard SPI FLASH
775-
// if (gpio == 16) return !psramFound(); // PSRAM pins on modules with off-package or in-package PSRAM
776-
// if (gpio == 17) {
777-
// if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) {
778-
// return true;
779-
// } else {
780-
// return !psramFound(); // PSRAM pins on modules with in-package PSRAM
781-
// }
782-
// }
775+
776+
// WLEDMM gpio 16/17 (PSRAM or SPI FLASH) are handled differently in WLED::setup() !!
777+
//if (gpio == 16) return !psramFound(); // PSRAM pins on modules with off-package or in-package PSRAM
778+
//if (gpio == 17) {
779+
// if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) {
780+
// return true;
781+
// } else {
782+
// return !psramFound(); // PSRAM pins on modules with in-package PSRAM
783+
// }
784+
783785
#endif
784786
if (output) return digitalPinCanOutput(gpio);
785787
else return true;
@@ -789,7 +791,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) const
789791
if (gpio < 12) return false; //SPI flash pins
790792
if (gpio <= NUM_DIGITAL_PINS) return true; //WLEDMM: include pin 17 / A0 / Audio in
791793
#endif
792-
return false;
794+
return false; // catches all other invalid pins
793795
}
794796

795797
PinOwner PinManagerClass::getPinOwner(byte gpio) const {

wled00/wled.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ void WLED::loop()
365365
DEBUG_PRINT(F("Avail heap: ")); DEBUG_PRINTLN(ESP.getMaxAllocHeap());
366366
DEBUG_PRINTF("%s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM
367367
#endif
368-
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
368+
#if defined(ARDUINO_ARCH_ESP32)
369+
#if defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3) // V4 can auto-detect PSRAM
369370
if (psramFound()) {
370371
//DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB");
371372
DEBUG_PRINT(F("Free PSRAM : ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB");
@@ -376,6 +377,7 @@ void WLED::loop()
376377
//DEBUG_PRINTLN(F("No PSRAM"));
377378
}
378379
#endif
380+
#endif
379381
DEBUG_PRINT(F("Wifi state: ")); DEBUG_PRINTLN(WiFi.status());
380382

381383
if (WiFi.status() != lastWifiState) {
@@ -666,7 +668,7 @@ void WLED::setup()
666668
// C3: reserve GPIO 12-17 for PSRAM (may fail due to isPinOk() but that will also prevent other allocation)
667669
//managed_pin_type pins[] = { {12, true}, {13, true}, {14, true}, {15, true}, {16, true}, {17, true} };
668670
//pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM);
669-
#else
671+
#elif defined(CONFIG_IDF_TARGET_ESP32)
670672
// GPIO16/GPIO17 reserved for SPI RAM
671673
if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) {
672674
// ESP32-D0WDR2-V3 keeps gpio17 available
@@ -678,7 +680,7 @@ void WLED::setup()
678680
}
679681

680682
#endif
681-
#if defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON)) // WLEDMM
683+
#if (defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3)) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON)) // WLEDMM
682684
if (psramFound()) {
683685
DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB");
684686
DEBUG_PRINT(F("Free PSRAM : ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB");
@@ -690,11 +692,19 @@ void WLED::setup()
690692
#if defined(ARDUINO_ARCH_ESP32)
691693
if ((strncmp("ESP32-PICO", ESP.getChipModel(), 10) == 0) || (strncmp("ESP32-U4WDH", ESP.getChipModel(), 11) == 0))
692694
{ // WLEDMM detect pico board and esp32-mini1 board at runtime
693-
// special handling for PICO-D4: gpio16+17 are in use for onboard SPI FLASH (not PSRAM)
695+
// PICO-D4: gpio16+17 are in use for onboard SPI FLASH (not PSRAM)
696+
// U4WDH / PICO-D2 / PICO-V3 / PICO-V3-02 : GPIO 16 and 17 are either used for PSRAM, or not connected
694697
managed_pin_type pins[] = { {16, true}, {17, true} };
695698
pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM);
696699
}
697-
#endif
700+
#if !defined(BOARD_HAS_PSRAM)
701+
if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) {
702+
// runtime detect ESP32-D0WDR2-V3: needs gpio16 for PSRAM, but keeps gpio17 available
703+
managed_pin_type pins[] = { {16, true} };
704+
pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM);
705+
}
706+
#endif
707+
#endif
698708

699709
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
700710
//DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap());
@@ -706,7 +716,7 @@ void WLED::setup()
706716
pinManager.allocatePin(2, true, PinOwner::DMX);
707717
#endif
708718

709-
#if defined(ALL_JSON_TO_PSRAM) && defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM_JSON) || defined(WLED_USE_PSRAM))
719+
#if defined(ALL_JSON_TO_PSRAM) && (defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3)) && (defined(WLED_USE_PSRAM_JSON) || defined(WLED_USE_PSRAM))
710720
if (psramFound()) {
711721
DEBUG_PRINT(F("\nfree heap ")); DEBUG_PRINTLN(ESP.getFreeHeap());
712722
USER_PRINTLN(F("JSON garbage collection (initial)."));

0 commit comments

Comments
 (0)