File tree 2 files changed +35
-6
lines changed
common-hal/microcontroller 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) {
29
29
mp_hal_delay_us (delay );
30
30
}
31
31
32
+ volatile uint32_t nesting_count = 0 ;
32
33
#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
+ }
34
53
#else
35
54
#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h"
36
- #endif
37
- volatile uint32_t nesting_count = 0 ;
38
55
#define PICO_ELEVATED_IRQ_PRIORITY (0x60) // between PICO_DEFAULT and PIOCO_HIGHEST_IRQ_PRIORITY
39
56
static uint32_t oldBasePri = 0 ; // 0 (default) masks nothing, other values mask equal-or-larger priority values
40
57
void common_hal_mcu_disable_interrupts (void ) {
@@ -64,6 +81,7 @@ void common_hal_mcu_enable_interrupts(void) {
64
81
}
65
82
restore_interrupts (my_interrupts );
66
83
}
84
+ #endif
67
85
68
86
static bool next_reset_to_bootloader = false;
69
87
Original file line number Diff line number Diff line change 52
52
#include "pico/bootrom.h"
53
53
#include "hardware/watchdog.h"
54
54
55
- #ifdef PICO_RP2040
56
- #include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include/RP2040.h"
57
- #else
55
+ #ifdef PICO_RP2350
58
56
#include "src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include/RP2350.h"
59
57
#endif
60
58
@@ -503,6 +501,18 @@ void port_interrupt_after_ticks(uint32_t ticks) {
503
501
}
504
502
505
503
void 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
506
516
// because we use interrupt priority, don't use
507
517
// common_hal_mcu_disable_interrupts (because an interrupt masked by
508
518
// BASEPRI will not occur)
@@ -526,6 +536,7 @@ void port_idle_until_interrupt(void) {
526
536
__isb ();
527
537
528
538
restore_interrupts (state );
539
+ #endif
529
540
}
530
541
531
542
/**
You can’t perform that action at this time.
0 commit comments