mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-10-15 10:19:57 +00:00
The RAK4631 overlay declared no zephcore,rtc-i2c candidate, so a fitted RAK12002 (an RV3028 at 0x52) was never probed or written, and every power cut started the node at 1970. Declaring it is not enough: the RV3028 ships with backup switchover disabled (EEPROM 37h BSM = 00), so a power cut still loses the time. The overlay now declares the RV3028 with the zero-mask rtc-i2c.dtsi uses for it, and a new optional rv3028-eeprom-config descriptor property holds (register, mask, value) triplets for its EEPROM configuration registers 35h-37h. The RAK4631 sets direct switchover with the trickle charger on (TCE, BSM = 01, TCR 3 kOhm), as the RV-3028-C7 Application Manual (Rev. 1.4) 7.3 prescribes for a capacitor backup, FEDE set as 3.15.6 says it always should be, and CLKOUT off. The configuration has to live in EEPROM: the chip reloads its configuration RAM from EEPROM at power-on and every midnight (4.6.2). The store runs only when a read identified the chip (RTC_FOUND, not an adoption on a failed second read) and a BSF-checked time read just before it showed no switchover. It follows 3.15.6 (BSM 00 or 10 for any EEPROM access): EERD held, switchover off in RAM, each configured byte compared against the EEPROM with a single-byte read and written only if it differs, and a closing Refresh that restores the stored switchover mode, read back on every boot. 36h, the factory trim, is never written. Switchover is turned back on only once EEbusy reads 0; otherwise it stays off until a retry or the daily refresh. A failed store sets the config in RAM (also only once EEbusy reads 0). A failed or skipped store is retried every 10 minutes, at most 3 times per boot, each retry identifying the chip again first. A switchover disables the chip's I2C mid-transfer (4.2), so at a node with rv3028-eeprom-config the time is read at boot and written on each sync with BSF cleared before and checked after. A read that saw a switchover gives no time. A write sets year 00h first and the real year last, so a power loss cutting it between its first and last byte leaves year 2000 and the next boot takes no time from it, and a write not confirmed is repeated every 5 s, up to 12 times, with the time run on. All of the RV3028 code is compiled only when some node carries rv3028-eeprom-config, so other boards, thinknode_m1 among them, build the same RTC object as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>