Skip to content

Commit 4ec0bc6

Browse files
jeromecoutantadbridge
authored andcommitted
STM32 RTC Init minor update
1 parent 95c9850 commit 4ec0bc6

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

targets/TARGET_STM/rtc_api.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ void rtc_init(void)
5353
__HAL_RCC_PWR_CLK_ENABLE();
5454
HAL_PWR_EnableBkUpAccess();
5555

56+
#if DEVICE_LOWPOWERTIMER
57+
if ( (rtc_isenabled()) && ((RTC->PRER & RTC_PRER_PREDIV_S) == PREDIV_S_VALUE) ) {
58+
#else /* DEVICE_LOWPOWERTIMER */
5659
if (rtc_isenabled()) {
60+
#endif /* DEVICE_LOWPOWERTIMER */
5761
return;
5862
}
5963

@@ -107,19 +111,8 @@ void rtc_init(void)
107111
RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
108112
#else /* TARGET_STM32F1 */
109113
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
110-
111-
/* PREDIV_A : 7-bit asynchronous prescaler */
112-
#if DEVICE_LOWPOWERTIMER && !MBED_CONF_TARGET_LOWPOWERTIMER_LPTIM
113-
/* PREDIV_A is set to a small value to improve the SubSeconds resolution */
114-
/* with a 32768Hz clock, PREDIV_A=7 gives a precision of 244us */
115-
RtcHandle.Init.AsynchPrediv = 7;
116-
#else
117-
/* PREDIV_A is set to the maximum value to improve the consumption */
118-
RtcHandle.Init.AsynchPrediv = 0x007F;
119-
#endif
120-
/* PREDIV_S : 15-bit synchronous prescaler */
121-
/* PREDIV_S is set in order to get a 1 Hz clock */
122-
RtcHandle.Init.SynchPrediv = RTC_CLOCK / (RtcHandle.Init.AsynchPrediv + 1) - 1;
114+
RtcHandle.Init.AsynchPrediv = PREDIV_A_VALUE;
115+
RtcHandle.Init.SynchPrediv = PREDIV_S_VALUE;
123116
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
124117
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
125118
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

targets/TARGET_STM/rtc_api_hal.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ extern "C" {
5151
#define RTC_CLOCK LSI_VALUE
5252
#endif
5353

54+
/* PREDIV_A : 7-bit asynchronous prescaler */
55+
/* PREDIV_S : 15-bit synchronous prescaler */
56+
/* PREDIV_S is set in order to get a 1 Hz clock */
57+
#if DEVICE_LOWPOWERTIMER && !MBED_CONF_TARGET_LOWPOWERTIMER_LPTIM
58+
/* PREDIV_A is set to a small value to improve the SubSeconds resolution */
59+
/* with a 32768Hz clock, PREDIV_A=7 gives a precision of 244us */
60+
#define PREDIV_A_VALUE 7
61+
#else /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */
62+
/* PREDIV_A is set to the maximum value to improve the consumption */
63+
#define PREDIV_A_VALUE 127
64+
#endif /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */
65+
66+
#define PREDIV_S_VALUE RTC_CLOCK / (PREDIV_A_VALUE + 1) - 1
67+
5468
/** Read RTC time with subsecond precision.
5569
*
5670
* @return Time is microsecond

0 commit comments

Comments
 (0)