Warn when using PSRAM on non-PSRAM boards (#2441)

Avoid link errors with a warning message and always-failing calls to
pmalloc/pcalloc.  Addresses #2439
This commit is contained in:
Earle F. Philhower, III 2024-09-10 09:50:51 -07:00 committed by GitHub
parent a9b390296f
commit 20c69bdfbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 5 deletions

View file

@ -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))

View file

@ -253,7 +253,7 @@ public:
}
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 @@ public:
}
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 @@ public:
}
inline size_t getPSRAMSize() {
#if defined(PICO_RP2350)
#if defined(RP2350_PSRAM_CS)
extern size_t __psram_size;
return __psram_size;
#else

View file

@ -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) {

View file

@ -105,4 +105,4 @@ OUTPUT_12MA LITERAL1
ARDUINO_ARCH_RP2040 LITERAL1
PRAM LITERAL1
PSRAM LITERAL1