You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/04/20 18:52:37 UTC

[mynewt-core] 01/06: Add initial common hal_uart driver for F4xx

This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit b858fbfe7bdb0d0d2a37b80cd30a429d82917a8b
Author: Fabio Utzig <ut...@apache.org>
AuthorDate: Mon Apr 16 13:24:06 2018 -0300

    Add initial common hal_uart driver for F4xx
---
 hw/bsp/nucleo-f401re/src/hal_bsp.c                    | 18 ++++++++----------
 hw/bsp/nucleo-f413re/src/hal_bsp.c                    |  2 +-
 hw/bsp/nucleo-f413zh/src/hal_bsp.c                    |  2 +-
 hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c       |  2 +-
 hw/bsp/sensorhub/src/hal_bsp.c                        |  2 +-
 hw/bsp/stm32f429discovery/src/hal_bsp.c               |  2 +-
 hw/bsp/stm32f4discovery/src/hal_bsp.c                 |  8 +++-----
 hw/mcu/stm/{stm32f4xx => stm32_common}/src/hal_uart.c | 13 ++++---------
 hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h          |  7 +++++--
 hw/mcu/stm/stm32f4xx/include/mcu/stm32f4_bsp.h        |  2 +-
 10 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/hw/bsp/nucleo-f401re/src/hal_bsp.c b/hw/bsp/nucleo-f401re/src/hal_bsp.c
index 3c43d19..49fdd7c 100644
--- a/hw/bsp/nucleo-f401re/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f401re/src/hal_bsp.c
@@ -36,25 +36,23 @@
 #include <stm32f4xx_hal_gpio_ex.h>
 #include <mcu/mcu.h>
 #include "mcu/stm32_hal.h"
-#include <mcu/stm32f4_bsp.h>
-#include <mcu/stm32f4xx_mynewt_hal.h>
 #include "bsp/bsp.h"
 #include <assert.h>
 
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev hal_uart0;
 
-static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+static const struct stm32_uart_cfg uart_cfg[UART_CNT] = {
     [0] = {
-        .suc_uart = USART2,
+        .suc_uart    = USART2,
         .suc_rcc_reg = &RCC->APB1ENR,
         .suc_rcc_dev = RCC_APB1ENR_USART2EN,
-        .suc_pin_tx = MCU_GPIO_PORTA(2),    /* PA2 */
-        .suc_pin_rx = MCU_GPIO_PORTA(3),    /* PA3 */
-        .suc_pin_rts = MCU_GPIO_PORTA(1),   /* PA1 */
-        .suc_pin_cts = MCU_GPIO_PORTA(0),   /* PA0 */
-        .suc_pin_af = GPIO_AF7_USART2,
-        .suc_irqn = USART2_IRQn
+        .suc_pin_tx  = MCU_GPIO_PORTA(2),
+        .suc_pin_rx  = MCU_GPIO_PORTA(3),
+        .suc_pin_rts = MCU_GPIO_PORTA(1),
+        .suc_pin_cts = MCU_GPIO_PORTA(0),
+        .suc_pin_af  = GPIO_AF7_USART2,
+        .suc_irqn    = USART2_IRQn
     }
 };
 #endif
diff --git a/hw/bsp/nucleo-f413re/src/hal_bsp.c b/hw/bsp/nucleo-f413re/src/hal_bsp.c
index 31c0dfc..db0f08a 100644
--- a/hw/bsp/nucleo-f413re/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f413re/src/hal_bsp.c
@@ -43,7 +43,7 @@
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev hal_uart0;
 
-static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+static const struct stm32_uart_cfg uart_cfg[UART_CNT] = {
     [0] = {
         .suc_uart = USART2,
         .suc_rcc_reg = &RCC->APB1ENR,
diff --git a/hw/bsp/nucleo-f413zh/src/hal_bsp.c b/hw/bsp/nucleo-f413zh/src/hal_bsp.c
index 002fd6e..13c10fb 100644
--- a/hw/bsp/nucleo-f413zh/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f413zh/src/hal_bsp.c
@@ -43,7 +43,7 @@
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev hal_uart0;
 
-static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+static const struct stm32_uart_cfg uart_cfg[UART_CNT] = {
     [0] = {
         .suc_uart = USART3,
         .suc_rcc_reg = &RCC->APB1ENR,
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
index 89a1e9d..09b25a2 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
@@ -276,7 +276,7 @@ struct stm32_hal_spi_cfg spi0_cfg = {
 };
 #endif
 #if MYNEWT_VAL(UART_0)
-static const struct stm32f4_uart_cfg uart_cfg0 = {
+static const struct stm32_uart_cfg uart_cfg0 = {
     .suc_uart = USART6,
     .suc_rcc_reg = &RCC->APB2ENR,
     .suc_rcc_dev = RCC_APB2ENR_USART6EN,
diff --git a/hw/bsp/sensorhub/src/hal_bsp.c b/hw/bsp/sensorhub/src/hal_bsp.c
index f181851..1b635d6 100644
--- a/hw/bsp/sensorhub/src/hal_bsp.c
+++ b/hw/bsp/sensorhub/src/hal_bsp.c
@@ -34,7 +34,7 @@
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev hal_uart0;
 
-static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+static const struct stm32_uart_cfg uart_cfg[UART_CNT] = {
     [0] = {
         .suc_uart = UART4,
         .suc_rcc_reg = &RCC->APB1ENR,
diff --git a/hw/bsp/stm32f429discovery/src/hal_bsp.c b/hw/bsp/stm32f429discovery/src/hal_bsp.c
index 49eac7d..a720144 100644
--- a/hw/bsp/stm32f429discovery/src/hal_bsp.c
+++ b/hw/bsp/stm32f429discovery/src/hal_bsp.c
@@ -42,7 +42,7 @@
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev hal_uart0;
 
-static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+static const struct stm32_uart_cfg uart_cfg[UART_CNT] = {
     [0] = {
         .suc_uart = USART2,
         .suc_rcc_reg = &RCC->APB1ENR,
diff --git a/hw/bsp/stm32f4discovery/src/hal_bsp.c b/hw/bsp/stm32f4discovery/src/hal_bsp.c
index 3cf3d68..ef92c39 100644
--- a/hw/bsp/stm32f4discovery/src/hal_bsp.c
+++ b/hw/bsp/stm32f4discovery/src/hal_bsp.c
@@ -36,8 +36,6 @@
 
 #include <stm32f407xx.h>
 #include <stm32f4xx_hal_gpio_ex.h>
-#include <mcu/stm32f4_bsp.h>
-#include "mcu/stm32f4xx_mynewt_hal.h"
 #include "mcu/stm32_hal.h"
 #include "hal/hal_i2c.h"
 
@@ -46,13 +44,13 @@
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev hal_uart0;
 
-static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
+static const struct stm32_uart_cfg uart_cfg[UART_CNT] = {
     [0] = {
         .suc_uart = USART6,
         .suc_rcc_reg = &RCC->APB2ENR,
         .suc_rcc_dev = RCC_APB2ENR_USART6EN,
-        .suc_pin_tx = MCU_GPIO_PORTC(6),	/* PC6 */
-        .suc_pin_rx = MCU_GPIO_PORTC(7),	/* PC7 */
+        .suc_pin_tx = MCU_GPIO_PORTC(6),
+        .suc_pin_rx = MCU_GPIO_PORTC(7),
         .suc_pin_rts = -1,
         .suc_pin_cts = -1,
         .suc_pin_af = GPIO_AF8_USART6,
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_uart.c b/hw/mcu/stm/stm32_common/src/hal_uart.c
similarity index 96%
rename from hw/mcu/stm/stm32f4xx/src/hal_uart.c
rename to hw/mcu/stm/stm32_common/src/hal_uart.c
index 1c684ef..20394e2 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_uart.c
+++ b/hw/mcu/stm/stm32_common/src/hal_uart.c
@@ -20,13 +20,8 @@
 #include "hal/hal_uart.h"
 #include "hal/hal_gpio.h"
 #include "mcu/cmsis_nvic.h"
+#include "mcu/stm32_hal.h"
 #include "bsp/bsp.h"
-#include "stm32f4xx.h"
-#include "stm32f4xx_hal_dma.h"
-#include "stm32f4xx_hal_uart.h"
-#include "stm32f4xx_hal_rcc.h"
-#include "mcu/stm32f4_bsp.h"
-#include "mcu/stm32f4xx_mynewt_hal.h"
 #include <assert.h>
 #include <stdlib.h>
 
@@ -40,7 +35,7 @@ struct hal_uart {
     hal_uart_tx_char u_tx_func;
     hal_uart_tx_done u_tx_done;
     void *u_func_arg;
-    const struct stm32f4_uart_cfg *u_cfg;
+    const struct stm32_uart_cfg *u_cfg;
 };
 static struct hal_uart uarts[UART_CNT];
 
@@ -265,7 +260,7 @@ hal_uart_config(int port, int32_t baudrate, uint8_t databits, uint8_t stopbits,
   enum hal_uart_parity parity, enum hal_uart_flow_ctl flow_ctl)
 {
     struct hal_uart *u;
-    const struct stm32f4_uart_cfg *cfg;
+    const struct stm32_uart_cfg *cfg;
     uint32_t cr1, cr2, cr3;
 
     if (port >= UART_CNT) {
@@ -387,7 +382,7 @@ hal_uart_init(int port, void *arg)
         return -1;
     }
     u = &uarts[port];
-    u->u_cfg = (const struct stm32f4_uart_cfg *)arg;
+    u->u_cfg = (const struct stm32_uart_cfg *)arg;
 
     return 0;
 }
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h b/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
index 1dee100..3ae59e7 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
@@ -30,6 +30,8 @@ extern "C" {
 #include "stm32f4xx_hal_def.h"
 
 #include "stm32f4xx_mynewt_hal.h"
+#include "stm32f4xx.h"
+#include "stm32f4xx_hal_dma.h"
 
 /* hal_watchdog */
 #include "stm32f4xx_hal_iwdg.h"
@@ -43,8 +45,6 @@ extern "C" {
     } while (0)
 
 /* hal_spi */
-#include "stm32f4xx.h"
-#include "stm32f4xx_hal_dma.h"
 #include "stm32f4xx_hal_spi.h"
 #include "stm32f4xx_hal_gpio.h"
 #include "stm32f4xx_hal_gpio_ex.h"
@@ -61,6 +61,9 @@ struct stm32_hal_spi_cfg {
 /* hal_i2c */
 #include "stm32f4xx_hal_i2c.h"
 #include "mcu/stm32f4xx_mynewt_hal.h"
+
+/* hal_uart */
+#include "stm32f4xx_hal_uart.h"
 #include "mcu/stm32f4_bsp.h"
 
 #ifdef __cplusplus
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4_bsp.h b/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4_bsp.h
index 3db39b0..5f12ecf 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4_bsp.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/stm32f4_bsp.h
@@ -30,7 +30,7 @@ extern "C" {
 /**
  * BSP specific UART settings.
  */
-struct stm32f4_uart_cfg {
+struct stm32_uart_cfg {
     USART_TypeDef *suc_uart;			/* UART dev registers */
     volatile uint32_t *suc_rcc_reg;		/* RCC register to modify */
     uint32_t suc_rcc_dev;			/* RCC device ID */

-- 
To stop receiving notification emails like this one, please contact
utzig@apache.org.