File tree Expand file tree Collapse file tree 2 files changed +35
-6
lines changed
common-hal/microcontroller Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -29,12 +29,29 @@ void common_hal_mcu_delay_us(uint32_t delay) {
2929 mp_hal_delay_us (delay );
3030}
3131
32+ volatile uint32_t nesting_count = 0 ;
3233#ifdef PICO_RP2040
33- #include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h"
34+ void common_hal_mcu_disable_interrupts (void ) {
35+ // We don't use save_and_disable_interrupts() from the sdk because we don't want to worry about PRIMASK.
36+ // This is what we do on the SAMD21 via CMSIS.
37+ asm volatile ("cpsid i" : : : "memory" );
38+ __dmb ();
39+ nesting_count ++ ;
40+ }
41+
42+ void common_hal_mcu_enable_interrupts (void ) {
43+ if (nesting_count == 0 ) {
44+ // reset_into_safe_mode(SAFE_MODE_INTERRUPT_ERROR);
45+ }
46+ nesting_count -- ;
47+ if (nesting_count > 0 ) {
48+ return ;
49+ }
50+ __dmb ();
51+ asm volatile ("cpsie i" : : : "memory" );
52+ }
3453#else
3554#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h"
36- #endif
37- volatile uint32_t nesting_count = 0 ;
3855#define PICO_ELEVATED_IRQ_PRIORITY (0x60) // between PICO_DEFAULT and PIOCO_HIGHEST_IRQ_PRIORITY
3956static uint32_t oldBasePri = 0 ; // 0 (default) masks nothing, other values mask equal-or-larger priority values
4057void common_hal_mcu_disable_interrupts (void ) {
@@ -64,6 +81,7 @@ void common_hal_mcu_enable_interrupts(void) {
6481 }
6582 restore_interrupts (my_interrupts );
6683}
84+ #endif
6785
6886static bool next_reset_to_bootloader = false;
6987
Original file line number Diff line number Diff line change 5252#include "pico/bootrom.h"
5353#include "hardware/watchdog.h"
5454
55- #ifdef PICO_RP2040
56- #include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h"
57- #else
55+ #ifdef PICO_RP2350
5856#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h"
5957#endif
6058
@@ -503,6 +501,18 @@ void port_interrupt_after_ticks(uint32_t ticks) {
503501}
504502
505503void port_idle_until_interrupt (void ) {
504+ #ifdef PICO_RP2040
505+ common_hal_mcu_disable_interrupts ();
506+ #if CIRCUITPY_USB_HOST
507+ if (!background_callback_pending () && !tud_task_event_ready () && !tuh_task_event_ready () && !_woken_up ) {
508+ #else
509+ if (!background_callback_pending () && !tud_task_event_ready () && !_woken_up ) {
510+ #endif
511+ __DSB ();
512+ __WFI ();
513+ }
514+ common_hal_mcu_enable_interrupts ();
515+ #else
506516 // because we use interrupt priority, don't use
507517 // common_hal_mcu_disable_interrupts (because an interrupt masked by
508518 // BASEPRI will not occur)
@@ -526,6 +536,7 @@ void port_idle_until_interrupt(void) {
526536 __isb ();
527537
528538 restore_interrupts (state );
539+ #endif
529540}
530541
531542/**
You can’t perform that action at this time.
0 commit comments