Skip to content

Commit 2032aa2

Browse files
committed
ports/stm32: Use PRIMASK for complete interrupt masking in Zephyr threading.
Replace arch_irq_lock/unlock with direct PRIMASK manipulation in IRQ management functions. PRIMASK masks ALL interrupts including priority 0, ensuring critical sections are not interrupted by Zephyr's scheduler or any IRQs. This provides more complete protection than BASEPRI which only masks interrupts at or above a specific priority threshold. Signed-off-by: Andrew Leech <andrew@alelec.net> Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent bea7a0c commit 2032aa2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ports/stm32/irq.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@ extern uint32_t irq_stats[IRQ_STATS_MAX];
6060
// value from disable_irq back to enable_irq.
6161

6262
#if MICROPY_ZEPHYR_THREADING
63-
// Zephyr IRQ management
64-
#include <zephyr/arch/cpu.h>
63+
// Zephyr IRQ management using PRIMASK for complete interrupt masking
64+
// PRIMASK masks ALL interrupts (including NMI-like priority 0), ensuring
65+
// critical sections are not interrupted by Zephyr's scheduler or any IRQs.
66+
// This is more complete than BASEPRI which only masks priority >= threshold.
6567

6668
static inline uint32_t query_irq(void) {
67-
// For Zephyr, assume IRQs are enabled when not in atomic section
68-
// This is a simplification - Zephyr manages IRQs via arch_irq_lock/unlock
69-
return IRQ_STATE_ENABLED;
69+
return __get_PRIMASK();
7070
}
7171

7272
static inline void enable_irq(mp_uint_t state) {
73-
arch_irq_unlock(state);
73+
__set_PRIMASK(state);
7474
}
7575

7676
static inline mp_uint_t disable_irq(void) {
77-
return arch_irq_lock();
77+
mp_uint_t state = __get_PRIMASK();
78+
__disable_irq();
79+
return state;
7880
}
7981

8082
#else

0 commit comments

Comments
 (0)