Skip to content

Commit 6e7c12f

Browse files
committed
[stm32] Fix STM32H7 RCC clock output configuration
1 parent 1c03e64 commit 6e7c12f

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public:
318318
};
319319
%% endif
320320

321-
%% if target.family in ["f2", "f4", "f7", "h7"]
321+
%% if target.family in ["f2", "f4", "f7"]
322322
enum class
323323
ClockOutput1Source : uint32_t
324324
{
@@ -338,6 +338,27 @@ public:
338338
Pll = RCC_CFGR_MCO2_1 | RCC_CFGR_MCO2_0,
339339
};
340340
%% endif
341+
%% elif target.family in ["h7"]
342+
enum class
343+
ClockOutput1Source : uint32_t
344+
{
345+
Hsi = 0,
346+
Lse = RCC_CFGR_MCO1_0,
347+
Hse = RCC_CFGR_MCO1_1,
348+
Pll1Q = RCC_CFGR_MCO1_1 | RCC_CFGR_MCO1_0,
349+
Hsi48 = RCC_CFGR_MCO1_2
350+
};
351+
352+
enum class
353+
ClockOutput2Source : uint32_t
354+
{
355+
SystemClock = 0,
356+
Pll2P = RCC_CFGR_MCO2_0,
357+
Hse = RCC_CFGR_MCO2_1,
358+
Pll = RCC_CFGR_MCO2_1 | RCC_CFGR_MCO2_0,
359+
Csi = RCC_CFGR_MCO2_2,
360+
Lsi = RCC_CFGR_MCO2_2 | RCC_CFGR_MCO2_0
361+
};
341362
%% elif target.family in ["l0", "l1", "l4", "l5", "g0", "g4"]
342363
enum class
343364
ClockOutputSource : uint32_t
@@ -654,7 +675,7 @@ public:
654675
}
655676
%% endif
656677

657-
%% if target.family in ["f2", "f4", "f7", "h7"]
678+
%% if target.family in ["f2", "f4", "f7"]
658679
static inline bool
659680
enableClockOutput1(ClockOutput1Source src, uint8_t div)
660681
{
@@ -674,7 +695,24 @@ public:
674695
return true;
675696
}
676697
%% endif
698+
%% elif target.family in ["h7"]
699+
static inline bool
700+
enableClockOutput1(ClockOutput1Source src, uint8_t div)
701+
{
702+
uint32_t tmp = RCC->CFGR & ~(RCC_CFGR_MCO1 | RCC_CFGR_MCO1PRE);
703+
if (div > 1) tmp |= (div << 18);
704+
RCC->CFGR = tmp | uint32_t(src);
705+
return true;
706+
}
677707

708+
static inline bool
709+
enableClockOutput2(ClockOutput2Source src, uint8_t div)
710+
{
711+
uint32_t tmp = RCC->CFGR & ~(RCC_CFGR_MCO2 | RCC_CFGR_MCO2PRE);
712+
if (div > 1) tmp |= (div << 25);
713+
RCC->CFGR = tmp | uint32_t(src);
714+
return true;
715+
}
678716
%% elif target.family in ["l0", "l1", "l4", "l5", "g0", "g4"]
679717
enum class
680718
ClockOutputPrescaler : uint32_t

0 commit comments

Comments
 (0)