99 */
1010// ----------------------------------------------------------------------------
1111
12- #ifndef MODM_STM32_F4X1CEU_MINI_F4X1_HPP
13- #define MODM_STM32_F4X1CEU_MINI_F4X1_HPP
12+ #pragma once
1413
1514#include <modm/platform.hpp>
1615#include <modm/architecture/interface/clock.hpp>
@@ -19,36 +18,69 @@ using namespace modm::platform;
1918
2019namespace Board
2120{
22- // / @ingroup modm_board_black_pill_f401 modm_board_black_pill_f411
21+ /// @ingroup modm_board_black_pill_f4{{target.name}}
2322/// @{
2423using namespace modm::literals;
2524
26- // / STM32F4x1 running at 84MHz generated from the external 25MHz crystal
25+ /// STM32F4{{target.name}} running at {% if target.name == "11" %}96{% else %}84{% endif %}MHz generated from the external 25MHz crystal
2726struct SystemClock
2827{
29- static constexpr uint32_t Frequency = 84_MHz;
28+ static constexpr uint32_t Hse = 25_MHz;
29+ static constexpr uint32_t Lse = 32.768_kHz;
30+ static constexpr Rcc::PllConfig pll
31+ {
32+ .M = 25, // 25 MHz / 25 = 1 MHz
33+ %% if target.name == "11"
34+ .N = 384, // 1 MHz * 384 = 384 MHz
35+ .P = 4, // 384 MHz / 4 = 96 MHz = F_cpu
36+ .Q = 8, // 384 MHz / 8 = 48 MHz = F_usb
37+ %% else
38+ .N = 336, // 1 MHz * 336 = 336 MHz
39+ .P = 4, // 336 MHz / 4 = 84 MHz = F_cpu
40+ .Q = 7, // 336 MHz / 7 = 48 MHz = F_usb
41+ %% endif
42+ };
43+ static constexpr uint32_t PllP = Hse / pll.M * pll.N / pll.P;
44+ static constexpr uint32_t PllQ = Hse / pll.M * pll.N / pll.Q;
45+ static_assert(PllP == {% if target.name == "11" %}96_MHz{% else %}Rcc::MaxFrequency{% endif %});
46+
47+ static constexpr uint32_t Frequency = PllP;
3048 static constexpr uint32_t Ahb = Frequency;
3149 static constexpr uint32_t Apb1 = Frequency / 2;
3250 static constexpr uint32_t Apb2 = Frequency;
33-
34- static constexpr uint32_t Adc = Apb2;
35-
36- static constexpr uint32_t Spi1 = Apb2;
51+ static constexpr uint32_t Ahb1 = Ahb;
52+
53+ static constexpr uint32_t Crc = Ahb1;
54+ static constexpr uint32_t Dma1 = Ahb1;
55+ static constexpr uint32_t Dma2 = Ahb1;
56+ static constexpr uint32_t Flash = Ahb1;
57+
58+ static constexpr uint32_t I2c1 = Apb1;
59+ static constexpr uint32_t I2c2 = Apb1;
60+ static constexpr uint32_t I2c3 = Apb1;
61+ static constexpr uint32_t I2s2Ext = Apb1;
62+ static constexpr uint32_t I2s3Ext = Apb1;
63+ static constexpr uint32_t IwdgBus = Apb1;
64+ static constexpr uint32_t Pwr = Apb1;
65+ static constexpr uint32_t RtcBus = Apb1;
3766 static constexpr uint32_t Spi2 = Apb1;
3867 static constexpr uint32_t Spi3 = Apb1;
68+ static constexpr uint32_t Usart2 = Apb1;
69+ static constexpr uint32_t Wwdg = Apb1;
70+
71+ static constexpr uint32_t Adc = Apb2;
72+ static constexpr uint32_t Adc1Common = Apb2;
73+ static constexpr uint32_t Exti = Apb2;
74+ static constexpr uint32_t Sdio = Apb2;
75+ static constexpr uint32_t Spi1 = Apb2;
3976 static constexpr uint32_t Spi4 = Apb2;
4077 static constexpr uint32_t Spi5 = Apb2;
41-
78+ static constexpr uint32_t Syscfg = Apb2;
4279 static constexpr uint32_t Usart1 = Apb2;
43- static constexpr uint32_t Usart2 = Apb1;
4480 static constexpr uint32_t Usart6 = Apb2;
4581
46- static constexpr uint32_t I2c1 = Apb1;
47- static constexpr uint32_t I2c2 = Apb1;
48- static constexpr uint32_t I2c3 = Apb1;
49-
5082 static constexpr uint32_t Apb1Timer = Apb1 * 2;
51- static constexpr uint32_t Apb2Timer = Apb2 * 1 ;
83+ static constexpr uint32_t Apb2Timer = Apb2 * 2 ;
5284 static constexpr uint32_t Timer1 = Apb2Timer;
5385 static constexpr uint32_t Timer2 = Apb1Timer;
5486 static constexpr uint32_t Timer3 = Apb1Timer;
@@ -58,37 +90,26 @@ struct SystemClock
5890 static constexpr uint32_t Timer10 = Apb2Timer;
5991 static constexpr uint32_t Timer11 = Apb2Timer;
6092
61- static constexpr uint32_t Usb = 48_MHz ;
93+ static constexpr uint32_t Usb = PllQ ;
6294 static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
63- static constexpr uint32_t Rtc = 32 .768_kHz ;
95+ static constexpr uint32_t Rtc = Lse ;
6496
6597 static bool inline
6698 enable()
6799 {
68- Rcc::enableLowSpeedExternalCrystal ();
69- Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::LowSpeedExternalCrystal);
70-
71- Rcc::enableExternalCrystal ();
72- const Rcc::PllFactors pllFactors{
73- .pllM = 25 , // 25MHz / M=25 -> 1MHz
74- .pllN = 336 , // 1MHz * N=336 -> 336MHz
75- .pllP = 4 , // 336MHz / P=4 -> 84MHz = F_cpu
76- .pllQ = 7 , // 336MHz / Q=7 -> 48MHz = F_usb
77- };
78- Rcc::enablePll (Rcc::PllSource::ExternalCrystal, pllFactors);
79-
80- // set flash latency
81- Rcc::setFlashLatency<Frequency>();
100+ Rcc::enableLseCrystal();
101+ Rcc::enableHseCrystal();
82102
83- // switch system clock to PLL output
84- Rcc::enableSystemClock (Rcc::SystemClockSource::Pll );
103+ Rcc::setFlashLatency<Frequency>();
104+ Rcc::updateCoreFrequency<Frequency>( );
85105
86106 Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
87- Rcc::setApb1Prescaler (Rcc::Apb1Prescaler ::Div2);
88- Rcc::setApb2Prescaler (Rcc::Apb2Prescaler ::Div1);
107+ Rcc::setApb1Prescaler(Rcc::ApbPrescaler ::Div2);
108+ Rcc::setApb2Prescaler(Rcc::ApbPrescaler ::Div1);
89109
90- // update frequencies for busy-wait delay functions
91- Rcc::updateCoreFrequency<Frequency>();
110+ Rcc::enablePll(Rcc::PllSource::Hse, pll);
111+ Rcc::enableSystemClock(Rcc::SystemClockSource::PllP);
112+ Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::Lse);
92113
93114 return true;
94115 }
@@ -97,7 +118,7 @@ struct SystemClock
97118
98119namespace usb
99120{
100- // / @ingroup modm_board_black_pill_f401 modm_board_black_pill_f411
121+ /// @ingroup modm_board_black_pill_f4{{target.name}}
101122/// @{
102123using Id = GpioA10;
103124using Dm = GpioA11;
@@ -107,7 +128,7 @@ using Device = UsbFs;
107128/// @}
108129}
109130
110- // / @ingroup modm_board_black_pill_f401 modm_board_black_pill_f411
131+ /// @ingroup modm_board_black_pill_f4{{target.name}}
111132/// @{
112133using Led = GpioInverted< GpioOutputC13 >;
113134using Leds = SoftwareGpioPort< Led >;
@@ -145,5 +166,3 @@ initializeUsbFs(uint8_t priority=3)
145166/// @}
146167
147168} // Board namespace
148-
149- #endif // MODM_STM32_F4X1CEU_MINI_F4X1_HPP
0 commit comments