Skip to content

Commit 7d7d29d

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt: Fix mp_hal_quiet_timing_enter()/exit() so timer still runs.
The initial code disabled IRQs, which caused the us-ticks timer to stop. The change here changes the priotity level, such that the timer still runs.
1 parent 7cc9b25 commit 7d7d29d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

ports/mimxrt/mpconfigport.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ __attribute__((always_inline)) static inline uint32_t disable_irq(void) {
189189
return state;
190190
}
191191

192+
static inline uint32_t raise_irq_pri(uint32_t pri) {
193+
uint32_t basepri = __get_BASEPRI();
194+
// If non-zero, the processor does not process any exception with a
195+
// priority value greater than or equal to BASEPRI.
196+
// When writing to BASEPRI_MAX the write goes to BASEPRI only if either:
197+
// - Rn is non-zero and the current BASEPRI value is 0
198+
// - Rn is non-zero and less than the current BASEPRI value
199+
pri <<= (8 - __NVIC_PRIO_BITS);
200+
__ASM volatile ("msr basepri_max, %0" : : "r" (pri) : "memory");
201+
return basepri;
202+
}
203+
204+
// "basepri" should be the value returned from raise_irq_pri
205+
static inline void restore_irq_pri(uint32_t basepri) {
206+
__set_BASEPRI(basepri);
207+
}
208+
192209
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
193210
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)
194211

ports/mimxrt/mphalport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ extern ringbuf_t stdin_ringbuf;
5353
#define mp_hal_pin_od_low(p) mp_hal_pin_low(p)
5454
#define mp_hal_pin_od_high(p) mp_hal_pin_high(p)
5555

56-
#define mp_hal_quiet_timing_enter() MICROPY_BEGIN_ATOMIC_SECTION()
57-
#define mp_hal_quiet_timing_exit(irq_state) MICROPY_END_ATOMIC_SECTION(irq_state)
56+
#define mp_hal_quiet_timing_enter() raise_irq_pri(1)
57+
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
5858

5959
void mp_hal_set_interrupt_char(int c);
6060

0 commit comments

Comments
 (0)