Skip to content

Commit 79d8b5f

Browse files
committed
rtc prescaler divider set/get in case of stm32F1
Using the stm32F1 existing functions to write/read the RTC prescaler registers (hold by the prediv var). In that case only the 1st is considered. Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent f2bfa27 commit 79d8b5f

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/rtc.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static uint8_t HSEDiv = 0;
6666
static uint8_t predivSync_bits = 0xFF;
6767
static int8_t predivAsync = -1;
6868
static int16_t predivSync = -1;
69+
#else
70+
static int32_t prediv = -1;
6971
#endif /* !STM32F1xx */
7072

7173
static hourFormat_t initFormat = HOUR_FORMAT_12;
@@ -210,9 +212,18 @@ static void RTC_initClock(sourceClock_t source)
210212
* @param synch: synchronous prescaler value in range 0 - PREDIVS_MAX
211213
* @retval None
212214
*/
215+
#if defined(STM32F1xx)
216+
void RTC_setPrediv(int32_t asynch, int16_t synch)
217+
{
218+
/* the synch param is not used there */
219+
UNUSED(synch);
220+
/* set the prescaler for a stm32F1 (value is hold by 1st param) */
221+
prediv = asynch;
222+
LL_RTC_SetAsynchPrescaler(RTC, (uint32_t)asynch);
223+
}
224+
#else
213225
void RTC_setPrediv(int8_t asynch, int16_t synch)
214226
{
215-
#if !defined(STM32F1xx)
216227
if ((asynch >= -1) && ((uint32_t)asynch <= PREDIVA_MAX) && \
217228
(synch >= -1) && ((uint32_t)synch <= PREDIVS_MAX)) {
218229
predivAsync = asynch;
@@ -221,11 +232,8 @@ void RTC_setPrediv(int8_t asynch, int16_t synch)
221232
RTC_computePrediv(&predivAsync, &predivSync);
222233
}
223234
predivSync_bits = (uint8_t)_log2(predivSync) + 1;
224-
#else
225-
UNUSED(asynch);
226-
UNUSED(synch);
227-
#endif /* !STM32F1xx */
228235
}
236+
#endif /* !STM32F1xx */
229237

230238
/**
231239
* @brief get user (a)synchronous prescaler values if set else computed ones
@@ -234,9 +242,18 @@ void RTC_setPrediv(int8_t asynch, int16_t synch)
234242
* @param synch: pointer where return synchronous prescaler value.
235243
* @retval None
236244
*/
245+
#if defined(STM32F1xx)
246+
void RTC_getPrediv(int32_t *asynch, int16_t *synch)
247+
{
248+
/* the synch param is not used there */
249+
UNUSED(synch);
250+
/* get the prescaler for a stm32F1 (value is hold by 1st param)*/
251+
prediv = (int32_t)LL_RTC_GetDivider(RTC);
252+
*asynch = prediv;
253+
}
254+
#else
237255
void RTC_getPrediv(int8_t *asynch, int16_t *synch)
238256
{
239-
#if !defined(STM32F1xx)
240257
if ((predivAsync == -1) || (predivSync == -1)) {
241258
RTC_computePrediv(&predivAsync, &predivSync);
242259
}
@@ -245,11 +262,8 @@ void RTC_getPrediv(int8_t *asynch, int16_t *synch)
245262
*synch = predivSync;
246263
}
247264
predivSync_bits = (uint8_t)_log2(predivSync) + 1;
248-
#else
249-
UNUSED(asynch);
250-
UNUSED(synch);
251-
#endif /* !STM32F1xx */
252265
}
266+
#endif /* !STM32F1xx */
253267

254268
#if !defined(STM32F1xx)
255269
/**

src/rtc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ static uint32_t RTC_getSource(void) {
135135
/* Exported macro ------------------------------------------------------------*/
136136
/* Exported functions ------------------------------------------------------- */
137137
void RTC_SetClockSource(sourceClock_t source);
138-
138+
#if defined(STM32F1xx)
139+
void RTC_getPrediv(int32_t *asynch, int16_t *synch);
140+
void RTC_setPrediv(int32_t asynch, int16_t synch);
141+
#else
139142
void RTC_getPrediv(int8_t *asynch, int16_t *synch);
140143
void RTC_setPrediv(int8_t asynch, int16_t synch);
144+
#endif /* STM32F1xx */
141145

142146
void RTC_init(hourFormat_t format, sourceClock_t source, bool reset);
143147
void RTC_DeInit(void);

0 commit comments

Comments
 (0)