Skip to content

Conversation

@yn386
Copy link
Contributor

@yn386 yn386 commented Sep 22, 2025

Summary

The folling code does not work with NUCLEO_F401RE.

from pyb import RTC

def cb(v):
    print(v)

rtc=RTC()
rtc.wakeup(1000, cb)

NameError exception occurred with following message.
The argument of callback should be accessed without exception.

Traceback (most recent call last):
  File "<stdin>", line 2, in cb
NameError: local variable referenced before assignment

To fix this issue, this PR passes EXTI_RTC_WAKEUP to callback argument.
This is equivalent behavior with ExtInt callback when ExtInt is mapped to RTC interrupt by passing an integer value.

Testing

Tested with NUCLEO_F401RE.
The argument of callback can be read (22 with NUCLEO_F401RE).

@github-actions
Copy link

github-actions bot commented Sep 22, 2025

Code size report:

  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +8 +0.002% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, this looks correct.

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 <wf.yn386@gmail.com>
@dpgeorge dpgeorge force-pushed the fix-rtc-wake-callback-arg branch from 9be4de5 to 58ff28b Compare September 30, 2025 23:38
@dpgeorge dpgeorge merged commit 58ff28b into micropython:master Sep 30, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants