diff --git a/sw/airborne/arch/stm32/mcu_arch.c b/sw/airborne/arch/stm32/mcu_arch.c index d7e3a81370..9a3c84f27e 100644 --- a/sw/airborne/arch/stm32/mcu_arch.c +++ b/sw/airborne/arch/stm32/mcu_arch.c @@ -27,69 +27,19 @@ #include BOARD_CONFIG #include -#include -#include -#include -#include +#include #include +#include void mcu_arch_init(void) { -#if USE_OPENCM3 +#if EXT_CLK == 8000000 +#pragma message "Using 8MHz external clock to PLL it to 72MHz." + rcc_clock_setup_in_hse_8mhz_out_72mhz(); +#elif EXT_CLK == 12000000 +#pragma message "Using 12MHz external clock to PLL it to 72MHz." rcc_clock_setup_in_hse_12mhz_out_72mhz(); - NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); - return; -#else // !USE_OPENCM3 -#ifdef HSE_TYPE_EXT_CLK -#pragma message "Using external clock." - /* Setup the microcontroller system. - * Initialize the Embedded Flash Interface, - * initialize the PLL and update the SystemFrequency variable. - */ - /* RCC system reset(for debug purpose) */ - RCC_DeInit(); - /* Enable HSE with external clock ( HSE_Bypass ) */ - RCC_HSEConfig( STM32_RCC_MODE ); - /* Wait till HSE is ready */ - ErrorStatus HSEStartUpStatus = RCC_WaitForHSEStartUp(); - if (HSEStartUpStatus != SUCCESS) { - /* block if something went wrong */ - while(1) {} - } - else { - /* Enable Prefetch Buffer */ - FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); - /* Flash 2 wait state */ - FLASH_SetLatency(FLASH_Latency_2); - /* HCLK = SYSCLK */ - RCC_HCLKConfig(RCC_SYSCLK_Div1); - /* PCLK2 = HCLK */ - RCC_PCLK2Config(RCC_HCLK_Div1); - /* PCLK1 = HCLK/2 */ - RCC_PCLK1Config(RCC_HCLK_Div2); - /* PLLCLK = 8MHz * 9 = 72 MHz */ - RCC_PLLConfig(RCC_PLLSource_HSE_Div1, STM32_PLL_MULT); - /* Enable PLL */ - RCC_PLLCmd(ENABLE); - /* Wait till PLL is ready */ - while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} - /* Select PLL as system clock source */ - RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); - /* Wait till PLL is used as system clock source */ - while(RCC_GetSYSCLKSource() != 0x08) {} - } -#else /* HSE_TYPE_EXT_CLK */ -#pragma message "Using normal system clock setup." - SystemInit(); -#endif /* HSE_TYPE_EXT_CLK */ - /* Set the Vector Table base location at 0x08000000 */ - NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); - -#ifdef STM32_FORCE_ALL_CLOCK_ON - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | - RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | - RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); +#else +#error EXT_CLK is either set to an unsupported frequency or not defined at all. Please check! #endif - -#endif // USE_OPENCM3 } diff --git a/sw/airborne/boards/lisa_l_1.0.h b/sw/airborne/boards/lisa_l_1.0.h index 5cf7ef8e27..e9652741ad 100644 --- a/sw/airborne/boards/lisa_l_1.0.h +++ b/sw/airborne/boards/lisa_l_1.0.h @@ -3,13 +3,10 @@ #define BOARD_LISA_L +/* Lisa/L has an 8MHZ external clock and 72MHz internal. */ +#define EXT_CLK 8000000 #define AHB_CLK 72000000 -/* Lisa uses an external clock instead of a crystal */ -#define HSE_TYPE_EXT_CLK -#define STM32_RCC_MODE RCC_HSE_Bypass -#define STM32_PLL_MULT RCC_PLLMul_9 - /* Onboard LEDs */ #define LED_1_BANK #define LED_STP08 diff --git a/sw/airborne/boards/lisa_m_1.0.h b/sw/airborne/boards/lisa_m_1.0.h index 65c50d754d..de64b20a41 100644 --- a/sw/airborne/boards/lisa_m_1.0.h +++ b/sw/airborne/boards/lisa_m_1.0.h @@ -3,6 +3,8 @@ #define BOARD_LISA_M +/* Lisa/M has a 12MHz external clock and 72MHz internal. */ +#define EXT_CLK 12000000 #define AHB_CLK 72000000 /* Onboard LEDs */ diff --git a/sw/airborne/boards/olimex_stm32-h103.h b/sw/airborne/boards/olimex_stm32-h103.h index f134c747f6..2ff19fb522 100644 --- a/sw/airborne/boards/olimex_stm32-h103.h +++ b/sw/airborne/boards/olimex_stm32-h103.h @@ -1,18 +1,14 @@ #ifndef CONFIG_OLIMEX_STM32_H103_H #define CONFIG_OLIMEX_STM32_H103_H - +/* Olimex STM32-H103 board has an 8MHz external clock and 72MHz internal. */ +#define EXT_CLK 8000000 #define AHB_CLK 72000000 -/* this board uses a crystal for HSE */ -//#define HSE_TYPE RCC_HSE_ON - /* Onboard LEDs */ #define LED_1_BANK #define LED_1_GPIO GPIOC #define LED_1_GPIO_CLK RCC_APB2Periph_GPIOC #define LED_1_GPIO_PIN GPIO_Pin_12 - - #endif /* CONFIG_OLIMEX_STM32_H103_H */