Skip to content

Instantly share code, notes, and snippets.

@dwagenk
Last active December 15, 2017 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwagenk/6c37b20b3ffd8f92646d901ec25104ee to your computer and use it in GitHub Desktop.
Save dwagenk/6c37b20b3ffd8f92646d901ec25104ee to your computer and use it in GitHub Desktop.
diff of zephyr/drivers/serial/uart_stm32.c to fix STM32F0 UART1 Clock problems
drivers/serial/uart_stm32.c | 113 ++++++++++++++++++++++++++++++--------------
1 file changed, 78 insertions(+), 35 deletions(-)
diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c
index 7342893..cb6e4c9 100644
--- a/drivers/serial/uart_stm32.c
+++ b/drivers/serial/uart_stm32.c
@@ -312,9 +312,10 @@ static int uart_stm32_init(struct device *dev)
}
/* Define clocks */
- #define STM32_CLOCK_UART(type, apb, n) \
- .pclken = { .bus = STM32_CLOCK_BUS_ ## apb, \
- .enr = LL_##apb##_GRP1_PERIPH_##type##n }
+ #define STM32_CLOCK_UART(type, apb, grp, clock_bus, n) \
+ .pclken = { .bus = STM32_CLOCK_BUS_ ## clock_bus, \
+ .enr = LL_##apb##_##grp##_PERIPH_##type##n }
+
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
#define STM32_UART_IRQ_HANDLER_DECL(n) \
@@ -336,7 +337,7 @@ static void uart_stm32_irq_config_func_##n(struct device *dev) \
#define STM32_UART_IRQ_HANDLER(n)
#endif
-#define UART_DEVICE_INIT_STM32(type, n, apb) \
+#define UART_DEVICE_INIT_STM32(type, n, apb, grp, clock_bus) \
STM32_UART_IRQ_HANDLER_DECL(n); \
\
static const struct uart_stm32_config uart_stm32_dev_cfg_##n = { \
@@ -344,7 +345,7 @@ static const struct uart_stm32_config uart_stm32_dev_cfg_##n = { \
.base = (u8_t *)CONFIG_UART_STM32_PORT_ ## n ## _BASE_ADDRESS, \
STM32_UART_IRQ_HANDLER_FUNC(n) \
}, \
- STM32_CLOCK_UART(type, apb, n), \
+ STM32_CLOCK_UART(type, apb, grp, clock_bus, n) \
}; \
\
static struct uart_stm32_data uart_stm32_dev_data_##n = { \
@@ -363,42 +364,84 @@ DEVICE_AND_API_INIT(uart_stm32_##n, CONFIG_UART_STM32_PORT_##n##_NAME, \
\
STM32_UART_IRQ_HANDLER(n)
-#ifdef CONFIG_UART_STM32_PORT_1
-UART_DEVICE_INIT_STM32(USART, 1, APB2)
-#endif /* CONFIG_UART_STM32_PORT_1 */
+#ifdef CONFIG_SOC_SERIES_STM32F0X
+ #ifdef CONFIG_UART_STM32_PORT_1
+ UART_DEVICE_INIT_STM32(USART, 1, APB1, GRP2, APB1_2)
+ #endif /* CONFIG_UART_STM32_PORT_1 */
-#ifdef CONFIG_UART_STM32_PORT_2
-UART_DEVICE_INIT_STM32(USART, 2, APB1)
-#endif /* CONFIG_UART_STM32_PORT_2 */
+ #ifdef CONFIG_UART_STM32_PORT_2
+ UART_DEVICE_INIT_STM32(USART, 2, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_2 */
-#ifdef CONFIG_UART_STM32_PORT_3
-UART_DEVICE_INIT_STM32(USART, 3, APB1)
-#endif /* CONFIG_UART_STM32_PORT_3 */
+ #ifdef CONFIG_UART_STM32_PORT_3
+ UART_DEVICE_INIT_STM32(USART, 3, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_3 */
-#ifdef CONFIG_UART_STM32_PORT_4
-UART_DEVICE_INIT_STM32(UART, 4, APB1)
-#endif /* CONFIG_UART_STM32_PORT_4 */
+ #ifdef CONFIG_UART_STM32_PORT_4
+ UART_DEVICE_INIT_STM32(UART, 4, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_4 */
-#ifdef CONFIG_UART_STM32_PORT_5
-UART_DEVICE_INIT_STM32(UART, 5, APB1)
-#endif /* CONFIG_UART_STM32_PORT_5 */
+ #ifdef CONFIG_UART_STM32_PORT_5
+ UART_DEVICE_INIT_STM32(UART, 5, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_5 */
-#ifdef CONFIG_UART_STM32_PORT_6
-UART_DEVICE_INIT_STM32(USART, 6, APB2)
-#endif /* CONFIG_UART_STM32_PORT_6 */
+ #ifdef CONFIG_UART_STM32_PORT_6
+ UART_DEVICE_INIT_STM32(USART, 6, APB1, GRP2, APB1_2)
+ #endif /* CONFIG_UART_STM32_PORT_6 */
-#ifdef CONFIG_UART_STM32_PORT_7
-UART_DEVICE_INIT_STM32(UART, 7, APB1)
-#endif /* CONFIG_UART_STM32_PORT_7 */
+ #ifdef CONFIG_UART_STM32_PORT_7
+ UART_DEVICE_INIT_STM32(UART, 7, APB1, GRP2, APB1_2)
+ #endif /* CONFIG_UART_STM32_PORT_7 */
-#ifdef CONFIG_UART_STM32_PORT_8
-UART_DEVICE_INIT_STM32(UART, 8, APB1)
-#endif /* CONFIG_UART_STM32_PORT_8 */
+ #ifdef CONFIG_UART_STM32_PORT_8
+ UART_DEVICE_INIT_STM32(UART, 8, APB1, GRP2, APB1_2)
+ #endif /* CONFIG_UART_STM32_PORT_8 */
-#ifdef CONFIG_UART_STM32_PORT_9
-UART_DEVICE_INIT_STM32(UART, 9, APB2)
-#endif /* CONFIG_UART_STM32_PORT_9 */
+ #ifdef CONFIG_UART_STM32_PORT_9
+ UART_DEVICE_INIT_STM32(UART, 9, APB1, GRP2, APB1_2)
+ #endif /* CONFIG_UART_STM32_PORT_9 */
-#ifdef CONFIG_UART_STM32_PORT_10
-UART_DEVICE_INIT_STM32(UART, 10, APB2)
-#endif /* CONFIG_UART_STM32_PORT_10 */
+ #ifdef CONFIG_UART_STM32_PORT_10
+ //FIXME DW this is an error
+ #endif /* CONFIG_UART_STM32_PORT_10 */
+#else
+ #ifdef CONFIG_UART_STM32_PORT_1
+ UART_DEVICE_INIT_STM32(USART, 1, APB2, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_1 */
+
+ #ifdef CONFIG_UART_STM32_PORT_2
+ UART_DEVICE_INIT_STM32(USART, 2, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_2 */
+
+ #ifdef CONFIG_UART_STM32_PORT_3
+ UART_DEVICE_INIT_STM32(USART, 3, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_3 */
+
+ #ifdef CONFIG_UART_STM32_PORT_4
+ UART_DEVICE_INIT_STM32(UART, 4, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_4 */
+
+ #ifdef CONFIG_UART_STM32_PORT_5
+ UART_DEVICE_INIT_STM32(UART, 5, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_5 */
+
+ #ifdef CONFIG_UART_STM32_PORT_6
+ UART_DEVICE_INIT_STM32(USART, 6, APB2, GRP1, APB2)
+ #endif /* CONFIG_UART_STM32_PORT_6 */
+
+ #ifdef CONFIG_UART_STM32_PORT_7
+ UART_DEVICE_INIT_STM32(UART, 7, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_7 */
+
+ #ifdef CONFIG_UART_STM32_PORT_8
+ UART_DEVICE_INIT_STM32(UART, 8, APB1, GRP1, APB1)
+ #endif /* CONFIG_UART_STM32_PORT_8 */
+
+ #ifdef CONFIG_UART_STM32_PORT_9
+ UART_DEVICE_INIT_STM32(UART, 9, APB2, GRP1, APB2)
+ #endif /* CONFIG_UART_STM32_PORT_9 */
+
+ #ifdef CONFIG_UART_STM32_PORT_10
+ UART_DEVICE_INIT_STM32(UART, 10, APB2, GRP1, APB2)
+ #endif /* CONFIG_UART_STM32_PORT_10 */
+#endif /* CONFIG_SOC_SERIES_STM32F0X */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment