From e6acaa5a460cc42ecd46f650a74312d6293a644c Mon Sep 17 00:00:00 2001 From: Rocco Marco Guglielmi Date: Fri, 30 Dec 2016 15:36:49 +0000 Subject: Fixed Bug #806 git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9999 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/STM32F0xx/hal_lld.c | 3 +- os/hal/ports/STM32/STM32F0xx/hal_lld.h | 19 ++++++++--- os/hal/ports/STM32/STM32F0xx/stm32_registry.h | 45 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) (limited to 'os/hal/ports/STM32/STM32F0xx') diff --git a/os/hal/ports/STM32/STM32F0xx/hal_lld.c b/os/hal/ports/STM32/STM32F0xx/hal_lld.c index 3422061e3..a85e92ac8 100644 --- a/os/hal/ports/STM32/STM32F0xx/hal_lld.c +++ b/os/hal/ports/STM32/STM32F0xx/hal_lld.c @@ -307,9 +307,10 @@ void stm32_clock_init(void) { #endif /* Clock settings.*/ + /* CFGR2 must be configured first since CFGR value could change CFGR2 */ + RCC->CFGR2 = STM32_PREDIV; RCC->CFGR = STM32_PLLNODIV | STM32_MCOPRE | STM32_MCOSEL | STM32_PLLMUL | STM32_PLLSRC | STM32_PPRE | STM32_HPRE; - RCC->CFGR2 = STM32_PREDIV; #if STM32_CECSW == STM32_CECSW_OFF RCC->CFGR3 = STM32_USBSW | STM32_I2C1SW | STM32_USART1SW; #else diff --git a/os/hal/ports/STM32/STM32F0xx/hal_lld.h b/os/hal/ports/STM32/STM32F0xx/hal_lld.h index 316d063b7..aebd833c9 100644 --- a/os/hal/ports/STM32/STM32F0xx/hal_lld.h +++ b/os/hal/ports/STM32/STM32F0xx/hal_lld.h @@ -499,6 +499,10 @@ * HSI related checks. */ #if STM32_HSI_ENABLED +#if (STM32_SW == STM32_SW_PLL) && \ + (STM32_PLLSRC == STM32_PLLSRC_HSI) && !STM32_HAS_HSI_PREDIV +#error "STM32_PLLSRC_HSI not available on this platform. Select STM32_PLLSRC_HSI_DIV2 instead." +#endif #else /* !STM32_HSI_ENABLED */ #if STM32_SW == STM32_SW_HSI @@ -548,6 +552,9 @@ * HSI48 related checks. */ #if STM32_HSI48_ENABLED +#if !STM32_HAS_HSI48 +#error "HSI48 not available on this platform" +#endif #else /* !STM32_HSI48_ENABLED */ #if STM32_SW == STM32_SW_HSI48 @@ -662,7 +669,7 @@ #define STM32_ACTIVATE_PLL FALSE #endif -/* HSE prescaler setting check.*/ +/* HSE, HSI prescaler setting check.*/ #if ((STM32_PREDIV_VALUE >= 1) || (STM32_PREDIV_VALUE <= 16)) #define STM32_PREDIV ((STM32_PREDIV_VALUE - 1) << 0) #else @@ -821,14 +828,16 @@ */ #if (STM32_MCOPRE == STM32_MCOPRE_DIV1) || defined(__DOXYGEN__) #define STM32_MCOCLK STM32_MCODIVCLK -#elif STM32_MCOPRE == STM32_MCOPRE_DIV2 +#elif (STM32_MCOPRE == STM32_MCOPRE_DIV2) && STM32_HAS_MCO_PREDIV #define STM32_MCOCLK (STM32_MCODIVCLK / 2) -#elif STM32_MCOPRE == STM32_MCOPRE_DIV4 +#elif (STM32_MCOPRE == STM32_MCOPRE_DIV4) && STM32_HAS_MCO_PREDIV #define STM32_MCOCLK (STM32_MCODIVCLK / 4) -#elif STM32_MCOPRE == STM32_MCOPRE_DIV8 +#elif (STM32_MCOPRE == STM32_MCOPRE_DIV8) && STM32_HAS_MCO_PREDIV #define STM32_MCOCLK (STM32_MCODIVCLK / 8) -#elif STM32_MCOPRE == STM32_MCOPRE_DIV16 +#elif (STM32_MCOPRE == STM32_MCOPRE_DIV16) && STM32_HAS_MCO_PREDIV #define STM32_MCOCLK (STM32_MCODIVCLK / 16) +#elif !STM32_HAS_MCO_PREDIV +#error "MCO_PREDIV not available on this platform. Select STM32_MCODIVCLK." #else #error "invalid STM32_MCOPRE value specified" #endif diff --git a/os/hal/ports/STM32/STM32F0xx/stm32_registry.h b/os/hal/ports/STM32/STM32F0xx/stm32_registry.h index e97c875c1..5e8b6532a 100644 --- a/os/hal/ports/STM32/STM32F0xx/stm32_registry.h +++ b/os/hal/ports/STM32/STM32F0xx/stm32_registry.h @@ -46,6 +46,15 @@ /* Common identifier of all STM32F030 devices.*/ #define STM32F030 +/* RCC attributes. */ +#define STM32_HAS_HSI48 FALSE +#if defined(STM32F030xC) +#define STM32_HAS_HSI_PREDIV TRUE +#else +#define STM32_HAS_HSI_PREDIV FALSE +#endif +#define STM32_HAS_MCO_PREDIV TRUE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE @@ -241,6 +250,7 @@ #define STM32_HAS_TIM2 FALSE #define STM32_HAS_TIM4 FALSE #define STM32_HAS_TIM5 FALSE +#define STM32_HAS_TIM7 FALSE #define STM32_HAS_TIM8 FALSE #define STM32_HAS_TIM9 FALSE #define STM32_HAS_TIM10 FALSE @@ -349,6 +359,11 @@ /*===========================================================================*/ #elif defined(STM32F031x6) || defined(STM32F038xx) +/* RCC attributes. */ +#define STM32_HAS_HSI48 FALSE +#define STM32_HAS_HSI_PREDIV FALSE +#define STM32_HAS_MCO_PREDIV TRUE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE @@ -553,6 +568,11 @@ /*===========================================================================*/ #elif defined(STM32F042x6) +/* RCC attributes. */ +#define STM32_HAS_HSI48 TRUE +#define STM32_HAS_HSI_PREDIV TRUE +#define STM32_HAS_MCO_PREDIV TRUE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE @@ -767,6 +787,11 @@ /*===========================================================================*/ #elif defined(STM32F048xx) +/* RCC attributes. */ +#define STM32_HAS_HSI48 TRUE +#define STM32_HAS_HSI_PREDIV TRUE +#define STM32_HAS_MCO_PREDIV TRUE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE @@ -985,6 +1010,11 @@ /*===========================================================================*/ #elif defined(STM32F051x8) || defined(STM32F058xx) +/* RCC attributes. */ +#define STM32_HAS_HSI48 FALSE +#define STM32_HAS_HSI_PREDIV FALSE +#define STM32_HAS_MCO_PREDIV FALSE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE @@ -1219,6 +1249,11 @@ /* Common identifier of all STM32F070 devices.*/ #define STM32F070 +/* RCC attributes. */ +#define STM32_HAS_HSI48 FALSE +#define STM32_HAS_HSI_PREDIV TRUE +#define STM32_HAS_MCO_PREDIV TRUE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE @@ -1469,6 +1504,11 @@ /*===========================================================================*/ #elif defined(STM32F071xB) || defined(STM32F072xB) || \ defined(STM32F078xx) + +/* RCC attributes. */ +#define STM32_HAS_HSI48 TRUE +#define STM32_HAS_HSI_PREDIV TRUE +#define STM32_HAS_MCO_PREDIV TRUE /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE @@ -1733,6 +1773,11 @@ /*===========================================================================*/ #elif defined(STM32F091xC) || defined(STM32F098xx) +/* RCC attributes. */ +#define STM32_HAS_HSI48 TRUE +#define STM32_HAS_HSI_PREDIV TRUE +#define STM32_HAS_MCO_PREDIV TRUE + /* ADC attributes.*/ #define STM32_HAS_ADC1 TRUE #define STM32_ADC_SUPPORTS_PRESCALER FALSE -- cgit v1.2.3