diff --git a/src/STM32RTC.cpp b/src/STM32RTC.cpp index 1c0ac13..ce23691 100644 --- a/src/STM32RTC.cpp +++ b/src/STM32RTC.cpp @@ -133,6 +133,19 @@ void STM32RTC::setClockSource(Source_Clock source) } } +#if defined(STM32F1xx) +/** + * @brief get user asynchronous prescaler value for the current clock source. + * @param predivA: pointer to the current Asynchronous prescaler value + * @param dummy : not used (kept for compatibility reason) + * @retval None + */ +void STM32RTC::getPrediv(uint32_t *predivA, int16_t *dummy) +{ + UNUSED(dummy); + RTC_getPrediv(predivA); +} +#else /** * @brief get user (a)synchronous prescaler values if set else computed * ones for the current clock source. @@ -146,7 +159,22 @@ void STM32RTC::getPrediv(int8_t *predivA, int16_t *predivS) RTC_getPrediv(predivA, predivS); } } +#endif /* STM32F1xx */ +#if defined(STM32F1xx) +/** + * @brief set user asynchronous prescalers value. + * @note This method must be called before begin(). + * @param predivA: Asynchronous prescaler value. Reset value: RTC_AUTO_1_SECOND + * @param dummy : not used (kept for compatibility reason) + * @retval None + */ +void STM32RTC::setPrediv(uint32_t predivA, int16_t dummy) +{ + UNUSED(dummy); + RTC_setPrediv(predivA); +} +#else /** * @brief set user (a)synchronous prescalers value. * @note This method must be called before begin(). @@ -158,6 +186,7 @@ void STM32RTC::setPrediv(int8_t predivA, int16_t predivS) { RTC_setPrediv(predivA, predivS); } +#endif /* STM32F1xx */ /** * @brief enable the RTC alarm. diff --git a/src/STM32RTC.h b/src/STM32RTC.h index 78c99dc..1464bb4 100644 --- a/src/STM32RTC.h +++ b/src/STM32RTC.h @@ -189,9 +189,13 @@ class STM32RTC { void setY2kEpoch(uint32_t ts); void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0); +#if defined(STM32F1xx) + void getPrediv(uint32_t *predivA, int16_t *dummy = nullptr); + void setPrediv(uint32_t predivA, int16_t dummy = 0); +#else void getPrediv(int8_t *predivA, int16_t *predivS); void setPrediv(int8_t predivA, int16_t predivS); - +#endif /* STM32F1xx */ bool isConfigured(void) { return _configured; diff --git a/src/rtc.c b/src/rtc.c index 0dfd05b..ecc369c 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -66,6 +66,8 @@ static uint8_t HSEDiv = 0; static uint8_t predivSync_bits = 0xFF; static int8_t predivAsync = -1; static int16_t predivSync = -1; +#else +static uint32_t prediv = RTC_AUTO_1_SECOND; #endif /* !STM32F1xx */ static hourFormat_t initFormat = HOUR_FORMAT_12; @@ -203,6 +205,20 @@ static void RTC_initClock(sourceClock_t source) __HAL_RCC_RTC_ENABLE(); } +#if defined(STM32F1xx) +/** + * @brief set user asynchronous prescaler value. + * @note use RTC_AUTO_1_SECOND to reset value + * @param asynch: asynchronous prescaler value in range 0 - PREDIVA_MAX + * @retval None + */ +void RTC_setPrediv(uint32_t asynch) +{ + /* set the prescaler for a stm32F1 (value is hold by one param) */ + prediv = asynch; + LL_RTC_SetAsynchPrescaler(RTC, asynch); +} +#else /** * @brief set user (a)synchronous prescaler values. * @note use -1 to reset value and use computed ones @@ -212,7 +228,6 @@ static void RTC_initClock(sourceClock_t source) */ void RTC_setPrediv(int8_t asynch, int16_t synch) { -#if !defined(STM32F1xx) if ((asynch >= -1) && ((uint32_t)asynch <= PREDIVA_MAX) && \ (synch >= -1) && ((uint32_t)synch <= PREDIVS_MAX)) { predivAsync = asynch; @@ -221,12 +236,22 @@ void RTC_setPrediv(int8_t asynch, int16_t synch) RTC_computePrediv(&predivAsync, &predivSync); } predivSync_bits = (uint8_t)_log2(predivSync) + 1; -#else - UNUSED(asynch); - UNUSED(synch); -#endif /* !STM32F1xx */ } +#endif /* STM32F1xx */ +#if defined(STM32F1xx) +/** + * @brief get user asynchronous prescaler value for the current clock source. + * @param asynch: pointer where return asynchronous prescaler value. + * @retval None + */ +void RTC_getPrediv(uint32_t *asynch) +{ + /* get the prescaler for a stm32F1 (value is hold by one param) */ + prediv = LL_RTC_GetDivider(RTC); + *asynch = prediv; +} +#else /** * @brief get user (a)synchronous prescaler values if set else computed ones * for the current clock source. @@ -236,7 +261,6 @@ void RTC_setPrediv(int8_t asynch, int16_t synch) */ void RTC_getPrediv(int8_t *asynch, int16_t *synch) { -#if !defined(STM32F1xx) if ((predivAsync == -1) || (predivSync == -1)) { RTC_computePrediv(&predivAsync, &predivSync); } @@ -245,11 +269,8 @@ void RTC_getPrediv(int8_t *asynch, int16_t *synch) *synch = predivSync; } predivSync_bits = (uint8_t)_log2(predivSync) + 1; -#else - UNUSED(asynch); - UNUSED(synch); -#endif /* !STM32F1xx */ } +#endif /* STM32F1xx */ #if !defined(STM32F1xx) /** diff --git a/src/rtc.h b/src/rtc.h index 63a13ee..6bb5ba7 100644 --- a/src/rtc.h +++ b/src/rtc.h @@ -94,6 +94,9 @@ typedef void(*voidCallbackPtr)(void *); #endif #define PREDIVA_MAX (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos) #define PREDIVS_MAX (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos) +#else +/* for stm32F1 the MAX value is combining PREDIV low & high registers */ +#define PREDIVA_MAX 0xFFFFFU #endif /* !STM32F1xx */ #if defined(STM32F0xx) || defined(STM32L0xx) || \ @@ -135,9 +138,13 @@ static uint32_t RTC_getSource(void) { /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void RTC_SetClockSource(sourceClock_t source); - +#if defined(STM32F1xx) +void RTC_getPrediv(uint32_t *asynch); +void RTC_setPrediv(uint32_t asynch); +#else void RTC_getPrediv(int8_t *asynch, int16_t *synch); void RTC_setPrediv(int8_t asynch, int16_t synch); +#endif /* STM32F1xx */ void RTC_init(hourFormat_t format, sourceClock_t source, bool reset); void RTC_DeInit(void);