Skip to content

Verification that prescaler values are configured should be added #71

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
jan019 opened this issue Jul 6, 2022 · 1 comment · Fixed by #72
Closed

Verification that prescaler values are configured should be added #71

jan019 opened this issue Jul 6, 2022 · 1 comment · Fixed by #72
Assignees
Labels
bug 🐛 Something isn't working
Milestone

Comments

@jan019
Copy link

jan019 commented Jul 6, 2022

RTC should contain an assertion checking if the prescaler values are configured or not. Or check if configured and if not, call the function to compute the values.

This portion of code

STM32RTC/src/rtc.c

Lines 382 to 398 in 95b7514

if (!LL_RTC_IsActiveFlag_INITS(RtcHandle.Instance) || reset) {
RtcHandle.Init.HourFormat = format == HOUR_FORMAT_12 ? RTC_HOURFORMAT_12 : RTC_HOURFORMAT_24;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
#if defined(RTC_OUTPUT_REMAP_NONE)
RtcHandle.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
#endif /* RTC_OUTPUT_REMAP_NONE */
RTC_getPrediv((int8_t *) & (RtcHandle.Init.AsynchPrediv), (int16_t *) & (RtcHandle.Init.SynchPrediv));
HAL_RTC_Init(&RtcHandle);
// Default: saturday 1st of January 2001
// Note: year 2000 is invalid as it is the hardware reset value and doesn't raise INITS flag
RTC_SetDate(1, 1, 1, 6);
reinit = true;
}
is executed only when the device was previously unpowered -> RTC is not initialized. For the case when RTC is not initialized the function
RTC_getPrediv((int8_t *) & (RtcHandle.Init.AsynchPrediv), (int16_t *) & (RtcHandle.Init.SynchPrediv));
is called and prescaler values are computed.

In case only a soft reset is performed, the RTC remains initialized, the above mentioned code is not executed and prescaler values are not calculated. Therefore they remain set to -1. Then when setting and RTC alarm with subseconds enabled, the following issue occurs:

This leads to reserved bits in the register being written to 1 and generally incorrect behaviour. This is not easy to debug and just a note in the readme that the function setPrediv() must be called before begin() can easly be missed.

The examples also don't call this function, which makes the issue even more hidden. Maybe some boards ensure that invalid values are not written to registers and this issue is not observed on them.

ABOSTM added a commit to ABOSTM/STM32RTC that referenced this issue Jul 8, 2022
…ized

fixes stm32duino#71

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
@ABOSTM
Copy link
Contributor

ABOSTM commented Jul 8, 2022

@jan019 thanks for reporting this issue, and for your detailed analysis.
I proposed a fix in PR #72,
feel free to review it and tests it

@rozrabiak this PR should also fix your issue #70

@fpistm fpistm added the bug label Jul 8, 2022
@fpistm fpistm added this to the 1.3.2 milestone Jul 8, 2022
@fpistm fpistm closed this as completed in #72 Jul 8, 2022
@fpistm fpistm added bug 🐛 Something isn't working and removed bug labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants