Skip to content

rtc/ptc85263A: Add handling of stop_enable flag.#18988

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
marinauterion:fix/ptc85263A-stopenable
May 28, 2026
Merged

rtc/ptc85263A: Add handling of stop_enable flag.#18988
xiaoxiang781216 merged 1 commit into
apache:masterfrom
marinauterion:fix/ptc85263A-stopenable

Conversation

@marinauterion
Copy link
Copy Markdown
Contributor

Summary

On some boards, the PCF85263 RTC does not count between reboots. After inspecting the registers
at boot, STOP_ENABLE (register 0x2E) had bit 0 set (STOP=1), which freezes the RTC counter.

The exact trigger is unknown - not all boards exhibit the issue. The bit is battery-backed and
persists across reboots, so once set (e.g. by a power glitch or undefined hardware state) the
RTC stays frozen until explicitly cleared. The old driver never did this.

Fix: write 0x00 to STOP_ENABLE on init, which is the correct reset value per the datasheet.
Fix: set time properly:
Due to datasheet the set_time should be as follow:
1. set stop_enable
2. clear prescaler
3. set time
4. clear stop_enable

Impact

On affected boards, system time resets to the last value written via system_time set after
every reboot, regardless of how much time has passed:

  1. Set time to 10:00am
  2. Turn off device, wait 2 minutes
  3. Turn on device → time is 10:00am again

Testing

Tested on PixHawk v6x (STM32H753IIK6)

Boot logs before and after the fix:

Before Fix

Boot 1:
> pcf85263: STOP_ENABLE before init: 0xc1  <-- STOP=1 (bit 0 set)
> board: RTC time: 1970-01-01 00:00:05

wait 1 min

Boot 2:
> pcf85263: STOP_ENABLE before init: 0xc1  <-- STOP=1 (persistent)
> board: RTC time: 1970-01-01 00:00:06     <-- RTC did not count while powered off

After Fix

Boot 3 (first boot after fix - STOP still set from before, now cleared by driver):
> pcf85263: STOP_ENABLE before init: 0xc1  <-- STOP=1, driver clears it
> board: RTC time: 1970-01-01 00:00:05
> system_time set 1779897071		   <-- Wed May 27 2026 15:51:11 GMT+0000

wait 1 min

Boot 4 (STOP was cleared on Boot 3, RTC counted during power-off):
> pcf85263: STOP_ENABLE before init: 0x00  <-- STOP=0
> board: RTC time: 2026-05-27 15:52:11     <-- correct time, RTC counted

Automated Power Cycle Test

41 iterations: power on → set time → power off → power on → compare RTC vs PC time.
STOP was 0 on every boot after the fix. The remaining ~1s diff is a measurement artifact
from integer truncation in the test script, not an RTC error.

run=0 diff=1s uC=1779952089 laptop=1779952090
run=1 diff=1s uC=1779952165 laptop=1779952166
run=2 diff=0s uC=1779952241 laptop=1779952241
run=3 diff=0s uC=1779952317 laptop=1779952317

run=39 diff=0s uC=1779955049 laptop=1779955049
run=40 diff=0s uC=1779955125 laptop=1779955125
run=41 diff=1s uC=1779955201 laptop=1779955202

On some boards, the PCF85263 RTC does not count between reboots. Due to STOP_ENABLE (register 0x2E), bit=0 = 1, which freezes the RTC counter.

The exact trigger is unknown - not all boards exhibit the issue. The bit is battery-backed and
persists across reboots, so once set (e.g. by a power glitch or undefined hardware state) the
RTC stays frozen until explicitly cleared. The old driver never did this.

Fix: write `0x00` to `STOP_ENABLE` on init, which is the correct reset value per the datasheet.
Fix: set time properly:
	Due to datasheet the set_time should be as follow:
	1. set stop_enable
	2. clear prescaler
	3. set time
	4. clear stop_enable

Signed-off-by: Marin Doetterer <marin@auterion.com>
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels May 28, 2026
@xiaoxiang781216 xiaoxiang781216 merged commit b4f04a8 into apache:master May 28, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants