diff options
| author | Damien George | 2018-07-31 17:24:10 +1000 |
|---|---|---|
| committer | Damien George | 2018-07-31 17:24:10 +1000 |
| commit | 9dfbb6cc169ab95f07876d97824fd2c3dae229a1 (patch) | |
| tree | d3a7700c19a46ebc4c8be1fa9c999ffb301c0306 /ports | |
| parent | 1e3a7f561fffc2d06436b1ef09cb8b44262bb2bc (diff) | |
stm32/rtc: Get rtc.wakeup working on F0 MCUs.
The problem was that the EXTI line for the RTC wakeup event is line 20 on
the F0, so the interrupt was not firing.
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/stm32/extint.h | 7 | ||||
| -rw-r--r-- | ports/stm32/rtc.c | 39 | ||||
| -rw-r--r-- | ports/stm32/stm32_it.c | 4 |
3 files changed, 29 insertions, 21 deletions
diff --git a/ports/stm32/extint.h b/ports/stm32/extint.h index c4a4ae6bb..2238ff4f8 100644 --- a/ports/stm32/extint.h +++ b/ports/stm32/extint.h @@ -26,6 +26,8 @@ #ifndef MICROPY_INCLUDED_STM32_EXTINT_H #define MICROPY_INCLUDED_STM32_EXTINT_H +#include "py/mphal.h" + // Vectors 0-15 are for regular pins // Vectors 16-22 are for internal sources. // @@ -36,8 +38,13 @@ #define EXTI_USB_OTG_FS_WAKEUP (18) #define EXTI_ETH_WAKEUP (19) #define EXTI_USB_OTG_HS_WAKEUP (20) +#if defined(STM32F0) +#define EXTI_RTC_TIMESTAMP (19) +#define EXTI_RTC_WAKEUP (20) +#else #define EXTI_RTC_TIMESTAMP (21) #define EXTI_RTC_WAKEUP (22) +#endif #if defined(STM32F7) #define EXTI_LPTIM1_ASYNC_EVENT (23) #endif diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c index dfc4591da..1999dfb38 100644 --- a/ports/stm32/rtc.c +++ b/ports/stm32/rtc.c @@ -27,6 +27,7 @@ #include <stdio.h> #include "py/runtime.h" +#include "extint.h" #include "rtc.h" #include "irq.h" @@ -612,17 +613,17 @@ mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args) { } // set the callback - MP_STATE_PORT(pyb_extint_callback)[22] = callback; + MP_STATE_PORT(pyb_extint_callback)[EXTI_RTC_WAKEUP] = callback; // disable register write protection RTC->WPR = 0xca; RTC->WPR = 0x53; // clear WUTE - RTC->CR &= ~(1 << 10); + RTC->CR &= ~RTC_CR_WUTE; // wait until WUTWF is set - while (!(RTC->ISR & (1 << 2))) { + while (!(RTC->ISR & RTC_ISR_WUTWF)) { } if (enable) { @@ -637,26 +638,26 @@ mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args) { // enable register write protection RTC->WPR = 0xff; - // enable external interrupts on line 22 + // enable external interrupts on line EXTI_RTC_WAKEUP #if defined(STM32L4) - EXTI->IMR1 |= 1 << 22; - EXTI->RTSR1 |= 1 << 22; + EXTI->IMR1 |= 1 << EXTI_RTC_WAKEUP; + EXTI->RTSR1 |= 1 << EXTI_RTC_WAKEUP; #elif defined(STM32H7) - EXTI_D1->IMR1 |= 1 << 22; - EXTI->RTSR1 |= 1 << 22; + EXTI_D1->IMR1 |= 1 << EXTI_RTC_WAKEUP; + EXTI->RTSR1 |= 1 << EXTI_RTC_WAKEUP; #else - EXTI->IMR |= 1 << 22; - EXTI->RTSR |= 1 << 22; + EXTI->IMR |= 1 << EXTI_RTC_WAKEUP; + EXTI->RTSR |= 1 << EXTI_RTC_WAKEUP; #endif // clear interrupt flags - RTC->ISR &= ~(1 << 10); + RTC->ISR &= ~RTC_ISR_WUTF; #if defined(STM32L4) - EXTI->PR1 = 1 << 22; + EXTI->PR1 = 1 << EXTI_RTC_WAKEUP; #elif defined(STM32H7) - EXTI_D1->PR1 = 1 << 22; + EXTI_D1->PR1 = 1 << EXTI_RTC_WAKEUP; #else - EXTI->PR = 1 << 22; + EXTI->PR = 1 << EXTI_RTC_WAKEUP; #endif NVIC_SetPriority(RTC_WKUP_IRQn, IRQ_PRI_RTC_WKUP); @@ -665,18 +666,18 @@ mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args) { //printf("wut=%d wucksel=%d\n", wut, wucksel); } else { // clear WUTIE to disable interrupts - RTC->CR &= ~(1 << 14); + RTC->CR &= ~RTC_CR_WUTIE; // enable register write protection RTC->WPR = 0xff; - // disable external interrupts on line 22 + // disable external interrupts on line EXTI_RTC_WAKEUP #if defined(STM32L4) - EXTI->IMR1 &= ~(1 << 22); + EXTI->IMR1 &= ~(1 << EXTI_RTC_WAKEUP); #elif defined(STM32H7) - EXTI_D1->IMR1 |= 1 << 22; + EXTI_D1->IMR1 |= 1 << EXTI_RTC_WAKEUP; #else - EXTI->IMR &= ~(1 << 22); + EXTI->IMR &= ~(1 << EXTI_RTC_WAKEUP); #endif } diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index a2a8d0f2e..026082eb9 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -574,7 +574,7 @@ void TAMP_STAMP_IRQHandler(void) { void RTC_WKUP_IRQHandler(void) { IRQ_ENTER(RTC_WKUP_IRQn); - RTC->ISR &= ~(1 << 10); // clear wakeup interrupt flag + RTC->ISR &= ~RTC_ISR_WUTF; // clear wakeup interrupt flag Handle_EXTI_Irq(EXTI_RTC_WAKEUP); // clear EXTI flag and execute optional callback IRQ_EXIT(RTC_WKUP_IRQn); } @@ -583,7 +583,7 @@ void RTC_WKUP_IRQHandler(void) { void RTC_IRQHandler(void) { IRQ_ENTER(RTC_IRQn); - RTC->ISR &= ~(1 << 10); // clear wakeup interrupt flag + RTC->ISR &= ~RTC_ISR_WUTF; // clear wakeup interrupt flag Handle_EXTI_Irq(EXTI_RTC_WAKEUP); // clear EXTI flag and execute optional callback IRQ_EXIT(RTC_IRQn); } |
