Skip to content

STM32 RTC Init minor update #6723

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

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions targets/TARGET_STM/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ void rtc_init(void)
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();

#if DEVICE_LOWPOWERTIMER
if ( (rtc_isenabled()) && ((RTC->PRER & RTC_PRER_PREDIV_S) == PREDIV_S_VALUE) ) {
#else /* DEVICE_LOWPOWERTIMER */
if (rtc_isenabled()) {
#endif /* DEVICE_LOWPOWERTIMER */
return;
}

Expand Down Expand Up @@ -107,19 +111,8 @@ void rtc_init(void)
RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
#else /* TARGET_STM32F1 */
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;

/* PREDIV_A : 7-bit asynchronous prescaler */
#if DEVICE_LOWPOWERTIMER && !MBED_CONF_TARGET_LOWPOWERTIMER_LPTIM
/* PREDIV_A is set to a small value to improve the SubSeconds resolution */
/* with a 32768Hz clock, PREDIV_A=7 gives a precision of 244us */
RtcHandle.Init.AsynchPrediv = 7;
#else
/* PREDIV_A is set to the maximum value to improve the consumption */
RtcHandle.Init.AsynchPrediv = 0x007F;
#endif
/* PREDIV_S : 15-bit synchronous prescaler */
/* PREDIV_S is set in order to get a 1 Hz clock */
RtcHandle.Init.SynchPrediv = RTC_CLOCK / (RtcHandle.Init.AsynchPrediv + 1) - 1;
RtcHandle.Init.AsynchPrediv = PREDIV_A_VALUE;
RtcHandle.Init.SynchPrediv = PREDIV_S_VALUE;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
Expand Down
14 changes: 14 additions & 0 deletions targets/TARGET_STM/rtc_api_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ extern "C" {
#define RTC_CLOCK LSI_VALUE
#endif

/* PREDIV_A : 7-bit asynchronous prescaler */
/* PREDIV_S : 15-bit synchronous prescaler */
/* PREDIV_S is set in order to get a 1 Hz clock */
#if DEVICE_LOWPOWERTIMER && !MBED_CONF_TARGET_LOWPOWERTIMER_LPTIM
/* PREDIV_A is set to a small value to improve the SubSeconds resolution */
/* with a 32768Hz clock, PREDIV_A=7 gives a precision of 244us */
#define PREDIV_A_VALUE 7
#else /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */
/* PREDIV_A is set to the maximum value to improve the consumption */
#define PREDIV_A_VALUE 127
#endif /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */

#define PREDIV_S_VALUE RTC_CLOCK / (PREDIV_A_VALUE + 1) - 1

/** Read RTC time with subsecond precision.
*
* @return Time is microsecond
Expand Down