Skip to content

Commit a0e3918

Browse files
committed
rp2040: restore the old definitions of these functions
According to https://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Processor/Programmers-model/Core-registers the Cortex M0 lacks the BASEPRI register used to mask low-priority interrupts. So, we have to use the original version.
1 parent 5fdaab1 commit a0e3918

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

ports/raspberrypi/common-hal/microcontroller/__init__.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff 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
3956
static uint32_t oldBasePri = 0; // 0 (default) masks nothing, other values mask equal-or-larger priority values
4057
void 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

6886
static bool next_reset_to_bootloader = false;
6987

ports/raspberrypi/supervisor/port.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@
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

505503
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
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
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy