From 358a0cd464c0798c7d6a1178b5a633f5d90ad515 Mon Sep 17 00:00:00 2001 From: Adam Newell Date: Mon, 9 Jun 2025 17:15:24 -0400 Subject: Fix MPU region enablement in stack guard installation Updated the MPU region enablement logic in the `install_stack_guard` function to correctly set the region limit by using the stack bottom address plus 256 minus one, ensuring proper memory protection configuration. See Table 235. MPU_RLAR Register in RP2350 documentation See Section 4.5 MPU_RLAR in armv8m MPU documentation --- embassy-rp/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-rp') diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index f3c5a35bb..94b20bce3 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -567,7 +567,7 @@ unsafe fn install_stack_guard(stack_bottom: *mut usize) -> Result<(), ()> { unsafe { core.MPU.ctrl.write(5); // enable mpu with background default map core.MPU.rbar.write(stack_bottom as u32 & !0xff); // set address - core.MPU.rlar.write(1); // enable region + core.MPU.rlar.write(((stack_bottom as usize + 255) as u32) | 1); } Ok(()) } -- cgit