diff --git a/wled00/json.cpp b/wled00/json.cpp index 2e4e98e9..1b8b0fea 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -1134,7 +1134,8 @@ void serializeInfo(JsonObject root) root[F("freestack")] = uxTaskGetStackHighWaterMark(NULL); //WLEDMM root[F("minfreeheap")] = ESP.getMinFreeHeap(); #endif - #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) + #if defined(ARDUINO_ARCH_ESP32) + #if defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3) // V4 can auto-detect PSRAM if (psramFound()) { root[F("tpsram")] = ESP.getPsramSize(); //WLEDMM root[F("psram")] = ESP.getFreePsram(); @@ -1147,11 +1148,7 @@ void serializeInfo(JsonObject root) #endif #endif } - #else - // for testing - // root[F("tpsram")] = 4194304; //WLEDMM - // root[F("psram")] = 4193000; - // root[F("psusedram")] = 3083000; + #endif #endif // begin WLEDMM diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index 1bdb05f9..20fb8446 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -756,30 +756,32 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) const // JTAG: GPIO39-42 are usually used for inline debugging // GPIO46 is input only and pulled down #else - if ((gpio > 5 && gpio < 12) && // WLEDMM slightly faster to first check for "potentially reserved pins" and then call ESP.getChipModel() - ((strncmp_P(PSTR("ESP32-U4WDH"), ESP.getChipModel(), 11) == 0) || // this is the correct identifier, but.... - (strncmp_P(PSTR("ESP32-PICO-D2"), ESP.getChipModel(), 13) == 0))) // https://github.com/espressif/arduino-esp32/issues/10683 - { - // this chip has 4 MB of internal Flash and different packaging, so available pins are different! - if (((gpio > 5) && (gpio < 9)) || (gpio == 11)) - return false; - } else { - // for classic ESP32 (non-mini) modules, these are the SPI flash pins - if (gpio > 5 && gpio < 12) return false; //SPI flash pins + // WLEDMM slightly faster to first check for "potentially reserved pins" and then call ESP.getChipModel() + if (gpio > 5 && gpio < 12) { + if ((strncmp_P(PSTR("ESP32-U4WDH"), ESP.getChipModel(), 11) == 0) || // this is the correct identifier, but.... + (strncmp_P(PSTR("ESP32-PICO-D"), ESP.getChipModel(), 12) == 0)) { // https://github.com/espressif/arduino-esp32/issues/10683 + // this chip has 4 MB of internal Flash and different packaging, so available pins are different! + 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 + // if (gpio == 16 || gpio == 17) return false; // U4WDH/PICO-D?: GPIO 16 and 17 are used for PSRAM --> WLEDMM handled by WLED::setup() + } else { + if (strncmp_P(PSTR("ESP32-PICO-V3"), ESP.getChipModel(), 13) == 0) { + if (gpio == 6 || gpio == 11) return false; // PICO-V3: uses GPIO 6 and 11 for flash + 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 + } else + // for classic ESP32 (non-mini) modules, these are the SPI flash pins + return false; //SPI flash = pins 6, 7, 8, 9, 10, 11 + } } - // WLEDMM gpio 16/17 (PSRAM or SPI FLASH) are handled differently ! - // - // if (((strncmp_P(PSTR("ESP32-PICO"), ESP.getChipModel(), 10) == 0) || - // (strncmp_P(PSTR("ESP32-U4WDH"), ESP.getChipModel(), 11) == 0)) - // && (gpio == 16 || gpio == 17)) return false; // PICO-D4/U4WDH: gpio16+17 are in use for onboard SPI FLASH - // if (gpio == 16) return !psramFound(); // PSRAM pins on modules with off-package or in-package PSRAM - // if (gpio == 17) { - // if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) { - // return true; - // } else { - // return !psramFound(); // PSRAM pins on modules with in-package PSRAM - // } - // } + + // WLEDMM gpio 16/17 (PSRAM or SPI FLASH) are handled differently in WLED::setup() !! + //if (gpio == 16) return !psramFound(); // PSRAM pins on modules with off-package or in-package PSRAM + //if (gpio == 17) { + // if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) { + // return true; + // } else { + // return !psramFound(); // PSRAM pins on modules with in-package PSRAM + // } + #endif if (output) return digitalPinCanOutput(gpio); else return true; @@ -789,7 +791,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) const if (gpio < 12) return false; //SPI flash pins if (gpio <= NUM_DIGITAL_PINS) return true; //WLEDMM: include pin 17 / A0 / Audio in #endif - return false; + return false; // catches all other invalid pins } PinOwner PinManagerClass::getPinOwner(byte gpio) const { diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 9be26682..6798c748 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -365,7 +365,8 @@ void WLED::loop() DEBUG_PRINT(F("Avail heap: ")); DEBUG_PRINTLN(ESP.getMaxAllocHeap()); DEBUG_PRINTF("%s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM #endif - #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) + #if defined(ARDUINO_ARCH_ESP32) + #if defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3) // V4 can auto-detect PSRAM if (psramFound()) { //DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB"); DEBUG_PRINT(F("Free PSRAM : ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB"); @@ -376,6 +377,7 @@ void WLED::loop() //DEBUG_PRINTLN(F("No PSRAM")); } #endif + #endif DEBUG_PRINT(F("Wifi state: ")); DEBUG_PRINTLN(WiFi.status()); if (WiFi.status() != lastWifiState) { @@ -666,7 +668,7 @@ void WLED::setup() // C3: reserve GPIO 12-17 for PSRAM (may fail due to isPinOk() but that will also prevent other allocation) //managed_pin_type pins[] = { {12, true}, {13, true}, {14, true}, {15, true}, {16, true}, {17, true} }; //pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM); - #else + #elif defined(CONFIG_IDF_TARGET_ESP32) // GPIO16/GPIO17 reserved for SPI RAM if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) { // ESP32-D0WDR2-V3 keeps gpio17 available @@ -678,7 +680,7 @@ void WLED::setup() } #endif - #if defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON)) // WLEDMM + #if (defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3)) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON)) // WLEDMM if (psramFound()) { DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB"); DEBUG_PRINT(F("Free PSRAM : ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB"); @@ -690,11 +692,19 @@ void WLED::setup() #if defined(ARDUINO_ARCH_ESP32) if ((strncmp("ESP32-PICO", ESP.getChipModel(), 10) == 0) || (strncmp("ESP32-U4WDH", ESP.getChipModel(), 11) == 0)) { // WLEDMM detect pico board and esp32-mini1 board at runtime - // special handling for PICO-D4: gpio16+17 are in use for onboard SPI FLASH (not PSRAM) + // PICO-D4: gpio16+17 are in use for onboard SPI FLASH (not PSRAM) + // U4WDH / PICO-D2 / PICO-V3 / PICO-V3-02 : GPIO 16 and 17 are either used for PSRAM, or not connected managed_pin_type pins[] = { {16, true}, {17, true} }; pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM); } -#endif + #if !defined(BOARD_HAS_PSRAM) + if (strncmp_P(PSTR("ESP32-D0WDR2-V3"), ESP.getChipModel(), 15) == 0) { + // runtime detect ESP32-D0WDR2-V3: needs gpio16 for PSRAM, but keeps gpio17 available + managed_pin_type pins[] = { {16, true} }; + pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM); + } + #endif + #endif //DEBUG_PRINT(F("LEDs inited. heap usage ~")); //DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap()); @@ -706,7 +716,7 @@ void WLED::setup() pinManager.allocatePin(2, true, PinOwner::DMX); #endif -#if defined(ALL_JSON_TO_PSRAM) && defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM_JSON) || defined(WLED_USE_PSRAM)) +#if defined(ALL_JSON_TO_PSRAM) && (defined(BOARD_HAS_PSRAM) || (ESP_IDF_VERSION_MAJOR > 3)) && (defined(WLED_USE_PSRAM_JSON) || defined(WLED_USE_PSRAM)) if (psramFound()) { DEBUG_PRINT(F("\nfree heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); USER_PRINTLN(F("JSON garbage collection (initial)."));