]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
stm32f4: add serial print port
authorkunhuahuang <huangkunhua@gmail.com>
Mon, 27 Apr 2015 19:01:19 +0000 (03:01 +0800)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 20:38:42 +0000 (22:38 +0200)
Add the stm32F4 board's serial ports support.
User can use it easily.
The user only need to edit the number of the usart.
The patch also fix the serial print out.

Last, this version of patch fix the first patch checkpatch.pl error.
Thanks to Kamil Lulko.

Signed-off-by: kunhuahuang <huangkunhua@gmail.com>
arch/arm/include/asm/arch-stm32f4/gpio.h
board/st/stm32f429-discovery/stm32f429-discovery.c
drivers/serial/serial_stm32.c
include/configs/stm32f429-discovery.h

index 7cd866ea2a1f91929f1a7ee894fe122895b11412..dd33b96c4848443ed47d720b82a742182e57b436 100644 (file)
 #ifndef _STM32_GPIO_H_
 #define _STM32_GPIO_H_
 
 #ifndef _STM32_GPIO_H_
 #define _STM32_GPIO_H_
 
+#if (CONFIG_STM32_USART == 1)
+#define STM32_GPIO_PORT_X   STM32_GPIO_PORT_A
+#define STM32_GPIO_PIN_TX   STM32_GPIO_PIN_9
+#define STM32_GPIO_PIN_RX   STM32_GPIO_PIN_10
+#define STM32_GPIO_USART    STM32_GPIO_AF7
+
+#elif (CONFIG_STM32_USART == 2)
+#define STM32_GPIO_PORT_X   STM32_GPIO_PORT_D
+#define STM32_GPIO_PIN_TX   STM32_GPIO_PIN_5
+#define STM32_GPIO_PIN_RX   STM32_GPIO_PIN_6
+#define STM32_GPIO_USART    STM32_GPIO_AF7
+
+#elif (CONFIG_STM32_USART == 3)
+#define STM32_GPIO_PORT_X   STM32_GPIO_PORT_C
+#define STM32_GPIO_PIN_TX   STM32_GPIO_PIN_10
+#define STM32_GPIO_PIN_RX   STM32_GPIO_PIN_11
+#define STM32_GPIO_USART    STM32_GPIO_AF7
+
+#elif (CONFIG_STM32_USART == 6)
+#define STM32_GPIO_PORT_X   STM32_GPIO_PORT_G
+#define STM32_GPIO_PIN_TX   STM32_GPIO_PIN_14
+#define STM32_GPIO_PIN_RX   STM32_GPIO_PIN_9
+#define STM32_GPIO_USART    STM32_GPIO_AF8
+
+#else
+#define STM32_GPIO_PORT_X   STM32_GPIO_PORT_A
+#define STM32_GPIO_PIN_TX   STM32_GPIO_PIN_9
+#define STM32_GPIO_PIN_RX   STM32_GPIO_PIN_10
+#define STM32_GPIO_USART    STM32_GPIO_AF7
+
+#endif
+
 enum stm32_gpio_port {
        STM32_GPIO_PORT_A = 0,
        STM32_GPIO_PORT_B,
 enum stm32_gpio_port {
        STM32_GPIO_PORT_A = 0,
        STM32_GPIO_PORT_B,
index 2c4830f790aee3b132d4939c6316fc177cd0dfda..2dd5d935d9ec9af0c661794d1daea9a9944fd6ae 100644 (file)
@@ -33,21 +33,21 @@ const struct stm32_gpio_ctl gpio_ctl_usart = {
        .otype = STM32_GPIO_OTYPE_PP,
        .speed = STM32_GPIO_SPEED_50M,
        .pupd = STM32_GPIO_PUPD_UP,
        .otype = STM32_GPIO_OTYPE_PP,
        .speed = STM32_GPIO_SPEED_50M,
        .pupd = STM32_GPIO_PUPD_UP,
-       .af = STM32_GPIO_AF7
+       .af = STM32_GPIO_USART
 };
 
 };
 
-static const struct stm32_gpio_dsc usart1_gpio[] = {
-       {STM32_GPIO_PORT_A, STM32_GPIO_PIN_9},  /* TX */
-       {STM32_GPIO_PORT_A, STM32_GPIO_PIN_10}, /* RX */
+static const struct stm32_gpio_dsc usart_gpio[] = {
+       {STM32_GPIO_PORT_X, STM32_GPIO_PIN_TX}, /* TX */
+       {STM32_GPIO_PORT_X, STM32_GPIO_PIN_RX}, /* RX */
 };
 
 };
 
-int uart1_setup_gpio(void)
+int uart_setup_gpio(void)
 {
        int i;
        int rv = 0;
 
 {
        int i;
        int rv = 0;
 
-       for (i = 0; i < ARRAY_SIZE(usart1_gpio); i++) {
-               rv = stm32_gpio_config(&usart1_gpio[i], &gpio_ctl_usart);
+       for (i = 0; i < ARRAY_SIZE(usart_gpio); i++) {
+               rv = stm32_gpio_config(&usart_gpio[i], &gpio_ctl_usart);
                if (rv)
                        goto out;
        }
                if (rv)
                        goto out;
        }
@@ -272,7 +272,7 @@ int board_early_init_f(void)
 {
        int res;
 
 {
        int res;
 
-       res = uart1_setup_gpio();
+       res = uart_setup_gpio();
        if (res)
                return res;
 
        if (res)
                return res;
 
index 8c613db95d5875a752e92ecbb7e7f3946eec1b79..8b2830b946a83b9bf3675c4fef03d2c8fc815882 100644 (file)
 #include <serial.h>
 #include <asm/arch/stm32.h>
 
 #include <serial.h>
 #include <asm/arch/stm32.h>
 
+/*
+ * Set up the usart port
+ */
+#if (CONFIG_STM32_USART >= 1) && (CONFIG_STM32_USART <= 6)
+#define USART_PORT     (CONFIG_STM32_USART - 1)
+#else
+#define USART_PORT     0
+#endif
+/*
+ * Set up the usart base address
+ *
+ * --STM32_USARTD_BASE means default setting
+ */
 #define STM32_USART1_BASE      (STM32_APB2PERIPH_BASE + 0x1000)
 #define STM32_USART1_BASE      (STM32_APB2PERIPH_BASE + 0x1000)
-#define RCC_APB2ENR_USART1EN   (1 << 4)
-
-#define USART_BASE             STM32_USART1_BASE
-#define RCC_USART_ENABLE       RCC_APB2ENR_USART1EN
+#define STM32_USART2_BASE      (STM32_APB1PERIPH_BASE + 0x4400)
+#define STM32_USART3_BASE      (STM32_APB1PERIPH_BASE + 0x4800)
+#define STM32_USART6_BASE      (STM32_APB2PERIPH_BASE + 0x1400)
+#define STM32_USARTD_BASE      STM32_USART1_BASE
+/*
+ * RCC USART specific definitions
+ *
+ * --RCC_ENR_USARTDEN means default setting
+ */
+#define RCC_ENR_USART1EN       (1 << 4)
+#define RCC_ENR_USART2EN       (1 << 17)
+#define RCC_ENR_USART3EN       (1 << 18)
+#define RCC_ENR_USART6EN       (1 <<  5)
+#define RCC_ENR_USARTDEN       RCC_ENR_USART1EN
 
 struct stm32_serial {
        u32 sr;
 
 struct stm32_serial {
        u32 sr;
@@ -39,6 +62,24 @@ struct stm32_serial {
 
 DECLARE_GLOBAL_DATA_PTR;
 
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static const unsigned long usart_base[] = {
+       STM32_USART1_BASE,
+       STM32_USART2_BASE,
+       STM32_USART3_BASE,
+       STM32_USARTD_BASE,
+       STM32_USARTD_BASE,
+       STM32_USART6_BASE
+};
+
+static const unsigned long rcc_enr_en[] = {
+       RCC_ENR_USART1EN,
+       RCC_ENR_USART2EN,
+       RCC_ENR_USART3EN,
+       RCC_ENR_USARTDEN,
+       RCC_ENR_USARTDEN,
+       RCC_ENR_USART6EN
+};
+
 static void stm32_serial_setbrg(void)
 {
        serial_init();
 static void stm32_serial_setbrg(void)
 {
        serial_init();
@@ -46,14 +87,17 @@ static void stm32_serial_setbrg(void)
 
 static int stm32_serial_init(void)
 {
 
 static int stm32_serial_init(void)
 {
-       struct stm32_serial *usart = (struct stm32_serial *)USART_BASE;
+       struct stm32_serial *usart =
+               (struct stm32_serial *)usart_base[USART_PORT];
        u32 clock, int_div, frac_div, tmp;
 
        u32 clock, int_div, frac_div, tmp;
 
-       if ((USART_BASE & STM32_BUS_MASK) == STM32_APB1PERIPH_BASE) {
-               setbits_le32(&STM32_RCC->apb1enr, RCC_USART_ENABLE);
+       if ((usart_base[USART_PORT] & STM32_BUS_MASK) ==
+                       STM32_APB1PERIPH_BASE) {
+               setbits_le32(&STM32_RCC->apb1enr, rcc_enr_en[USART_PORT]);
                clock = clock_get(CLOCK_APB1);
                clock = clock_get(CLOCK_APB1);
-       } else if ((USART_BASE & STM32_BUS_MASK) == STM32_APB2PERIPH_BASE) {
-               setbits_le32(&STM32_RCC->apb2enr, RCC_USART_ENABLE);
+       } else if ((usart_base[USART_PORT] & STM32_BUS_MASK) ==
+                       STM32_APB2PERIPH_BASE) {
+               setbits_le32(&STM32_RCC->apb2enr, rcc_enr_en[USART_PORT]);
                clock = clock_get(CLOCK_APB2);
        } else {
                return -1;
                clock = clock_get(CLOCK_APB2);
        } else {
                return -1;
@@ -72,7 +116,8 @@ static int stm32_serial_init(void)
 
 static int stm32_serial_getc(void)
 {
 
 static int stm32_serial_getc(void)
 {
-       struct stm32_serial *usart = (struct stm32_serial *)USART_BASE;
+       struct stm32_serial *usart =
+               (struct stm32_serial *)usart_base[USART_PORT];
        while ((readl(&usart->sr) & USART_SR_FLAG_RXNE) == 0)
                ;
        return readl(&usart->dr);
        while ((readl(&usart->sr) & USART_SR_FLAG_RXNE) == 0)
                ;
        return readl(&usart->dr);
@@ -80,7 +125,8 @@ static int stm32_serial_getc(void)
 
 static void stm32_serial_putc(const char c)
 {
 
 static void stm32_serial_putc(const char c)
 {
-       struct stm32_serial *usart = (struct stm32_serial *)USART_BASE;
+       struct stm32_serial *usart =
+               (struct stm32_serial *)usart_base[USART_PORT];
 
        if (c == '\n')
                stm32_serial_putc('\r');
 
        if (c == '\n')
                stm32_serial_putc('\r');
@@ -92,7 +138,8 @@ static void stm32_serial_putc(const char c)
 
 static int stm32_serial_tstc(void)
 {
 
 static int stm32_serial_tstc(void)
 {
-       struct stm32_serial *usart = (struct stm32_serial *)USART_BASE;
+       struct stm32_serial *usart =
+               (struct stm32_serial *)usart_base[USART_PORT];
        u8 ret;
 
        ret = readl(&usart->sr) & USART_SR_FLAG_RXNE;
        u8 ret;
 
        ret = readl(&usart->sr) & USART_SR_FLAG_RXNE;
index 7f569fdac815ded0f72ab3cb32f1554e5c339f29..84cc19df4f6bd68a64d40dc6cbd7aa38c02cc0ba 100644 (file)
 
 #define CONFIG_STM32_GPIO
 #define CONFIG_STM32_SERIAL
 
 #define CONFIG_STM32_GPIO
 #define CONFIG_STM32_SERIAL
-
-#define CONFIG_STM32_USART1
+/*
+ * Configuration of the USART
+ * 1:   TX:PA9  PX:PA10
+ * 2:   TX:PD5  RX:PD6
+ * 3:   TX:PC10 RX:PC11
+ * 6:   TX:PC6  RX:PC7
+ */
+#define CONFIG_STM32_USART             1
 
 #define CONFIG_STM32_HSE_HZ            8000000
 
 
 #define CONFIG_STM32_HSE_HZ            8000000