Skip to content

Commit 78a4c01

Browse files
committed
[rcc] Add HSE prescaler to RTC clock source
1 parent 89f387f commit 78a4c01

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/modm/platform/clock/stm32/module.lb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def build(env):
8989
(target["family"] == "l4" and target["name"][0] in ["p", "q", "r", "s"])
9090
properties["pllsai_p_usb"] = (target["family"] == "f7") or \
9191
((target["family"] == "f4") and target["name"] in ["46", "69", "79"])
92+
properties["rtcpre"] = target.family in ["f2", "f4", "f7", "h7", "l0", "l1"]
93+
properties["cfgr_rtc"] = "CR" if target.family in ["l0", "l1"] else \
94+
("CFGR1" if target.family in ["h5"] else "CFGR")
95+
9296

9397
if target.family in ["h7"]:
9498
if target.name in ["a3", "b0", "b3"]:

src/modm/platform/clock/stm32/rcc.hpp.in

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ public:
204204
LowSpeedExternalClock = Lse,
205205
LowSpeedExternalCrystal = Lse
206206
};
207+
%% if target.family in ["l0", "l1"]
208+
enum class
209+
RealTimeClockHsePrescaler : uint8_t
210+
{
211+
Div2 = 0,
212+
Div4 = 1,
213+
Div8 = 2,
214+
Div16 = 3,
215+
};
216+
%% endif
207217

208218
enum class
209219
WatchdogClockSource : uint32_t
@@ -788,8 +798,11 @@ public:
788798
enableSystemClock(SystemClockSource src, uint32_t waitCycles = 2048);
789799

790800
static inline bool
791-
enableRealTimeClock(RealTimeClockSource src)
801+
enableRealTimeClock(RealTimeClockSource src{% if rtcpre %}, {% if target.family in ["l0", "l1"] %}RealTimeClockHsePrescaler hseDiv = RealTimeClockHsePrescaler::Div16{% else %}uint8_t hseDiv = 0xff{% endif %}{% endif %})
792802
{
803+
%% if rtcpre
804+
RCC->{{cfgr_rtc}} = (RCC->{{cfgr_rtc}} & ~RCC_{{cfgr_rtc}}_RTCPRE_Msk) | ((uint8_t(hseDiv) << RCC_{{cfgr_rtc}}_RTCPRE_Pos) & RCC_{{cfgr_rtc}}_RTCPRE_Msk);
805+
%% endif
793806
RCC->{{bdcr}} = (RCC->{{bdcr}} & ~RCC_{{bdcr}}_RTCSEL) | RCC_{{bdcr}}_RTCEN | uint32_t(src);
794807
return true;
795808
}

0 commit comments

Comments
 (0)