Skip to content

Commit 5870df0

Browse files
committed
feat: add STM32WL3x support
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 9bbfbfc commit 5870df0

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/STM32RTC.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void STM32RTC::begin(bool resetTime, Hour_Format format)
6262
bool reinit;
6363

6464
_format = format;
65-
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
65+
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
6666
reinit = RTC_init((format == HOUR_12) ? HOUR_FORMAT_12 : HOUR_FORMAT_24,
6767
(_mode == MODE_MIX) ? ::MODE_BINARY_MIX : ((_mode == MODE_BIN) ? ::MODE_BINARY_ONLY : ::MODE_BINARY_NONE),
6868
(_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
@@ -74,7 +74,7 @@ void STM32RTC::begin(bool resetTime, Hour_Format format)
7474
(_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
7575
(_clockSource == HSE_CLOCK) ? ::HSE_CLOCK : ::LSI_CLOCK
7676
, resetTime);
77-
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
77+
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
7878
_timeSet = !reinit;
7979

8080
syncDate();
@@ -145,13 +145,13 @@ void STM32RTC::setClockSource(Source_Clock source, uint32_t predivA, uint32_t pr
145145
{
146146
if (IS_CLOCK_SOURCE(source)) {
147147
_clockSource = source;
148-
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
148+
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
149149
RTC_SetClockSource((_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
150150
(_clockSource == HSI_CLOCK) ? ::HSI_CLOCK : ::LSI_CLOCK);
151151
#else
152152
RTC_SetClockSource((_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
153153
(_clockSource == HSE_CLOCK) ? ::HSE_CLOCK : ::LSI_CLOCK);
154-
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
154+
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
155155
}
156156
RTC_setPrediv(predivA, predivS);
157157
}

src/STM32RTC.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868

6969
typedef void(*voidFuncPtr)(void *);
7070

71-
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
71+
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
7272
#define IS_CLOCK_SOURCE(SRC) (((SRC) == STM32RTC::LSI_CLOCK) || ((SRC) == STM32RTC::LSE_CLOCK) ||\
7373
((SRC) == STM32RTC::HSI_CLOCK))
7474
#else
7575
#define IS_CLOCK_SOURCE(SRC) (((SRC) == STM32RTC::LSI_CLOCK) || ((SRC) == STM32RTC::LSE_CLOCK) ||\
7676
((SRC) == STM32RTC::HSE_CLOCK))
77-
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
77+
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
7878
#define IS_HOUR_FORMAT(FMT) (((FMT) == STM32RTC::HOUR_12) || ((FMT) == STM32RTC::HOUR_24))
7979

8080
class STM32RTC {
@@ -112,11 +112,11 @@ class STM32RTC {
112112
enum Source_Clock : uint8_t {
113113
LSI_CLOCK = ::LSI_CLOCK,
114114
LSE_CLOCK = ::LSE_CLOCK,
115-
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048)
115+
#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
116116
HSI_CLOCK = ::HSI_CLOCK,
117117
#else
118118
HSE_CLOCK = ::HSE_CLOCK
119-
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 */
119+
#endif /* RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 || RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512 */
120120
};
121121

122122
enum Alarm : uint32_t {

src/rtc.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ static void RTC_initClock(sourceClock_t source)
205205
enableClock(HSI_CLOCK);
206206
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP;
207207
PeriphClkInit.RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048;
208+
#elif defined(RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC)
209+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC;
210+
PeriphClkInit.RTCWDGSUBGLPAWURLCDLCSCClockSelection = RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSE;
211+
} else if (source == HSI_CLOCK) {
212+
/* Enable the clock if not already set by user */
213+
enableClock(HSI_CLOCK);
214+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC;
215+
PeriphClkInit.RTCWDGSUBGLPAWURLCDLCSCClockSelection = RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512;
208216
#else
209217
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
210218
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
@@ -251,6 +259,9 @@ static void RTC_initClock(sourceClock_t source)
251259
#if defined(RCC_PERIPHCLK_RTC_WDG_BLEWKUP)
252260
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP;
253261
PeriphClkInit.RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSI;
262+
#elif defined(RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC)
263+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_SUBG_LPAWUR_LCD_LCSC;
264+
PeriphClkInit.RTCWDGSUBGLPAWURLCDLCSCClockSelection = RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSI;
254265
#else
255266
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
256267
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
@@ -536,6 +547,13 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
536547
(oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) ? HSI_CLOCK :
537548
// default case corresponding to no clock source
538549
0xFFFFFFFF);
550+
#elif defined(__HAL_RCC_GET_RTC_SUBG_LPAWUR_LCD_LCSC_CLK_CONFIG)
551+
uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_SUBG_LPAWUR_LCD_LCSC_CLK_CONFIG();
552+
oldRtcClockSource = ((oldRtcClockSource == RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSE) ? LSE_CLOCK :
553+
(oldRtcClockSource == RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_LSI) ? LSI_CLOCK :
554+
(oldRtcClockSource == RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512) ? HSI_CLOCK :
555+
// default case corresponding to no clock source
556+
0xFFFFFFFF);
539557
#else
540558
uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_SOURCE();
541559
oldRtcClockSource = ((oldRtcClockSource == RCC_RTCCLKSOURCE_LSE) ? LSE_CLOCK :
@@ -1223,7 +1241,7 @@ void RTC_Alarm_IRQHandler(void)
12231241
defined(STM32F030xC) || defined(STM32G0xx) || defined(STM32H5xx) || \
12241242
defined(STM32L0xx) || defined(STM32L5xx) || defined(STM32U0xx) ||\
12251243
defined(STM32U3xx) || defined(STM32U5xx) || defined(STM32WB0x) || \
1226-
defined(STM32WBAxx)
1244+
defined(STM32WBAxx) || defined(STM32WL3x)
12271245
// In some cases, the same vector is used to manage WakeupTimer,
12281246
// but with a dedicated HAL IRQHandler
12291247
HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);

src/rtc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ typedef void(*voidCallbackPtr)(void *);
131131
#if defined(STM32C0xx) || defined(STM32F0xx) || defined(STM32H5xx) || \
132132
defined(STM32L0xx) || defined(STM32L5xx) || defined(STM32U3xx) || \
133133
defined(STM32U3xx) || defined(STM32U5xx) || defined(STM32WB0x) || \
134-
defined(STM32WBAxx)
134+
defined(STM32WBAxx) || defined(STM32WL3x)
135135
#define RTC_Alarm_IRQn RTC_IRQn
136136
#define RTC_Alarm_IRQHandler RTC_IRQHandler
137137
#endif
@@ -144,7 +144,7 @@ typedef void(*voidCallbackPtr)(void *);
144144
#if defined(STM32F1xx) || (defined(STM32F0xx) && defined(RTC_CR_WUTE)) || \
145145
defined(STM32H5xx) || defined(STM32L0xx) || defined(STM32L5xx) || \
146146
defined(STM32U3xx) || defined(STM32U5xx) || defined(STM32WB0x) || \
147-
defined(STM32WBAxx)
147+
defined(STM32WBAxx) || defined(STM32WL3x)
148148
// specific WakeUp interrupt
149149
#define ONESECOND_IRQn RTC_IRQn
150150
#elif defined(STM32MP1xx)

0 commit comments

Comments
 (0)