Skip to content

Commit 3ba0f3a

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 3ba0f3a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/rtc.c

Lines changed: 12 additions & 4 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,7 +212,7 @@ static void RTC_initClock(sourceClock_t source)
210212
* @param synch: synchronous prescaler value in range 0 - PREDIVS_MAX
211213
* @retval None
212214
*/
213-
void RTC_setPrediv(int8_t asynch, int16_t synch)
215+
void RTC_setPrediv(int32_t asynch, int16_t synch)
214216
{
215217
#if !defined(STM32F1xx)
216218
if ((asynch >= -1) && ((uint32_t)asynch <= PREDIVA_MAX) && \
@@ -222,8 +224,11 @@ void RTC_setPrediv(int8_t asynch, int16_t synch)
222224
}
223225
predivSync_bits = (uint8_t)_log2(predivSync) + 1;
224226
#else
225-
UNUSED(asynch);
227+
/* the synch param is not used there */
226228
UNUSED(synch);
229+
/* set the prescaler for a stm32F1 (value is hold by 1st param) */
230+
prediv = (int32_t)asynch;
231+
LL_RTC_SetAsynchPrescaler(RTC, asynch);
227232
#endif /* !STM32F1xx */
228233
}
229234

@@ -234,7 +239,7 @@ void RTC_setPrediv(int8_t asynch, int16_t synch)
234239
* @param synch: pointer where return synchronous prescaler value.
235240
* @retval None
236241
*/
237-
void RTC_getPrediv(int8_t *asynch, int16_t *synch)
242+
void RTC_getPrediv(int32_t *asynch, int16_t *synch)
238243
{
239244
#if !defined(STM32F1xx)
240245
if ((predivAsync == -1) || (predivSync == -1)) {
@@ -246,8 +251,11 @@ void RTC_getPrediv(int8_t *asynch, int16_t *synch)
246251
}
247252
predivSync_bits = (uint8_t)_log2(predivSync) + 1;
248253
#else
249-
UNUSED(asynch);
254+
/* the synch param is not used there */
250255
UNUSED(synch);
256+
/* get the prescaler for a stm32F1 (value is hold by 1st param)*/
257+
prediv = (int32_t)LL_RTC_GetDivider(RTC);
258+
*asynch = prediv;
251259
#endif /* !STM32F1xx */
252260
}
253261

src/rtc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ static uint32_t RTC_getSource(void) {
136136
/* Exported functions ------------------------------------------------------- */
137137
void RTC_SetClockSource(sourceClock_t source);
138138

139-
void RTC_getPrediv(int8_t *asynch, int16_t *synch);
140-
void RTC_setPrediv(int8_t asynch, int16_t synch);
139+
void RTC_getPrediv(int32_t *asynch, int16_t *synch);
140+
void RTC_setPrediv(int32_t asynch, int16_t synch);
141141

142142
void RTC_init(hourFormat_t format, sourceClock_t source, bool reset);
143143
void RTC_DeInit(void);

0 commit comments

Comments
 (0)