21 #ifndef ARCH_RCC_HPP_INCLUDED 22 #define ARCH_RCC_HPP_INCLUDED 72 template<
typename... Tp >
86 cfg_list::template strict_reset_to<
102 template< freq_t output_freq, freq_t hse_freq >
106 static constexpr
unsigned p = 2;
107 static constexpr
unsigned m = hse_freq / vco_input;
108 static constexpr
unsigned n = (output_freq / vco_input ) * p;
109 static constexpr
unsigned q = n / 48 + (n % 48 ? 1 : 0);
111 static_assert(p==2 || p==4 || p==6 || p==8,
"illegal PLLP value");
112 static_assert(q >= 2 && q <= 15,
"illegal PLLQ value");
113 static_assert(n >= 192 && n <= 432,
"illegal PLLN value");
114 static_assert(m >= 2 && m <= 63,
"illegal PLLM value");
116 static constexpr
freq_t vco_output = vco_input * n;
117 static constexpr
freq_t pll_output = vco_output / p;
118 static constexpr
freq_t pll48clk = vco_output / q;
120 static_assert(vco_input >=
mhz(1) && vco_input <=
mhz(2),
"illegal VCO input frequency");
121 static_assert(vco_output >=
mhz(192) && vco_output <=
mhz(432),
"illegal VCO output frequency");
122 static_assert(pll_output <=
mhz(168),
"illegal PLL output frequency");
125 static constexpr
bool usb_otg_available = ( pll48clk ==
mhz(48) );
129 static constexpr
bool sdio_available = ( pll48clk <=
mhz(48) );
130 static constexpr
bool rng_available = ( pll48clk <=
mhz(48) );
133 static_assert(usb_otg_available,
"USB OTG FS is not available");
134 static_assert(sdio_available,
"SDIO is not available");
135 static_assert(rng_available,
"RNG is not available");
144 #ifdef OPENMPTL_SIMULATION 146 std::cout << std::dec <<
"--------------------" << std::endl;
147 std::cout <<
"HCLK = " << output_freq /
mhz(1) <<
" MHz" << std::endl;
148 std::cout <<
"HSE = " << hse_freq /
mhz(1) <<
" MHz" << std::endl;
149 std::cout << std::dec <<
"--------------------" << std::endl;
151 std::cout <<
"m=" << m << std::endl;
152 std::cout <<
"n=" << n << std::endl;
153 std::cout <<
"p=" << p << std::endl;
154 std::cout <<
"q=" << q << std::endl;
156 std::cout <<
"vco_input = " << (vco_input /
mhz(1)) <<
" MHz" << std::endl;
157 std::cout <<
"vco_output = " << (vco_output /
mhz(1)) <<
" MHz" << std::endl;
158 std::cout <<
"pll_output = " << (pll_output /
mhz(1)) <<
" MHz" << std::endl;
159 std::cout <<
"pll48clk = " << (pll48clk /
mhz(1)) <<
" MHz" << std::endl;
176 template< freq_t output_freq, freq_t hse_freq = mhz(8) >
179 RCC::CFGR::HPRE ::DIV1,
180 RCC::CFGR::PPRE1::DIV4,
181 RCC::CFGR::PPRE2::DIV2,
182 typename system_clock_pllcfgr< output_freq, hse_freq >::type
185 static_assert( output_freq <=
mhz(168),
"illegal output (HCLK) frequency" );
186 static_assert( hse_freq >=
mhz(4) && hse_freq <=
mhz(26),
"illegal HSE frequency" );
188 static constexpr
freq_t hclk_freq = output_freq;
189 static constexpr
freq_t pclk1_freq = hclk_freq / 4;
190 static constexpr
freq_t pclk2_freq = hclk_freq / 2;
221 #endif // ARCH_RCC_HPP_INCLUDED static __always_inline void set(void)
Clock configuration register.
Definition: rcc.hpp:78
static void init(void)
Definition: rcc.hpp:80
Generic HSE system clock setup.
Definition: rcc.hpp:177
static bool wait_hse_ready(unsigned timeout)
Definition: rcc.hpp:50
static void configure(void)
Definition: rcc.hpp:85
static __always_inline bool test(void)
static bool wait_hsi_ready(unsigned timeout)
Definition: rcc.hpp:60
reglist< regval< RCC::PLLCFGR::PLLM, m >, regval< RCC::PLLCFGR::PLLN, n >, regval< RCC::PLLCFGR::PLLP,(p > > 1) - 1 >, regval< RCC::PLLCFGR::PLLQ, q > > type
Definition: rcc.hpp:142
static void wait_hse_ready()
Definition: rcc.hpp:47
static constexpr freq_t mhz(unsigned long long x)
PLL configuration with fixed PLLP=2.
Definition: rcc.hpp:103
static void wait_hsi_ready()
Definition: rcc.hpp:57
PLL configuration register.
Definition: rcc.hpp:65