First of all: Sry my english...
Ok. Let's start!
If you alredy had tried to use the RTC with a battery backup to make the time counting even if there is no power supply, you may probably hit you in the biggest proble of the milenary: The RTC keep it's time but don't continue to run.
But why?
the solution is inside the deepest registers of the STM32.
Firstly, the batterry has to be connected beetween VBACK and GND. With that, all the RAM registers of the STM32 will be kept in memory (like you're rtc object that you've instancied from pyb.RTC()). To make it "forwarding" the RTC, you have, like written in the page 131 of the link here:https://www.st.com/content/ccc/resource ... 171190.pdf
You have to modify the Backup domain control register (RCC_BDCR) to enable the RTC of using the VBAT (VBACK on PyBoard) power input.
Passing the details, you will have to do some asembler to modify the two bits of RTCSEL to 01, and in code, that looks like that:
Code: Select all
import stm
@micropython.asm_thumb
def enableRTC():
movwt(r2, stm.RCC)
ldr(r0, [r2, stm.RCC_BDCR])
movwt(r1, 0xFFFFFCFF)
and_(r0, r1)
movwt(r1, 0x00000100)
orr(r0, r1)
str(r0, [r2, stm.RCC_BDCR])
enableRTC()
https://docs.micropython.org/en/latest/ ... index.html
Then, you just have to setup you're RTC with a simple pyb.RTC.datetime([year, month, day, weekday, hours, minutes, seconds, subseconds]) and the magic happend! The RTC will work infinitly with a ~1[uA] curent consumption.
Have a nice developpment time!