Skip to content

Commit 3c286d2

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 one param is considered. Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent f2bfa27 commit 3c286d2

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/rtc.c

Lines changed: 32 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 uint32_t prediv = RTC_AUTO_1_SECOND;
6971
#endif /* !STM32F1xx */
7072

7173
static hourFormat_t initFormat = HOUR_FORMAT_12;
@@ -203,6 +205,20 @@ static void RTC_initClock(sourceClock_t source)
203205
__HAL_RCC_RTC_ENABLE();
204206
}
205207

208+
#if defined(STM32F1xx)
209+
/**
210+
* @brief set user (a)synchronous prescaler values.
211+
* @note use RTC_AUTO_1_SECOND to reset value and use computed ones
212+
* @param asynch: asynchronous prescaler value in range 0 - PREDIVA_MAX
213+
* @retval None
214+
*/
215+
void RTC_setPrediv(uint32_t asynch)
216+
{
217+
/* set the prescaler for a stm32F1 (value is hold by one param) */
218+
prediv = asynch;
219+
LL_RTC_SetAsynchPrescaler(RTC, asynch);
220+
}
221+
#else
206222
/**
207223
* @brief set user (a)synchronous prescaler values.
208224
* @note use -1 to reset value and use computed ones
@@ -212,7 +228,6 @@ static void RTC_initClock(sourceClock_t source)
212228
*/
213229
void RTC_setPrediv(int8_t asynch, int16_t synch)
214230
{
215-
#if !defined(STM32F1xx)
216231
if ((asynch >= -1) && ((uint32_t)asynch <= PREDIVA_MAX) && \
217232
(synch >= -1) && ((uint32_t)synch <= PREDIVS_MAX)) {
218233
predivAsync = asynch;
@@ -221,12 +236,23 @@ void RTC_setPrediv(int8_t asynch, int16_t synch)
221236
RTC_computePrediv(&predivAsync, &predivSync);
222237
}
223238
predivSync_bits = (uint8_t)_log2(predivSync) + 1;
224-
#else
225-
UNUSED(asynch);
226-
UNUSED(synch);
227-
#endif /* !STM32F1xx */
228239
}
240+
#endif /* STM32F1xx */
229241

242+
#if defined(STM32F1xx)
243+
/**
244+
* @brief get user (a)synchronous prescaler values if set else computed ones
245+
* for the current clock source.
246+
* @param asynch: pointer where return asynchronous prescaler value.
247+
* @retval None
248+
*/
249+
void RTC_getPrediv(uint32_t *asynch)
250+
{
251+
/* get the prescaler for a stm32F1 (value is hold by one param)*/
252+
prediv = LL_RTC_GetDivider(RTC);
253+
*asynch = prediv;
254+
}
255+
#else
230256
/**
231257
* @brief get user (a)synchronous prescaler values if set else computed ones
232258
* for the current clock source.
@@ -236,7 +262,6 @@ void RTC_setPrediv(int8_t asynch, int16_t synch)
236262
*/
237263
void RTC_getPrediv(int8_t *asynch, int16_t *synch)
238264
{
239-
#if !defined(STM32F1xx)
240265
if ((predivAsync == -1) || (predivSync == -1)) {
241266
RTC_computePrediv(&predivAsync, &predivSync);
242267
}
@@ -245,11 +270,8 @@ void RTC_getPrediv(int8_t *asynch, int16_t *synch)
245270
*synch = predivSync;
246271
}
247272
predivSync_bits = (uint8_t)_log2(predivSync) + 1;
248-
#else
249-
UNUSED(asynch);
250-
UNUSED(synch);
251-
#endif /* !STM32F1xx */
252273
}
274+
#endif /* STM32F1xx */
253275

254276
#if !defined(STM32F1xx)
255277
/**

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(uint32_t *asynch);
140+
void RTC_setPrediv(uint32_t asynch);
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)