34 #include <libopencm3/stm32/gpio.h>
35 #include <libopencm3/stm32/rcc.h>
36 #include <libopencm3/stm32/timer.h>
37 #include <libopencm3/stm32/flash.h>
38 #include <libopencm3/cm3/scb.h>
44 const clock_scale_t hse_24mhz_3v3[CLOCK_3V3_END] = {
50 .hpre = RCC_CFGR_HPRE_DIV_NONE,
51 .ppre1 = RCC_CFGR_PPRE_DIV_4,
52 .ppre2 = RCC_CFGR_PPRE_DIV_2,
54 .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE |
55 FLASH_ACR_LATENCY_3WS,
56 .apb1_frequency = 12000000,
57 .apb2_frequency = 24000000,
64 .hpre = RCC_CFGR_HPRE_DIV_NONE,
65 .ppre1 = RCC_CFGR_PPRE_DIV_4,
66 .ppre2 = RCC_CFGR_PPRE_DIV_2,
68 .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE |
69 FLASH_ACR_LATENCY_3WS,
70 .apb1_frequency = 30000000,
71 .apb2_frequency = 60000000,
78 .hpre = RCC_CFGR_HPRE_DIV_NONE,
79 .ppre1 = RCC_CFGR_PPRE_DIV_4,
80 .ppre2 = RCC_CFGR_PPRE_DIV_2,
81 .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE |
82 FLASH_ACR_LATENCY_5WS,
83 .apb1_frequency = 42000000,
84 .apb2_frequency = 84000000,
92 PRINT_CONFIG_MSG(
"We are running luftboot, the interrupt vector is being relocated.")
94 SCB_VTOR = 0x00004000;
96 SCB_VTOR = 0x00002000;
99 #if EXT_CLK == 8000000
102 rcc_clock_setup_in_hse_8mhz_out_72mhz();
103 #elif defined(STM32F4)
105 rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);
107 #elif EXT_CLK == 12000000
110 rcc_clock_setup_in_hse_12mhz_out_72mhz();
111 #elif defined(STM32F4)
113 rcc_clock_setup_hse_3v3(&hse_12mhz_3v3[CLOCK_3V3_168MHZ]);
115 #elif EXT_CLK == 16000000
118 rcc_clock_setup_hse_3v3(&hse_16mhz_3v3[CLOCK_3V3_168MHZ]);
120 #elif EXT_CLK == 24000000
123 rcc_clock_setup_hse_3v3(&hse_24mhz_3v3[CLOCK_3V3_168MHZ]);
125 #elif EXT_CLK == 25000000
128 rcc_clock_setup_hse_3v3(&hse_25mhz_3v3[CLOCK_3V3_168MHZ]);
131 #error EXT_CLK is either set to an unsupported frequency or not defined at all. Please check!
138 #ifndef RTOS_IS_CHIBIOS
139 scb_set_priority_grouping(SCB_AIRCR_PRIGROUP_NOGROUP_SUB16);
145 #define RCC_CFGR_PPRE2_SHIFT 11
146 #define RCC_CFGR_PPRE2 (7 << RCC_CFGR_PPRE2_SHIFT)
148 #define RCC_CFGR_PPRE1_SHIFT 8
149 #define RCC_CFGR_PPRE1 (7 << RCC_CFGR_PPRE1_SHIFT)
151 static inline uint32_t rcc_get_ppre1(
void)
153 return RCC_CFGR & RCC_CFGR_PPRE1;
156 static inline uint32_t rcc_get_ppre2(
void)
158 return RCC_CFGR & RCC_CFGR_PPRE2;
160 #elif defined(STM32F4)
161 static inline uint32_t rcc_get_ppre1(
void)
163 return RCC_CFGR & ((1 << 10) | (1 << 11) | (1 << 12));
166 static inline uint32_t rcc_get_ppre2(
void)
168 return RCC_CFGR & ((1 << 13) | (1 << 14) | (1 << 15));
181 switch (timer_peripheral) {
194 if (!rcc_get_ppre2())
197 return rcc_apb2_frequency;
200 return rcc_apb2_frequency * 2;
219 if (!rcc_get_ppre1())
222 return rcc_apb1_frequency;
225 return rcc_apb1_frequency * 2;
uint32_t timer_get_frequency(uint32_t timer_peripheral)
Get Timer clock frequency (before prescaling) Only valid if using the internal clock for the timer...
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
Arch independent mcu ( Micro Controller Unit ) utilities.