From 31d6ee050cfae21706b5fe2ed3c9ff2cb996d2e6 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 10 Sep 2024 09:39:45 -0700 Subject: [PATCH] Warn when using PSRAM on non-PSRAM boards Avoid link errors with a warning message and always-failing calls to pmalloc/pcalloc. Addresses #2439 --- cores/rp2040/Arduino.h | 5 ++++- cores/rp2040/RP2040Support.h | 6 +++--- cores/rp2040/malloc-lock.cpp | 9 +++++++++ keywords.txt | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cores/rp2040/Arduino.h b/cores/rp2040/Arduino.h index 30961a92a..6db94ea7e 100644 --- a/cores/rp2040/Arduino.h +++ b/cores/rp2040/Arduino.h @@ -58,12 +58,15 @@ extern "C" { void interrupts(); void noInterrupts(); +// Only implemented on some RP2350 boards, not the OG Pico 2 #ifdef RP2350_PSRAM_CS void *pmalloc(size_t size); void *pcalloc(size_t count, size_t size); +#else +[[deprecated("This chip does not have PSRAM, pmalloc will always fail")]] void *pmalloc(size_t size); +[[deprecated("This chip does not have PSRAM, pcalloc will always fail")]] void *pcalloc(size_t count, size_t size); #endif - // AVR compatibility macros...naughty and accesses the HW directly #define digitalPinToPort(pin) (0) #define digitalPinToBitMask(pin) (1UL << (pin)) diff --git a/cores/rp2040/RP2040Support.h b/cores/rp2040/RP2040Support.h index 031eaca75..e0dfa760d 100644 --- a/cores/rp2040/RP2040Support.h +++ b/cores/rp2040/RP2040Support.h @@ -253,7 +253,7 @@ class RP2040 { } inline int getUsedPSRAMHeap() { -#if defined(PICO_RP2350) +#if defined(RP2350_PSRAM_CS) extern size_t __psram_total_used(); return __psram_total_used(); #else @@ -262,7 +262,7 @@ class RP2040 { } inline int getTotalPSRAMHeap() { -#if defined(PICO_RP2350) +#if defined(RP2350_PSRAM_CS) extern size_t __psram_total_space(); return __psram_total_space(); #else @@ -290,7 +290,7 @@ class RP2040 { } inline size_t getPSRAMSize() { -#if defined(PICO_RP2350) +#if defined(RP2350_PSRAM_CS) extern size_t __psram_size; return __psram_size; #else diff --git a/cores/rp2040/malloc-lock.cpp b/cores/rp2040/malloc-lock.cpp index f26838a96..bf2e9e7fd 100644 --- a/cores/rp2040/malloc-lock.cpp +++ b/cores/rp2040/malloc-lock.cpp @@ -73,6 +73,15 @@ extern "C" void *pcalloc(size_t count, size_t size) { interrupts(); return rc; } +#else +// No PSRAM, always fail +extern "C" void *pmalloc(size_t size) { + return nullptr; +} + +extern "C" void *pcalloc(size_t count, size_t size) { + return nullptr; +} #endif extern "C" void *__wrap_realloc(void *mem, size_t size) { diff --git a/keywords.txt b/keywords.txt index 7a6c8de20..f5366ccaa 100644 --- a/keywords.txt +++ b/keywords.txt @@ -105,4 +105,4 @@ OUTPUT_12MA LITERAL1 ARDUINO_ARCH_RP2040 LITERAL1 -PRAM LITERAL1 +PSRAM LITERAL1