Skip to content

ports/rtc: Inconsistencies between ports and the documentation. #10578

Description

@robert-hh

It looks like the machine.rtc() API is different for all ports and to the documentation.

  • to start with the good part: In all ports rtc.datetime() matches the machine.RTC class documentation.
  • rtc.init() for the cc3200 works as documented
  • rtc.init() differs from the documentation in the item order of the datetime tuple for the ports esp32, samd, mimxrt.
  • no rtc.init() at the rp2 port.
  • rtc.init() at the stm32 and renesas.ra port just reinit's the RTC device and ignores the function argument.
  • rtc.now() is only available in the cc3200 and mimxrt port.
  • the documentation for rtc.datetime() is different between the machine.RTC class section and the quickref for the ports stm32, rp2, mimxrt, esp32, esp8266, renesas-ra,

So it seems as if the documentation of rtc.init() and rtc.now() only matches the cc3200 port. I can make that all consistent, but we should agree first on which class methods should be available. So a simple approach would be:

  • keep rtc.datetime() as it is now. Maybe add it to the cc3200 port. It is not consistent to CPython datetime.datetime, but that topic has been discussed several times already with the decision to keep the actual rtc.datetime format.
  • drop rtc.now() from the mimxrt port. Only keep it at the CC3200 port for legacy.
  • drop the set date/time functionality of rtc.init() and/or change at least the documentation.
  • fix the inconsistencies in the documentation.

Edit: Created PR #10607

Activity

  1. peterhinch commented on Jan 25, 2023

    @peterhinch
    Contributor

    You've probably seen #5553. Fixing this is long overdue but it will break code.

    Should the rtc.datetime tuple match the format of time.localtime? (This would break even more code, though.)

  2. robert-hh commented on Jan 25, 2023

    @robert-hh
    ContributorAuthor

    The section of the documentation which you changed is the only one which matches rtc.datetime(). But all the quickref paragraphs are wrong.My preference is in the post before in the last four bullets. I do not suggest to change rtc.datetime(), since it seems the only part which is consistent over the ports, if implemented at all.

  3. SirWintour commented on Jan 25, 2023

    @SirWintour

    How about adding a rtc.localtime that follow the time.localtime format?
    This way, there is a function that follows the time format, and don't break any existing code.

  4. robert-hh commented on Jan 25, 2023

    @robert-hh
    ContributorAuthor

    Why? rtc.datetime() and time.localtime() use the same hardware clock, if it exists. So there is no benefit in having a rtc,localtime().

  5. SirWintour commented on Jan 25, 2023

    @SirWintour

    What I really want, is a simple way of setting the RTC using something like Unix Timestamp.
    It is possible to use time.gmtime to convert seconds to a datetime format, but this don't fit with the rtc.datetime as stated.

    An alternative solution is make a function like rtc.set_epoc or similar.
    Then even libraries that can get the time, can be converted to epoc and used to set the RTC.

  6. robert-hh commented on Jan 25, 2023

    @robert-hh
    ContributorAuthor

    For the SAMD port I had made an extension for boards without RTC, that you could supply a time value as seconds since epoch as argument to time.localtime() to set the time. But that's non-standard.

  7. robert-hh commented on Jan 28, 2023

    @robert-hh
    ContributorAuthor

    @dpgeorge Do you have a preference about how to proceed with reducing the inconsistencies of machine.RTC. I can at least make an initial PR to fix the documentation of rtc.datetime(), assuming that this method will not be changed.

  8. villeneuve commented on May 3, 2023

    @villeneuve

    Hi!
    Correct me if I'm wrong, but I see a mistake in the doc for the rp2 RTC. We can read:
    rtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and time, eg. 2017/8/23 1:12:48

    The code works ok, no problem. But the comment should be read: #... eg. 2017/8/23 12:48

    As per the class RTC doc, The 8-tuple has the following format: (year, month, day, weekday, hours, minutes, seconds, subseconds)

    So the time set is 12:48:00 not 1:12:48

  9. added
    portsRelates to multiple ports, or a new/proposed port
    on Sep 10, 2024
  10. added a commit that references this issue on Aug 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    portsRelates to multiple ports, or a new/proposed port

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions