Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/STM32RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void STM32RTC::begin(bool resetTime, Hour_Format format)
bool reinit;

_format = format;
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
reinit = RTC_init((format == HOUR_12) ? HOUR_FORMAT_12 : HOUR_FORMAT_24,
(_mode == MODE_MIX) ? ::MODE_BINARY_MIX : ((_mode == MODE_BIN) ? ::MODE_BINARY_ONLY : ::MODE_BINARY_NONE),
(_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
Expand All @@ -74,7 +74,7 @@ void STM32RTC::begin(bool resetTime, Hour_Format format)
(_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
(_clockSource == HSE_CLOCK) ? ::HSE_CLOCK : ::LSI_CLOCK
, resetTime);
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
_timeSet = !reinit;

syncDate();
Expand Down Expand Up @@ -145,13 +145,13 @@ void STM32RTC::setClockSource(Source_Clock source, uint32_t predivA, uint32_t pr
{
if (IS_CLOCK_SOURCE(source)) {
_clockSource = source;
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
RTC_SetClockSource((_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
(_clockSource == HSI_CLOCK) ? ::HSI_CLOCK : ::LSI_CLOCK);
#else
RTC_SetClockSource((_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
(_clockSource == HSE_CLOCK) ? ::HSE_CLOCK : ::LSI_CLOCK);
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
}
RTC_setPrediv(predivA, predivS);
}
Expand Down
8 changes: 4 additions & 4 deletions src/STM32RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@

typedef void(*voidFuncPtr)(void *);

#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
#define IS_CLOCK_SOURCE(SRC) (((SRC) == STM32RTC::LSI_CLOCK) || ((SRC) == STM32RTC::LSE_CLOCK) ||\
((SRC) == STM32RTC::HSI_CLOCK))
#else
#define IS_CLOCK_SOURCE(SRC) (((SRC) == STM32RTC::LSI_CLOCK) || ((SRC) == STM32RTC::LSE_CLOCK) ||\
((SRC) == STM32RTC::HSE_CLOCK))
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
#define IS_HOUR_FORMAT(FMT) (((FMT) == STM32RTC::HOUR_12) || ((FMT) == STM32RTC::HOUR_24))

class STM32RTC {
Expand Down Expand Up @@ -112,11 +112,11 @@ class STM32RTC {
enum Source_Clock : uint8_t {
LSI_CLOCK = ::LSI_CLOCK,
LSE_CLOCK = ::LSE_CLOCK,
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
HSI_CLOCK = ::HSI_CLOCK,
#else
HSE_CLOCK = ::HSE_CLOCK
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
};

enum Alarm : uint32_t {
Expand Down
20 changes: 19 additions & 1 deletion src/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ static void RTC_initClock(sourceClock_t source)
enableClock(HSI_CLOCK);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP;
PeriphClkInit.RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048;
#elif defined(RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC)
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC;
PeriphClkInit.RTCWDGSUBGLPAWURLCDLCSCClockSelection = RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSE;
} else if (source == HSI_CLOCK) {
/* Enable the clock if not already set by user */
enableClock(HSI_CLOCK);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC;
PeriphClkInit.RTCWDGSUBGLPAWURLCDLCSCClockSelection = RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512;
#else
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
Expand Down Expand Up @@ -251,6 +259,9 @@ static void RTC_initClock(sourceClock_t source)
#if defined(RCC_PERIPHCLK_RTC_WDG_BLEWKUP)
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP;
PeriphClkInit.RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSI;
#elif defined(RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC)
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC;
PeriphClkInit.RTCWDGSUBGLPAWURLCDLCSCClockSelection = RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSI;
#else
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
Expand Down Expand Up @@ -536,6 +547,13 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
(oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) ? HSI_CLOCK :
// default case corresponding to no clock source
0xFFFFFFFF);
#elif defined(__HAL_RCC_GET_RTC_SUBG_LPAWUR_LCD_LCSC_CLK_CONFIG)
uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_SUBG_LPAWUR_LCD_LCSC_CLK_CONFIG();
oldRtcClockSource = ((oldRtcClockSource == RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSE) ? LSE_CLOCK :
(oldRtcClockSource == RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSI) ? LSI_CLOCK :
(oldRtcClockSource == RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512) ? HSI_CLOCK :
// default case corresponding to no clock source
0xFFFFFFFF);
#else
uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_SOURCE();
oldRtcClockSource = ((oldRtcClockSource == RCC_RTCCLKSOURCE_LSE) ? LSE_CLOCK :
Expand Down Expand Up @@ -1223,7 +1241,7 @@ void RTC_Alarm_IRQHandler(void)
defined(STM32F030xC) || defined(STM32G0xx) || defined(STM32H5xx) || \
defined(STM32L0xx) || defined(STM32L5xx) || defined(STM32U0xx) ||\
defined(STM32U3xx) || defined(STM32U5xx) || defined(STM32WB0x) || \
defined(STM32WBAxx)
defined(STM32WBAxx) || defined(STM32WL3x)
// In some cases, the same vector is used to manage WakeupTimer,
// but with a dedicated HAL IRQHandler
HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
Expand Down
4 changes: 2 additions & 2 deletions src/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ typedef void(*voidCallbackPtr)(void *);
#if defined(STM32C0xx) || defined(STM32F0xx) || defined(STM32H5xx) || \
defined(STM32L0xx) || defined(STM32L5xx) || defined(STM32U3xx) || \
defined(STM32U3xx) || defined(STM32U5xx) || defined(STM32WB0x) || \
defined(STM32WBAxx)
defined(STM32WBAxx) || defined(STM32WL3x)
#define RTC_Alarm_IRQn RTC_IRQn
#define RTC_Alarm_IRQHandler RTC_IRQHandler
#endif
Expand All @@ -144,7 +144,7 @@ typedef void(*voidCallbackPtr)(void *);
#if defined(STM32F1xx) || (defined(STM32F0xx) && defined(RTC_CR_WUTE)) || \
defined(STM32H5xx) || defined(STM32L0xx) || defined(STM32L5xx) || \
defined(STM32U3xx) || defined(STM32U5xx) || defined(STM32WB0x) || \
defined(STM32WBAxx)
defined(STM32WBAxx) || defined(STM32WL3x)
// specific WakeUp interrupt
#define ONESECOND_IRQn RTC_IRQn
#elif defined(STM32MP1xx)
Expand Down