From 58ff28b505cb311e4ffb024a81d81e1b094976bc Mon Sep 17 00:00:00 2001 From: Yuuki NAGAO Date: Mon, 22 Sep 2025 20:24:18 +0900 Subject: [PATCH] stm32/rtc: Fix passing invalid argument to RTC callback. NameError occurred when trying to access the argument of RTC.wakeup() callback because the callback argument is not initialized. To fix this issue, this commit passes EXTI_RTC_WAKEUP to callback argument. This is equivalent behavior with ExtInt callback. Signed-off-by: Yuuki NAGAO --- ports/stm32/extint.c | 2 +- ports/stm32/extint.h | 1 + ports/stm32/rtc.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/stm32/extint.c b/ports/stm32/extint.c index df0ed6e23e..b1e5c8a8f2 100644 --- a/ports/stm32/extint.c +++ b/ports/stm32/extint.c @@ -127,7 +127,7 @@ static uint8_t pyb_extint_mode[EXTI_NUM_VECTORS]; static bool pyb_extint_hard_irq[EXTI_NUM_VECTORS]; // The callback arg is a small-int or a ROM Pin object, so no need to scan by GC -static mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS]; +mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS]; #if !defined(ETH) #define ETH_WKUP_IRQn 62 // Some MCUs don't have ETH, but we want a value to put in our table diff --git a/ports/stm32/extint.h b/ports/stm32/extint.h index 801dcf62b5..cdebf6eb86 100644 --- a/ports/stm32/extint.h +++ b/ports/stm32/extint.h @@ -64,6 +64,7 @@ #endif #define EXTI_NUM_VECTORS (PYB_EXTI_NUM_VECTORS) +extern mp_obj_t pyb_extint_callback_arg[]; void extint_init0(void); diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c index fa28fda6a8..fb106e179b 100644 --- a/ports/stm32/rtc.c +++ b/ports/stm32/rtc.c @@ -771,6 +771,7 @@ mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args) { // set the callback MP_STATE_PORT(pyb_extint_callback)[EXTI_RTC_WAKEUP] = callback; + pyb_extint_callback_arg[EXTI_RTC_WAKEUP] = MP_OBJ_NEW_SMALL_INT(EXTI_RTC_WAKEUP); // disable register write protection RTC->WPR = 0xca;