Skip to content

Commit e39bca4

Browse files
committed
[stm32] add missing HSI48-related functionality
1 parent ab7c1ca commit e39bca4

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ def build(env):
6969
properties["pllprediv2"] = False # FIXME: not sure what value this should have
7070
properties["pll_hse_prediv2"] = target["family"] == "f1" and target["name"] in ["01", "02", "03"]
7171
properties["hsi48"] = \
72+
(target["family"] in ["g4", "h5", "h7", "l5", "u0", "u5"]) or \
7273
(target["family"] == "f0" and target["name"] in ["42", "48", "71", "72", "78", "91", "98"]) or \
73-
(target["family"] == "l4" and target["name"][0] not in ["7", "8"]) or \
74-
(target["family"] == "l5") or \
75-
(target["family"] == "u5")
76-
if target["family"] in ["l4", "l5"]:
74+
(target["family"] == "g0" and target["name"] in ["b1", "c1"]) or \
75+
(target["family"] == "l0" and target["name"][1] == "2") or \
76+
(target["family"] == "l4" and target["name"][0] not in ["7", "8"])
77+
if target["family"] in ["g4", "l0", "l4", "l5", "u0"]:
7778
properties["hsi48_cr"] = "CRRCR"
78-
elif target["family"] in ["c0", "u5"]:
79+
elif target["family"] in ["g0", "h5", "h7", "u5"]:
7980
properties["hsi48_cr"] = "CR"
80-
else:
81+
elif target["family"] in ["f0"]:
8182
properties["hsi48_cr"] = "CR2"
8283
properties["pll_p"] = ((target["family"] == "l4" and target["name"] not in ["12", "22"]) or target["family"] == "g4")
8384
properties["overdrive"] = (target["family"] == "f7") or \

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public:
116116
Hsi16 = 0b10,
117117
Hse = 0b11,
118118
%% endif
119-
%% if hsi48 and target.family not in ["l4", "l5", "u5"]
119+
%% if hsi48 and target.family in ["f0"]
120120
/// High speed internal clock (48 MHz)
121121
Hsi48 = RCC_CFGR_PLLSRC_HSI48_PREDIV,
122122
InternalClockMHz48 = Hsi48,
@@ -171,7 +171,7 @@ public:
171171
Hsi16 = Hsi,
172172
%% endif
173173
Hse = RCC_CFGR_SW_HSE,
174-
%% if hsi48 and target.family != "l4"
174+
%% if hsi48 and target.family in ["f0"]
175175
Hsi48 = RCC_CFGR_SW_HSI48,
176176
InternalClockMHz48 = Hsi48,
177177
%% endif
@@ -383,6 +383,12 @@ public:
383383
Pll1Q = 0b10 << RCC_CCIPR1_ICLKSEL_Pos,
384384
Msik = 0b11 << RCC_CCIPR1_ICLKSEL_Pos,
385385
};
386+
%% elif hsi48 and target.family in ["l0"]
387+
enum class Clock48Source
388+
{
389+
PllQ = 0,
390+
Hsi48 = RCC_CCIPR_HSI48SEL,
391+
};
386392
%% endif
387393

388394
%% if target.family in ["f2", "f4", "f7"]
@@ -456,7 +462,7 @@ public:
456462
MultiSpeedInternalClockK = (0b1001 << RCC_{{cfgr_mco}}_MCOSEL_Pos), // MSIK
457463
%% endif
458464
};
459-
%% else
465+
%% elif target.family in ["f0", "f1", "f3"]
460466
enum class
461467
ClockOutputSource : uint32_t
462468
{
@@ -814,6 +820,12 @@ public:
814820
{
815821
RCC->CCIPR1 = (RCC->CCIPR1 & ~RCC_CCIPR1_ICLKSEL_Msk) | uint32_t(source);
816822
}
823+
%% elif hsi48 and target.family in ["l0"]
824+
static inline void
825+
setClock48Source(Clock48Source source)
826+
{
827+
RCC->CCIPR = (RCC->CCIPR & ~RCC_CCIPR_HSI48SEL_Msk) | uint32_t(source);
828+
}
817829
%% endif
818830

819831
%% if target.family == "h7"
@@ -830,6 +842,31 @@ public:
830842
{
831843
RCC->{{d2}}CCIP2R = (RCC->{{d2}}CCIP2R & ~RCC_{{d2}}CCIP2R_USBSEL_Msk) | uint32_t(source);
832844
}
845+
%% elif hsi48 and target.family in ["f0"] and (target.name in ["42", "48", "72", "78"])
846+
enum class
847+
UsbClockSource : uint32_t
848+
{
849+
Hsi48 = 0,
850+
Pll = RCC_CFGR3_USBSW_PLLCLK,
851+
};
852+
static inline void
853+
enableUsbClockSource(UsbClockSource source)
854+
{
855+
RCC->CFGR3 = (RCC->CFGR3 & ~RCC_CFGR3_USBSW_Msk) | uint32_t(source);
856+
}
857+
%% elif hsi48 and target.family in ["g0"]
858+
enum class
859+
UsbClockSource : uint32_t
860+
{
861+
Hsi48 = 0,
862+
Hse = RCC_CCIPR2_USBSEL_0,
863+
Pll = RCC_CCIPR2_USBSEL_1,
864+
};
865+
static inline void
866+
enableUsbClockSource(UsbClockSource source)
867+
{
868+
RCC->CCIPR2 = (RCC->CCIPR2 & ~RCC_CCIPR2_USBSEL_Msk) | uint32_t(source);
869+
}
833870
%% endif
834871

835872
%% if target.family in ["f2", "f4", "f7"]

0 commit comments

Comments
 (0)