From 97797540cbd6e8d60c8c0bb194cd079172523c7a Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 6 Dec 2025 10:16:54 -0800 Subject: [PATCH] Fix rp2040.getFreeStack() on RP2350 Use the linker symbols for stack location instead of hardcoding values which differ RP2040 to RP2350. Fixed #3254 --- cores/rp2040/RP2040Support.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cores/rp2040/RP2040Support.h b/cores/rp2040/RP2040Support.h index 811146565..12640b3af 100644 --- a/cores/rp2040/RP2040Support.h +++ b/cores/rp2040/RP2040Support.h @@ -276,6 +276,8 @@ extern RP2040 rp2040; extern void main1(); extern "C" char __StackLimit; extern "C" char __bss_end__; +extern "C" uint32_t __scratch_x_start__; +extern "C" uint32_t __scratch_y_start__; extern "C" void setup1() __attribute__((weak)); extern "C" void loop1() __attribute__((weak)); extern "C" bool core1_separate_stack; @@ -477,12 +479,12 @@ class RP2040 { */ inline int getFreeStack() { const unsigned int sp = getStackPointer(); - uint32_t ref = 0x20040000; + uint32_t ref = (uint32_t)&__scratch_x_start__; if (setup1 || loop1) { if (core1_separate_stack) { - ref = cpuid() ? (unsigned int)core1_separate_stack_address : 0x20040000; + ref = (uint32_t)(cpuid() ? core1_separate_stack_address : &__scratch_x_start__); } else { - ref = cpuid() ? 0x20040000 : 0x20041000; + ref = (uint32_t)(cpuid() ? &__scratch_x_start__ : &__scratch_y_start__); } } return sp - ref;