Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RP2: machine.RTC().datetime() does not advance during lightsleep #16519

Open
@madozu

Description

@madozu

Port, board and/or hardware

Raspberry Pi Pico W and Raspberry Pi Pico 2 W

MicroPython version

All versions since v1.24.0 (including latest v1.25.0-preview.172.g5d12df51f)

Reproduction

  1. Copy code below to Pico and name it "main.py"
  2. Reset the Pico and allow the code to complete (approx 5 seconds). No repl needed as the code writes a log file to the flash storage
  3. Connect the Pico to the USB port and inspect the file "local.log" on the Pico

Code used to test:

import machine, os, timeSLEEP_MS = const(2000)def write_log(s: str) -> None:    dt = machine.RTC().datetime()    log_text = "[RTC={6:02d}:{7:02d}:{8:02d} ticks={0:d}]  {1:s}".format(time.ticks_ms(), s, *dt)    with open("local.log", "a") as file:        file.write(log_text + "\n")def safe_sleep(ms: int) -> int:    begin = time.ticks_ms()    wake = -1    sleep = ms    while sleep > 0:        machine.lightsleep(sleep)        wake += 1        sleep = ms - time.ticks_diff(time.ticks_ms(), begin)    return wakewrite_log(f"Machine = '{os.uname()[4]}'")write_log(f"Version = '{os.uname()[3]}'")time.sleep_ms(SLEEP_MS)write_log(f"After time.sleep_ms({SLEEP_MS})")wakeups = safe_sleep(SLEEP_MS)write_log(f"After safe_sleep({SLEEP_MS}) with {wakeups} early wakeups")

Expected behaviour

The real time clock should advance by 2 seconds after running 'machine.lightsleep(2000)' like it was on micropython versions up to and including 1.23.0. Example output from1.23.0:

[RTC=00:00:01 ticks=49]  Machine = 'Raspberry Pi Pico W with RP2040'[RTC=00:00:01 ticks=54]  Version = 'v1.23.0 on 2024-06-02 (GNU 13.2.0 MinSizeRel)'[RTC=00:00:03 ticks=2058]  After time.sleep_ms(2000)[RTC=00:00:05 ticks=4065]  After safe_sleep(2000) with 0 early wakeups

Observed behaviour

The real time clock does not advance during machine.lightsleep(2000) as shown in the output below running on1.24.0:

[RTC=00:00:01 ticks=36]  Machine = 'Raspberry Pi Pico W with RP2040'[RTC=00:00:01 ticks=41]  Version = 'v1.24.0 on 2024-10-25 (GNU 13.2.0 MinSizeRel)'[RTC=00:00:03 ticks=2044]  After time.sleep_ms(2000)[RTC=00:00:03 ticks=4049]  After safe_sleep(2000) with 31 early wakeups

Additional Information

While machine.RTC().datetime() does not advance during machine.lightsleep(),time.ticks_ms advances as expected.

The funtion "safe_sleep()" was used to encapsulate calls to machine.lightsleep() because machine.lightsleep() returns after ~64ms. SeeIssue #15622 andIssue #16181

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp