From 1c03e64c000b2fe89179ae67a26c6ac97435796a Mon Sep 17 00:00:00 2001 From: Christopher Durand Date: Fri, 29 Apr 2022 15:06:05 +0200 Subject: [PATCH 1/2] [stm32] Add Gpio connect() method for clock output to RCC driver --- src/modm/platform/clock/stm32/rcc.hpp.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modm/platform/clock/stm32/rcc.hpp.in b/src/modm/platform/clock/stm32/rcc.hpp.in index a3389bcc5e..49e8106546 100644 --- a/src/modm/platform/clock/stm32/rcc.hpp.in +++ b/src/modm/platform/clock/stm32/rcc.hpp.in @@ -3,7 +3,7 @@ * Copyright (c) 2012, 2017, Fabian Greif * Copyright (c) 2012, 2014-2017, Niklas Hauser * Copyright (c) 2013-2014, Kevin Läufer - * Copyright (c) 2018, 2021, Christopher Durand + * Copyright (c) 2018, 2021-2022, Christopher Durand * * This file is part of the modm project. * @@ -19,6 +19,7 @@ #include #include "../device.hpp" #include +#include #include namespace modm::platform @@ -843,6 +844,14 @@ public: static void updateCoreFrequency(); + template< class... Signals > + static void + connect() + { + using Connector = GpioConnector; + Connector::connect(); + } + public: template< Peripheral peripheral > static void From 6e7c12f8bdda328acf22376f88d62a7d0928b3e7 Mon Sep 17 00:00:00 2001 From: Christopher Durand Date: Fri, 29 Apr 2022 15:07:07 +0200 Subject: [PATCH 2/2] [stm32] Fix STM32H7 RCC clock output configuration --- src/modm/platform/clock/stm32/rcc.hpp.in | 42 ++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/modm/platform/clock/stm32/rcc.hpp.in b/src/modm/platform/clock/stm32/rcc.hpp.in index 49e8106546..b91529ef38 100644 --- a/src/modm/platform/clock/stm32/rcc.hpp.in +++ b/src/modm/platform/clock/stm32/rcc.hpp.in @@ -318,7 +318,7 @@ public: }; %% endif -%% if target.family in ["f2", "f4", "f7", "h7"] +%% if target.family in ["f2", "f4", "f7"] enum class ClockOutput1Source : uint32_t { @@ -338,6 +338,27 @@ public: Pll = RCC_CFGR_MCO2_1 | RCC_CFGR_MCO2_0, }; %% endif +%% elif target.family in ["h7"] + enum class + ClockOutput1Source : uint32_t + { + Hsi = 0, + Lse = RCC_CFGR_MCO1_0, + Hse = RCC_CFGR_MCO1_1, + Pll1Q = RCC_CFGR_MCO1_1 | RCC_CFGR_MCO1_0, + Hsi48 = RCC_CFGR_MCO1_2 + }; + + enum class + ClockOutput2Source : uint32_t + { + SystemClock = 0, + Pll2P = RCC_CFGR_MCO2_0, + Hse = RCC_CFGR_MCO2_1, + Pll = RCC_CFGR_MCO2_1 | RCC_CFGR_MCO2_0, + Csi = RCC_CFGR_MCO2_2, + Lsi = RCC_CFGR_MCO2_2 | RCC_CFGR_MCO2_0 + }; %% elif target.family in ["l0", "l1", "l4", "l5", "g0", "g4"] enum class ClockOutputSource : uint32_t @@ -654,7 +675,7 @@ public: } %% endif -%% if target.family in ["f2", "f4", "f7", "h7"] +%% if target.family in ["f2", "f4", "f7"] static inline bool enableClockOutput1(ClockOutput1Source src, uint8_t div) { @@ -674,7 +695,24 @@ public: return true; } %% endif +%% elif target.family in ["h7"] + static inline bool + enableClockOutput1(ClockOutput1Source src, uint8_t div) + { + uint32_t tmp = RCC->CFGR & ~(RCC_CFGR_MCO1 | RCC_CFGR_MCO1PRE); + if (div > 1) tmp |= (div << 18); + RCC->CFGR = tmp | uint32_t(src); + return true; + } + static inline bool + enableClockOutput2(ClockOutput2Source src, uint8_t div) + { + uint32_t tmp = RCC->CFGR & ~(RCC_CFGR_MCO2 | RCC_CFGR_MCO2PRE); + if (div > 1) tmp |= (div << 25); + RCC->CFGR = tmp | uint32_t(src); + return true; + } %% elif target.family in ["l0", "l1", "l4", "l5", "g0", "g4"] enum class ClockOutputPrescaler : uint32_t