Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM: monotonic time even when RTC is changed #7965

Merged
merged 2 commits into from
May 12, 2023

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented May 12, 2023

Test:

>> import time,rtc
>>> r = rtc.RTC()
>>> print(time.monotonic()); r.datetime = time.struct_time((2023,1,1,0,0,0,0,0,0)); print(time.monotonic())
1329.49
1329.49
>>> print(time.monotonic()); r.datetime = time.struct_time((2022,1,1,0,0,0,0,0,0)); print(time.monotonic())
1339.38
1339.38
>>> print(time.monotonic_ns()); r.datetime = time.struct_time((2022,1,1,0,0,0,0,0,0)); print(time.monotonic_ns())
1353792083741
1353791992187
>>> print(time.monotonic_ns()); r.datetime = time.struct_time((2024,1,1,0,0,0,0,0,0)); print(time.monotonic_ns())
1362228332530
1362227539062
>>> 

I also tested after ctrl-D: time.monotonic() is not reset to zero, which I think is OK.

The change looks bigger than it is: I had to reorder some things to avoid a forward declaration.

jepler
jepler previously approved these changes May 12, 2023
Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

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

makes sense, didn't test.

Neradoc
Neradoc previously approved these changes May 12, 2023
Copy link

@Neradoc Neradoc left a comment

Choose a reason for hiding this comment

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

This fixes #7808 from my tests on a Feather STM32F405 Express.
Thanks !

@dhalbert
Copy link
Collaborator Author

I need to look at this again. I didn't notice time is going backwards slightly here:

>>> print(time.monotonic_ns()); r.datetime = time.struct_time((2022,1,1,0,0,0,0,0,0)); print(time.monotonic_ns())
1353792083741
1353791992187

@dhalbert dhalbert marked this pull request as draft May 12, 2023 14:47
@dhalbert dhalbert dismissed stale reviews from Neradoc and jepler via e806785 May 12, 2023 18:40
@dhalbert
Copy link
Collaborator Author

dhalbert commented May 12, 2023

monotonic_ns() now always goes forward. subticks (32 per tick) were not being taken into account.

>>> print(time.monotonic_ns()); r.datetime = time.struct_time((2022,1,1,0,0,0,0,0,0)); print(time.monotonic_ns())
35930114752
35930236824

I am not so fond of the STM32 RTC peripheral.

@dhalbert dhalbert marked this pull request as ready for review May 12, 2023 19:38
@dhalbert dhalbert requested review from jepler and Neradoc May 12, 2023 19:38
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thank you!

@tannewt tannewt merged commit ca01200 into adafruit:main May 12, 2023
415 checks passed
@dhalbert dhalbert deleted the stm-rtc-monotonic branch May 12, 2023 22:42
dhalbert pushed a commit to dhalbert/circuitpython that referenced this pull request Sep 19, 2023
As per Issue adafruit#7965, this class does not work on the Unix build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting the rtc on STM32 affects the value of time.monotonic()
4 participants