micropython
micropython copied to clipboard
ports/nrf: Add RTC support to NRF ports.
Resubmitting after accidentally closing #10400
Updated after reviewing RTCounter.py. It turns out that RTCounter starts up and uses the second nrf rtc unit so piggybacking off of that this update doesn't need most of the Circuitpython logic the earlier PR was using and takes care of starting up the rtc which had been omitted.
Since RTCounter uses rtc unit 1 this PR compiles on all of the currently supported nrf series boards.
This is the same update as the accidentally closed PR but there is an alternate version to evaluate as well #13340.
Signed-off-by: RetiredWizard [email protected]
@cwalther I was thinking about the offset check from my PR and was wondering if it's a carry over from the IMX boards that support an RTC battery to keep the clock running when the rest of the board is shutdown. I don't know if the nrf boards have any similar capability.
Found it. The validation thing is from https://github.com/adafruit/circuitpython/pull/2924/ and the purpose is indeed to maintain the clock over certain kinds of reset that clear the BSS section but not all of RAM (not a MicroPython soft reboot, that is already achieved by my approach). However, the parts of it that are in this PR are not sufficient to make this work, adjusting the linker scripts and heap initialization for setting up the .uninitialized section is also needed, as well as saving the RTC counter (https://github.com/adafruit/circuitpython/commit/daf7c2857da3f0cc61f20474bdd1ce2824cb409c).
I am undecided whether this is a desirable thing, so I will not add it to #13340 for now. It is useful in some cases, such as an unattended device in the field that occasionally crashes and is restarted by a watch-dog timer. On the other hand, it is a complication and violates the expectation that a reset resets everything.
Thanks! Great detective work!
I had to add MICROPY_PY_MACHINE_RTC_ENTRY to the MICROPY_PY_MACHINE_EXTRA_GLOBALS marco to make RTC show up in the machine module
time.localtime() and rtc.datetime() are not in sync. According to https://docs.micropython.org/en/latest/library/time.html "If secs is not provided or None, then the current time from the RTC is used."
time.localtime(time.mktime(machine.RTC().datetime())) works
Thank you for your work!