diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-05-29 08:18:50 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-05-29 08:18:50 +0000 |
commit | 0a80e007b010a9b1546c6e19d0cf768d52f6650b (patch) | |
tree | f517fdba6c26b027ce1b7158d3ae7318fe809673 | |
parent | 685dc4e5f4803e914bdebf95ca8465724d4bc2c7 (diff) | |
download | ChibiOS-0a80e007b010a9b1546c6e19d0cf768d52f6650b.tar.gz ChibiOS-0a80e007b010a9b1546c6e19d0cf768d52f6650b.tar.bz2 ChibiOS-0a80e007b010a9b1546c6e19d0cf768d52f6650b.zip |
Implemented support for HSI16 divider on STM32L0xx.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10223 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | demos/STM32/NIL-STM32L011K4-NUCLEO32/mcuconf.h | 1 | ||||
-rw-r--r-- | demos/STM32/RT-STM32L031K6-NUCLEO32/mcuconf.h | 1 | ||||
-rw-r--r-- | demos/STM32/RT-STM32L053-DISCOVERY/mcuconf.h | 1 | ||||
-rw-r--r-- | demos/STM32/RT-STM32L053R8-NUCLEO64/mcuconf.h | 1 | ||||
-rw-r--r-- | demos/STM32/RT-STM32L073RZ-NUCLEO64/mcuconf.h | 1 | ||||
-rw-r--r-- | os/hal/ports/STM32/STM32L0xx/hal_lld.c | 6 | ||||
-rw-r--r-- | os/hal/ports/STM32/STM32L0xx/hal_lld.h | 30 | ||||
-rw-r--r-- | testhal/STM32/STM32L0xx/ADC/mcuconf.h | 1 | ||||
-rw-r--r-- | testhal/STM32/STM32L0xx/EXT/mcuconf.h | 1 | ||||
-rw-r--r-- | testhal/STM32/STM32L0xx/SPI/mcuconf.h | 1 |
10 files changed, 37 insertions, 7 deletions
diff --git a/demos/STM32/NIL-STM32L011K4-NUCLEO32/mcuconf.h b/demos/STM32/NIL-STM32L011K4-NUCLEO32/mcuconf.h index 1c648453a..064707691 100644 --- a/demos/STM32/NIL-STM32L011K4-NUCLEO32/mcuconf.h +++ b/demos/STM32/NIL-STM32L011K4-NUCLEO32/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
diff --git a/demos/STM32/RT-STM32L031K6-NUCLEO32/mcuconf.h b/demos/STM32/RT-STM32L031K6-NUCLEO32/mcuconf.h index f7cedeb21..21f900cdd 100644 --- a/demos/STM32/RT-STM32L031K6-NUCLEO32/mcuconf.h +++ b/demos/STM32/RT-STM32L031K6-NUCLEO32/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
diff --git a/demos/STM32/RT-STM32L053-DISCOVERY/mcuconf.h b/demos/STM32/RT-STM32L053-DISCOVERY/mcuconf.h index 9007e117a..f8cdcecc2 100644 --- a/demos/STM32/RT-STM32L053-DISCOVERY/mcuconf.h +++ b/demos/STM32/RT-STM32L053-DISCOVERY/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED FALSE
diff --git a/demos/STM32/RT-STM32L053R8-NUCLEO64/mcuconf.h b/demos/STM32/RT-STM32L053R8-NUCLEO64/mcuconf.h index 20c45e99c..bbf1fd85b 100644 --- a/demos/STM32/RT-STM32L053R8-NUCLEO64/mcuconf.h +++ b/demos/STM32/RT-STM32L053R8-NUCLEO64/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED TRUE
diff --git a/demos/STM32/RT-STM32L073RZ-NUCLEO64/mcuconf.h b/demos/STM32/RT-STM32L073RZ-NUCLEO64/mcuconf.h index bfdace23b..514cedbba 100644 --- a/demos/STM32/RT-STM32L073RZ-NUCLEO64/mcuconf.h +++ b/demos/STM32/RT-STM32L073RZ-NUCLEO64/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED TRUE
diff --git a/os/hal/ports/STM32/STM32L0xx/hal_lld.c b/os/hal/ports/STM32/STM32L0xx/hal_lld.c index c3bb6dd87..cd6113939 100644 --- a/os/hal/ports/STM32/STM32L0xx/hal_lld.c +++ b/os/hal/ports/STM32/STM32L0xx/hal_lld.c @@ -208,6 +208,12 @@ void stm32_clock_init(void) { RCC->CR |= RCC_CR_HSION;
while ((RCC->CR & RCC_CR_HSIRDY) == 0)
; /* Waits until HSI16 is stable. */
+
+#if STM32_HSI16_DIVIDER_ENABLED
+ RCC->CR |= RCC_CR_HSIDIVEN;
+ while ((RCC->CR & RCC_CR_HSIDIVF) == 0)
+ ;
+#endif
#endif
#if STM32_HSE_ENABLED
diff --git a/os/hal/ports/STM32/STM32L0xx/hal_lld.h b/os/hal/ports/STM32/STM32L0xx/hal_lld.h index ec88abfc0..22baf5706 100644 --- a/os/hal/ports/STM32/STM32L0xx/hal_lld.h +++ b/os/hal/ports/STM32/STM32L0xx/hal_lld.h @@ -325,6 +325,13 @@ #endif
/**
+ * @brief Enables or disables the HSI16 clock divider.
+ */
+#if !defined(STM32_HSI16_DIVIDER_ENABLED) || defined(__DOXYGEN__)
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
+#endif
+
+/**
* @brief Enables or disables the LSI clock source.
*/
#if !defined(STM32_LSI_ENABLED) || defined(__DOXYGEN__)
@@ -675,6 +682,15 @@ #endif /* !STM32_HSI16_ENABLED */
+/*
+ * @brief Divided HSI16 clock.
+ */
+#if STM32_HSI16_DIVIDER_ENABLED || defined(__DOXYGEN__)
+#define STM32_HSI16DIVCLK (STM32_HSI16CLK / 4)
+#else
+#define STM32_HSI16DIVCLK STM32_HSI16CLK
+#endif
+
/* HSE related checks.*/
#if STM32_HSE_ENABLED
#if STM32_HSECLK == 0
@@ -798,7 +814,7 @@ #if (STM32_PLLSRC == STM32_PLLSRC_HSE) || defined(__DOXYGEN__)
#define STM32_PLLCLKIN STM32_HSECLK
#elif STM32_PLLSRC == STM32_PLLSRC_HSI16
-#define STM32_PLLCLKIN STM32_HSI16CLK
+#define STM32_PLLCLKIN STM32_HSI16DIVCLK
#else
#error "invalid STM32_PLLSRC value specified"
#endif
@@ -954,7 +970,7 @@ #elif STM32_MCOSEL == STM32_MCOSEL_SYSCLK
#define STM32_MCODIVCLK STM32_SYSCLK
#elif STM32_MCOSEL == STM32_MCOSEL_HSI16
-#define STM32_MCODIVCLK STM32_HSI16CLK
+#define STM32_MCODIVCLK STM32_HSI16DIVCLK
#elif STM32_MCOSEL == STM32_MCOSEL_MSI
#define STM32_MCODIVCLK STM32_MSICLK
#elif STM32_MCOSEL == STM32_MCOSEL_HSE
@@ -1026,7 +1042,7 @@ #elif STM32_USART1SEL == STM32_USART1SEL_SYSCLK
#define STM32_USART1CLK STM32_SYSCLK
#elif STM32_USART1SEL == STM32_USART1SEL_HSI16
-#define STM32_USART1CLK STM32_HSI16CLK
+#define STM32_USART1CLK STM32_HSI16DIVCLK
#elif STM32_USART1SEL == STM32_USART1SEL_LSE
#define STM32_USART1CLK STM32_LSECLK
#else
@@ -1041,7 +1057,7 @@ #elif STM32_USART2SEL == STM32_USART2SEL_SYSCLK
#define STM32_USART2CLK STM32_SYSCLK
#elif STM32_USART2SEL == STM32_USART2SEL_HSI16
-#define STM32_USART2CLK STM32_HSI16CLK
+#define STM32_USART2CLK STM32_HSI16DIVCLK
#elif STM32_USART2SEL == STM32_USART2SEL_LSE
#define STM32_USART2CLK STM32_LSECLK
#else
@@ -1066,7 +1082,7 @@ #elif STM32_LPUART1SEL == STM32_LPUART1SEL_SYSCLK
#define STM32_LPUART1CLK STM32_SYSCLK
#elif STM32_LPUART1SEL == STM32_LPUART1SEL_HSI16
-#define STM32_LPUART1CLK STM32_HSI16CLK
+#define STM32_LPUART1CLK STM32_HSI16DIVCLK
#elif STM32_LPUART1SEL == STM32_LPUART1SEL_LSE
#define STM32_LPUART1CLK STM32_LSECLK
#else
@@ -1081,7 +1097,7 @@ #elif STM32_I2C1SEL == STM32_I2C1SEL_SYSCLK
#define STM32_I2C1CLK STM32_SYSCLK
#elif STM32_I2C1SEL == STM32_I2C1SEL_HSI16
-#define STM32_I2C1CLK STM32_HSI16CLK
+#define STM32_I2C1CLK STM32_HSI16DIVCLK
#else
#error "invalid source selected for I2C1 clock"
#endif
@@ -1094,7 +1110,7 @@ #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_LSI
#define STM32_LPTIM1CLK STM32_LSICLK
#elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_HSI16
-#define STM32_LPTIM1CLK STM32_HSI16CLK
+#define STM32_LPTIM1CLK STM32_HSI16DIVCLK
#elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_LSE
#define STM32_LPTIM1CLK STM32_LSECLK
#else
diff --git a/testhal/STM32/STM32L0xx/ADC/mcuconf.h b/testhal/STM32/STM32L0xx/ADC/mcuconf.h index dbce0c6c9..d051c130a 100644 --- a/testhal/STM32/STM32L0xx/ADC/mcuconf.h +++ b/testhal/STM32/STM32L0xx/ADC/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED TRUE
diff --git a/testhal/STM32/STM32L0xx/EXT/mcuconf.h b/testhal/STM32/STM32L0xx/EXT/mcuconf.h index 5fd1710a1..2c9bd2422 100644 --- a/testhal/STM32/STM32L0xx/EXT/mcuconf.h +++ b/testhal/STM32/STM32L0xx/EXT/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED TRUE
diff --git a/testhal/STM32/STM32L0xx/SPI/mcuconf.h b/testhal/STM32/STM32L0xx/SPI/mcuconf.h index c4c0ba11b..d902d5021 100644 --- a/testhal/STM32/STM32L0xx/SPI/mcuconf.h +++ b/testhal/STM32/STM32L0xx/SPI/mcuconf.h @@ -41,6 +41,7 @@ #define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_HSI16_ENABLED TRUE
+#define STM32_HSI16_DIVIDER_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED TRUE
|