Skip to content

Rtc mix in millisec API is using subsecond expressed in milliseconds #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

FRASTM
Copy link
Contributor

@FRASTM FRASTM commented Jul 10, 2023

STM32RTC APi has subsecond parameter which is a value in milliseconds

Becasue of the BINARY MIX mode, the parameter subsecond could be confusing as the subsecond register of the RTC is:

  • a nb of millisec [0-999] in BCD mode
  • a nb of ticks in BIN or MIX mode -> one tick is one counter unit at the fqce = RTC clock source freq / fqce_apre

For example, in MIX mode, when RTC is clocked by the LSE (32768Hz) the tick is downcounting at 256Hz
(1 tick is ~ 3.9ms )
The RTC subsecond register is converted in ms by (0xFFFFFFFF - SubSecReg) * 1000/256
And N miliseconds is converted in ticks (count unit) by 0xFFFFFFFF - (SubSecReg * 256) /1000

With this PR, the STM32RTC API is always giving the subsecond parameter in a nb of milliseconds.
Especially with functions:

  • getSubSeconds() and getTime()

  • getAlarmSubSeconds()

  • setAlarmSubSeconds() and setAlarmTime()

  • setSubSeconds() and setTime() (but Subsecond value is ignored there RO register)

This is valid when the RTC_BINARY_MIX mode exists in the RTC
(bitfield in the RTC ICSR register)
Set the RTC mode through a setBinaryMode function to be called
before begin.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
@FRASTM
Copy link
Contributor Author

FRASTM commented Jul 10, 2023

with this PR and running the sketch mixRTCAlarm:

18:23:23.681 -> Start at 16:22:06.199
18:23:23.776 -> Set Alarm A in 12s (at 16:22:18)
18:23:23.776 -> Set Alarm B (in 400 ms) at 597 ms
18:23:24.099 -> Alarm B Match at 597 ms
18:23:35.495 -> Alarm A Match at 16:22:18

@FRASTM FRASTM force-pushed the rtc_mix_millisec branch 3 times, most recently from adeb2e4 to 614cc5c Compare July 11, 2023 11:11
@FRASTM FRASTM force-pushed the rtc_mix_millisec branch 2 times, most recently from 45d9df2 to 87aec09 Compare July 21, 2023 12:37
configure the Alarm with Second mask --> trigs IRQHandler
The Autoclear bit field depends on the RTC ALARM  SSR register.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
When the RTC is running in MIX mode (bianry and calendar),
the ssub-second register is a 32-bit value which must not be converted
in ms

Signed-off-by: Francois Ramu <francois.ramu@st.com>
In case the RTC is running in MIX mode (BINary and calendar),
the subsecond register is a 32-bit value (and not msec)

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Set the subsecond for the alarm value.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
The binaryMode_t is retrieved directly from the RTC mode,
not as a parameter.
The Subsecond parameter is expressed in millisecond in
RTC_SetTime/GetTime RTC_StartAlarm/GetAlarm

Signed-off-by: Francois Ramu <francois.ramu@st.com>
@FRASTM
Copy link
Contributor Author

FRASTM commented Sep 7, 2023

Now squashed in #93

@FRASTM FRASTM closed this Sep 7, 2023
@FRASTM FRASTM deleted the rtc_mix_millisec branch September 7, 2023 08:28
@fpistm fpistm added the duplicate This issue or pull request already exists label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
Development

Successfully merging this pull request may close these issues.

2 participants