From 6544bf52fb87fd47c234a8ab3fc26865b124c039 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 7 Apr 2020 17:15:18 -0700 Subject: [PATCH] Enable SNVS interrupt The iMX RT has a separate wake up controller, the GPC, that replaces the NVIC when asleep. It adds the ability to only wake up on certain interrupts. It seems that it requires at least one enabled interrupt in the NVIC to turn on it's wake up circuitry. It doesn't need to be the same interrupt as the wake up signal. For example, the RTC in the SNVS can wake us up if a USB interrupt is enabled. Before then it won't work. So, we enable the SNVS interrupt on start up so it can wake us up. --- ports/mimxrt10xx/supervisor/port.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ports/mimxrt10xx/supervisor/port.c b/ports/mimxrt10xx/supervisor/port.c index 242b0592e1..1a4f9520b8 100644 --- a/ports/mimxrt10xx/supervisor/port.c +++ b/ports/mimxrt10xx/supervisor/port.c @@ -252,6 +252,10 @@ safe_mode_t port_init(void) { rtc_init(); #endif + // Always enable the SNVS interrupt. The GPC won't wake us up unless at least one interrupt is + // enabled. It won't occur very often so it'll be low overhead. + NVIC_EnableIRQ(SNVS_HP_WRAPPER_IRQn); + // Reset everything into a known state before board_init. reset_port(); @@ -365,7 +369,6 @@ void SNVS_HP_WRAPPER_IRQHandler(void) { // Enable 1/1024 second tick. void port_enable_tick(void) { - NVIC_EnableIRQ(SNVS_HP_WRAPPER_IRQn); uint32_t hpcr = SNVS->HPCR; hpcr &= ~SNVS_HPCR_PI_FREQ_MASK; SNVS->HPCR = hpcr | SNVS_HPCR_PI_FREQ(5) | SNVS_HPCR_PI_EN_MASK; @@ -374,7 +377,6 @@ void port_enable_tick(void) { // Disable 1/1024 second tick. void port_disable_tick(void) { SNVS->HPCR &= ~SNVS_HPCR_PI_EN_MASK; - NVIC_DisableIRQ(SNVS_HP_WRAPPER_IRQn); } void port_interrupt_after_ticks(uint32_t ticks) {