PSRAM: you can have it, and eat it or not eat it
*This patch allows to compile with BOARD_HAS_PSRAM, but not set WLED_USE_PSRAM - reserved pins will be protected, and PSRAM usage will be shown in info. * if you add `-D WLED_USE_PSRAM_JSON` then PSRAM will be used for some JSON buffers, but not for LEDs and Segments.
This commit is contained in:
@@ -157,7 +157,7 @@ bool Segment::allocateData(size_t len) {
|
|||||||
deallocateData();
|
deallocateData();
|
||||||
if (Segment::getUsedSegmentData() + len > MAX_SEGMENT_DATA) return false; //not enough memory
|
if (Segment::getUsedSegmentData() + len > MAX_SEGMENT_DATA) return false; //not enough memory
|
||||||
// if possible use SPI RAM on ESP32
|
// if possible use SPI RAM on ESP32
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
||||||
if (psramFound())
|
if (psramFound())
|
||||||
data = (byte*) ps_malloc(len);
|
data = (byte*) ps_malloc(len);
|
||||||
else
|
else
|
||||||
@@ -204,7 +204,7 @@ void Segment::setUpLeds() {
|
|||||||
leds = &Segment::_globalLeds[start];
|
leds = &Segment::_globalLeds[start];
|
||||||
#endif
|
#endif
|
||||||
else if (!leds) {
|
else if (!leds) {
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
||||||
if (psramFound())
|
if (psramFound())
|
||||||
leds = (CRGB*)ps_malloc(sizeof(CRGB)*length());
|
leds = (CRGB*)ps_malloc(sizeof(CRGB)*length());
|
||||||
else
|
else
|
||||||
@@ -1443,7 +1443,7 @@ void WS2812FX::finalizeInit(void)
|
|||||||
}
|
}
|
||||||
if (useLedsArray) {
|
if (useLedsArray) {
|
||||||
size_t arrSize = sizeof(CRGB) * getLengthTotal();
|
size_t arrSize = sizeof(CRGB) * getLengthTotal();
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
||||||
if (psramFound())
|
if (psramFound())
|
||||||
Segment::_globalLeds = (CRGB*) ps_malloc(arrSize);
|
Segment::_globalLeds = (CRGB*) ps_malloc(arrSize);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -422,7 +422,7 @@
|
|||||||
|
|
||||||
//this is merely a default now and can be changed at runtime
|
//this is merely a default now and can be changed at runtime
|
||||||
#ifndef LEDPIN
|
#ifndef LEDPIN
|
||||||
#if defined(ESP8266) || (defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
#if defined(ESP8266) || (defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)) || defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
#define LEDPIN 2 // GPIO2 (D4) on Wemod D1 mini compatible boards
|
#define LEDPIN 2 // GPIO2 (D4) on Wemod D1 mini compatible boards
|
||||||
#else
|
#else
|
||||||
#define LEDPIN 16 // aligns with GPIO2 (D4) on Wemos D1 mini32 compatible boards
|
#define LEDPIN 16 // aligns with GPIO2 (D4) on Wemos D1 mini32 compatible boards
|
||||||
|
|||||||
@@ -914,7 +914,7 @@ void serializeInfo(JsonObject root)
|
|||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
root[F("minfreeheap")] = ESP.getMinFreeHeap();
|
root[F("minfreeheap")] = ESP.getMinFreeHeap();
|
||||||
#endif
|
#endif
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) && defined(BOARD_HAS_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
|
||||||
if (psramFound()) {
|
if (psramFound()) {
|
||||||
root[F("tpram")] = ESP.getPsramSize(); //WLEDMM
|
root[F("tpram")] = ESP.getPsramSize(); //WLEDMM
|
||||||
root[F("psram")] = ESP.getFreePsram();
|
root[F("psram")] = ESP.getFreePsram();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ static void doSaveState() {
|
|||||||
size_t len = measureJson(*fileDoc) + 1;
|
size_t len = measureJson(*fileDoc) + 1;
|
||||||
DEBUG_PRINTLN(len);
|
DEBUG_PRINTLN(len);
|
||||||
// if possible use SPI RAM on ESP32
|
// if possible use SPI RAM on ESP32
|
||||||
#ifdef WLED_USE_PSRAM
|
#if defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON))
|
||||||
if (psramFound())
|
if (psramFound())
|
||||||
tmpRAMbuffer = (char*) ps_malloc(len);
|
tmpRAMbuffer = (char*) ps_malloc(len);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ void WLED::loop()
|
|||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
DEBUG_PRINTF("%s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM
|
DEBUG_PRINTF("%s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM
|
||||||
#endif
|
#endif
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
|
||||||
if (psramFound()) {
|
if (psramFound()) {
|
||||||
//DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB");
|
//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");
|
DEBUG_PRINT(F("Free PSRAM: ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB");
|
||||||
@@ -468,7 +468,8 @@ void WLED::setup()
|
|||||||
DEBUG_PRINTF("%s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM
|
DEBUG_PRINTF("%s min free stack %d\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL)); //WLEDMM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
|
||||||
|
psramInit();
|
||||||
if (psramFound()) {
|
if (psramFound()) {
|
||||||
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
// GPIO16/GPIO17 reserved for SPI RAM
|
// GPIO16/GPIO17 reserved for SPI RAM
|
||||||
@@ -485,7 +486,7 @@ void WLED::setup()
|
|||||||
DEBUG_PRINTLN(F("No PSRAM found."));
|
DEBUG_PRINTLN(F("No PSRAM found."));
|
||||||
#endif
|
#endif
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && !defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && !defined(WLED_USE_PSRAM)
|
||||||
DEBUG_PRINTLN(F("PSRAM not used."));
|
DEBUG_PRINTLN(F("PSRAM not used for LEDs."));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
|
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
|
||||||
|
|||||||
@@ -146,7 +146,7 @@
|
|||||||
// The following is a construct to enable code to compile without it.
|
// The following is a construct to enable code to compile without it.
|
||||||
// There is a code thet will still not use PSRAM though:
|
// There is a code thet will still not use PSRAM though:
|
||||||
// AsyncJsonResponse is a derived class that implements DynamicJsonDocument (AsyncJson-v6.h)
|
// AsyncJsonResponse is a derived class that implements DynamicJsonDocument (AsyncJson-v6.h)
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON))
|
||||||
struct PSRAM_Allocator {
|
struct PSRAM_Allocator {
|
||||||
void* allocate(size_t size) {
|
void* allocate(size_t size) {
|
||||||
if (psramFound()) return ps_malloc(size); // use PSRAM if it exists
|
if (psramFound()) return ps_malloc(size); // use PSRAM if it exists
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ void appendGPIOinfo() {
|
|||||||
|
|
||||||
//Note: Using pin 3 (RX) disables Adalight / Serial JSON
|
//Note: Using pin 3 (RX) disables Adalight / Serial JSON
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM)
|
||||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
if (psramFound()) oappend(SET_F(",16,17")); // GPIO16 & GPIO17 reserved for SPI RAM on ESP32 (not on S2, S3 or C3)
|
if (psramFound()) oappend(SET_F(",16,17")); // GPIO16 & GPIO17 reserved for SPI RAM on ESP32 (not on S2, S3 or C3)
|
||||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
|
|||||||
Reference in New Issue
Block a user