diff options
| author | Matteo Meluzzi <[email protected]> | 2025-10-02 10:53:31 +0200 |
|---|---|---|
| committer | Matteo Meluzzi <[email protected]> | 2025-10-02 10:53:31 +0200 |
| commit | 828a8df18d04877df1f55f04354980b28ff2f2f8 (patch) | |
| tree | c4fa405f5eba7a14b6d435d6cc746c9e0dc52632 /embassy-rp/src | |
| parent | 176649e71ad442ca9856af6c11989b0b2f228c4b (diff) | |
| parent | 194a721d0eab929a2af0a2a4e45ca8e70e0d3f0a (diff) | |
Merge branch 'main' into 17-add-support-for-boot-protocol
Diffstat (limited to 'embassy-rp/src')
| -rw-r--r-- | embassy-rp/src/lib.rs | 14 | ||||
| -rw-r--r-- | embassy-rp/src/rom_data/rp235x.rs | 32 |
2 files changed, 35 insertions, 11 deletions
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 6fb680b34..d03ba1fef 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -565,18 +565,10 @@ unsafe fn install_stack_guard(stack_bottom: *mut usize) -> Result<(), ()> { | |||
| 565 | #[cfg(all(feature = "_rp235x", not(feature = "_test")))] | 565 | #[cfg(all(feature = "_rp235x", not(feature = "_test")))] |
| 566 | #[inline(always)] | 566 | #[inline(always)] |
| 567 | unsafe fn install_stack_guard(stack_bottom: *mut usize) -> Result<(), ()> { | 567 | unsafe fn install_stack_guard(stack_bottom: *mut usize) -> Result<(), ()> { |
| 568 | let core = unsafe { cortex_m::Peripherals::steal() }; | 568 | // The RP2350 arm cores are cortex-m33 and can use the MSPLIM register to guard the end of stack. |
| 569 | // We'll need to do something else for the riscv cores. | ||
| 570 | cortex_m::register::msplim::write(stack_bottom.addr() as u32); | ||
| 569 | 571 | ||
| 570 | // Fail if MPU is already configured | ||
| 571 | if core.MPU.ctrl.read() != 0 { | ||
| 572 | return Err(()); | ||
| 573 | } | ||
| 574 | |||
| 575 | unsafe { | ||
| 576 | core.MPU.ctrl.write(5); // enable mpu with background default map | ||
| 577 | core.MPU.rbar.write(stack_bottom as u32 & !0xff); // set address | ||
| 578 | core.MPU.rlar.write(((stack_bottom as usize + 255) as u32) | 1); | ||
| 579 | } | ||
| 580 | Ok(()) | 572 | Ok(()) |
| 581 | } | 573 | } |
| 582 | 574 | ||
diff --git a/embassy-rp/src/rom_data/rp235x.rs b/embassy-rp/src/rom_data/rp235x.rs index b16fee8f7..c0a1ed6fb 100644 --- a/embassy-rp/src/rom_data/rp235x.rs +++ b/embassy-rp/src/rom_data/rp235x.rs | |||
| @@ -750,3 +750,35 @@ pub fn is_secure_mode() -> bool { | |||
| 750 | pub fn is_secure_mode() -> bool { | 750 | pub fn is_secure_mode() -> bool { |
| 751 | false | 751 | false |
| 752 | } | 752 | } |
| 753 | |||
| 754 | // These and the reset_to_usb_boot function are found from https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_bootrom/bootrom.c#L35-L51 | ||
| 755 | // The following has just been translated to rust from the original c++ | ||
| 756 | const BOOTSEL_FLAG_GPIO_PIN_SPECIFIED: u32 = 0x20; | ||
| 757 | const REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL: u32 = 0x2; | ||
| 758 | const REBOOT2_FLAG_NO_RETURN_ON_SUCCESS: u32 = 0x100; | ||
| 759 | |||
| 760 | /// Resets the RP235x and uses the watchdog facility to re-start in BOOTSEL mode: | ||
| 761 | /// * gpio_activity_pin_mask is provided to enable an 'activity light' via GPIO attached LED | ||
| 762 | /// for the USB Mass Storage Device: | ||
| 763 | /// * 0 No pins are used as per cold boot. | ||
| 764 | /// * Otherwise a single bit set indicating which GPIO pin should be set to output and | ||
| 765 | /// raised whenever there is mass storage activity from the host. | ||
| 766 | /// * disable_interface_mask may be used to control the exposed USB interfaces: | ||
| 767 | /// * 0 To enable both interfaces (as per cold boot). | ||
| 768 | /// * 1 To disable the USB Mass Storage Interface. | ||
| 769 | /// * 2 to Disable the USB PICOBOOT Interface. | ||
| 770 | pub fn reset_to_usb_boot(mut usb_activity_gpio_pin_mask: u32, disable_interface_mask: u32) { | ||
| 771 | let mut flags = disable_interface_mask; | ||
| 772 | |||
| 773 | if usb_activity_gpio_pin_mask != 0 { | ||
| 774 | flags = flags | BOOTSEL_FLAG_GPIO_PIN_SPECIFIED; | ||
| 775 | usb_activity_gpio_pin_mask = usb_activity_gpio_pin_mask.trailing_zeros() | ||
| 776 | } | ||
| 777 | |||
| 778 | reboot( | ||
| 779 | REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL | REBOOT2_FLAG_NO_RETURN_ON_SUCCESS, | ||
| 780 | 10, | ||
| 781 | flags, | ||
| 782 | usb_activity_gpio_pin_mask, | ||
| 783 | ); | ||
| 784 | } | ||
