You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2022/07/11 00:02:29 UTC
[incubator-nuttx] 01/02: stm32g0: add support for USART3 and USART4
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 5c1c18af03a22dd35d1e938d98d3c1b56b8da20e
Author: raiden00pl <ra...@railab.me>
AuthorDate: Thu Jul 7 19:04:11 2022 +0200
stm32g0: add support for USART3 and USART4
---
arch/arm/src/stm32f0l0g0/Kconfig | 2 +
arch/arm/src/stm32f0l0g0/hardware/stm32g0_pinmap.h | 63 ++++++++++-
arch/arm/src/stm32f0l0g0/stm32_serial_v2.c | 115 +++++++++++++++++++--
3 files changed, 167 insertions(+), 13 deletions(-)
diff --git a/arch/arm/src/stm32f0l0g0/Kconfig b/arch/arm/src/stm32f0l0g0/Kconfig
index 9e18961dd1..15912ca3a2 100644
--- a/arch/arm/src/stm32f0l0g0/Kconfig
+++ b/arch/arm/src/stm32f0l0g0/Kconfig
@@ -803,6 +803,8 @@ config STM32F0L0G0_STM32F0
config STM32F0L0G0_STM32G0
bool
default n
+ select STM32F0L0G0_HAVE_USART3
+ select STM32F0L0G0_HAVE_USART4
select STM32F0L0G0_HAVE_DMAMUX
select STM32F0L0G0_HAVE_IP_USART_V2
select STM32F0L0G0_HAVE_IP_EXTI_V2
diff --git a/arch/arm/src/stm32f0l0g0/hardware/stm32g0_pinmap.h b/arch/arm/src/stm32f0l0g0/hardware/stm32g0_pinmap.h
index 6884a25a5a..bf053662ba 100644
--- a/arch/arm/src/stm32f0l0g0/hardware/stm32g0_pinmap.h
+++ b/arch/arm/src/stm32f0l0g0/hardware/stm32g0_pinmap.h
@@ -96,7 +96,41 @@
/* TODO: RTC */
-/* TODO: SPI */
+/* SPI */
+
+#define GPIO_SPI1_SCK_1 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN1)
+#define GPIO_SPI1_SCK_2 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN5)
+#define GPIO_SPI1_SCK_3 (GPIO_ALT | GPIO_AF0 | GPIO_PORTB | GPIO_PIN3)
+#define GPIO_SPI1_SCK_4 (GPIO_ALT | GPIO_AF1 | GPIO_PORTD | GPIO_PIN8)
+#define GPIO_SPI1_MISO_1 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN6)
+#define GPIO_SPI1_MISO_2 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN11)
+#define GPIO_SPI1_MISO_3 (GPIO_ALT | GPIO_AF0 | GPIO_PORTB | GPIO_PIN4)
+#define GPIO_SPI1_MISO_4 (GPIO_ALT | GPIO_AF1 | GPIO_PORTD | GPIO_PIN5)
+#define GPIO_SPI1_MOSI_1 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN2)
+#define GPIO_SPI1_MOSI_2 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN7)
+#define GPIO_SPI1_MOSI_3 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN12)
+#define GPIO_SPI1_MOSI_4 (GPIO_ALT | GPIO_AF0 | GPIO_PORTB | GPIO_PIN5)
+#define GPIO_SPI1_MOSI_5 (GPIO_ALT | GPIO_AF1 | GPIO_PORTD | GPIO_PIN6)
+
+#define GPIO_SPI2_SCK_1 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN0)
+#define GPIO_SPI2_SCK_2 (GPIO_ALT | GPIO_AF0 | GPIO_PORTB | GPIO_PIN13)
+#define GPIO_SPI2_SCK_3 (GPIO_ALT | GPIO_AF1 | GPIO_PORTB | GPIO_PIN13)
+#define GPIO_SPI2_SCK_4 (GPIO_ALT | GPIO_AF1 | GPIO_PORTD | GPIO_PIN1)
+#define GPIO_SPI2_SCK_5 (GPIO_ALT | GPIO_AF5 | GPIO_PORTB | GPIO_PIN10)
+#define GPIO_SPI2_MISO_1 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN3)
+#define GPIO_SPI2_MISO_2 (GPIO_ALT | GPIO_AF4 | GPIO_PORTA | GPIO_PIN9)
+#define GPIO_SPI2_MISO_3 (GPIO_ALT | GPIO_AF1 | GPIO_PORTB | GPIO_PIN2)
+#define GPIO_SPI2_MISO_4 (GPIO_ALT | GPIO_AF4 | GPIO_PORTB | GPIO_PIN6)
+#define GPIO_SPI2_MISO_5 (GPIO_ALT | GPIO_AF0 | GPIO_PORTB | GPIO_PIN14)
+#define GPIO_SPI2_MISO_6 (GPIO_ALT | GPIO_AF1 | GPIO_PORTC | GPIO_PIN2)
+#define GPIO_SPI2_MISO_7 (GPIO_ALT | GPIO_AF1 | GPIO_PORTD | GPIO_PIN3)
+#define GPIO_SPI2_MOSI_1 (GPIO_ALT | GPIO_AF1 | GPIO_PORTA | GPIO_PIN4)
+#define GPIO_SPI2_MOSI_2 (GPIO_ALT | GPIO_AF0 | GPIO_PORTA | GPIO_PIN10)
+#define GPIO_SPI2_MOSI_3 (GPIO_ALT | GPIO_AF1 | GPIO_PORTB | GPIO_PIN7)
+#define GPIO_SPI2_MOSI_4 (GPIO_ALT | GPIO_AF1 | GPIO_PORTB | GPIO_PIN11)
+#define GPIO_SPI2_MOSI_5 (GPIO_ALT | GPIO_AF0 | GPIO_PORTB | GPIO_PIN15)
+#define GPIO_SPI2_MOSI_6 (GPIO_ALT | GPIO_AF1 | GPIO_PORTC | GPIO_PIN3)
+#define GPIO_SPI2_MOSI_7 (GPIO_ALT | GPIO_AF1 | GPIO_PORTD | GPIO_PIN4)
/* Timers */
@@ -192,9 +226,30 @@
#define GPIO_USART2_TX_2 (GPIO_ALT | GPIO_PULLUP | GPIO_AF1 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN14)
#define GPIO_USART2_TX_3 (GPIO_ALT | GPIO_PULLUP | GPIO_AF0 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTD | GPIO_PIN6)
-/* TODO: USART3 */
-
-/* TODO: USART4 */
+#define GPIO_USART3_CTS_1 (GPIO_ALT | GPIO_AF4 | GPIO_PORTA | GPIO_PIN6)
+#define GPIO_USART3_CTS_2 (GPIO_ALT | GPIO_AF4 | GPIO_PORTB | GPIO_PIN13)
+#define GPIO_USART3_RX_1 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN3)
+#define GPIO_USART3_RX_2 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN0)
+#define GPIO_USART3_RX_3 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN9)
+#define GPIO_USART3_RX_4 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN11)
+#define GPIO_USART3_RX_5 (GPIO_ALT | GPIO_PULLUP | GPIO_AF0 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTC | GPIO_PIN5)
+#define GPIO_USART3_RX_6 (GPIO_ALT | GPIO_PULLUP | GPIO_AF0 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTC | GPIO_PIN11)
+#define GPIO_USART3_TX_1 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN5)
+#define GPIO_USART3_TX_2 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN2)
+#define GPIO_USART3_TX_3 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN8)
+#define GPIO_USART3_TX_4 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTB | GPIO_PIN10)
+#define GPIO_USART3_TX_5 (GPIO_ALT | GPIO_PULLUP | GPIO_AF0 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTC | GPIO_PIN4)
+#define GPIO_USART3_TX_6 (GPIO_ALT | GPIO_PULLUP | GPIO_AF0 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTC | GPIO_PIN10)
+#define GPIO_USART3_RTS_1 (GPIO_ALT | GPIO_AF5 | GPIO_PORTA | GPIO_PIN15)
+#define GPIO_USART3_RTS_2 (GPIO_ALT | GPIO_AF4 | GPIO_PORTB | GPIO_PIN1)
+#define GPIO_USART3_RTS_3 (GPIO_ALT | GPIO_AF4 | GPIO_PORTB | GPIO_PIN14)
+
+#define GPIO_USART4_CTS_1 (GPIO_ALT | GPIO_AF4 | GPIO_PORTB | GPIO_PIN7)
+#define GPIO_USART4_RX_1 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN1)
+#define GPIO_USART4_RX_2 (GPIO_ALT | GPIO_PULLUP | GPIO_AF1 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTC | GPIO_PIN11)
+#define GPIO_USART4_TX_1 (GPIO_ALT | GPIO_PULLUP | GPIO_AF4 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTA | GPIO_PIN0)
+#define GPIO_USART4_TX_2 (GPIO_ALT | GPIO_PULLUP | GPIO_AF1 | GPIO_SPEED_HIGH | GPIO_PUSHPULL | GPIO_PORTC | GPIO_PIN10)
+#define GPIO_USART4_RTS_1 (GPIO_ALT | GPIO_AF4 | GPIO_PORTA | GPIO_PIN15)
/* TODO: LPTIM */
diff --git a/arch/arm/src/stm32f0l0g0/stm32_serial_v2.c b/arch/arm/src/stm32f0l0g0/stm32_serial_v2.c
index ff607e46ea..a9e836bbc3 100644
--- a/arch/arm/src/stm32f0l0g0/stm32_serial_v2.c
+++ b/arch/arm/src/stm32f0l0g0/stm32_serial_v2.c
@@ -52,13 +52,6 @@
#include <arch/board/board.h>
-#ifdef CONFIG_STM32F0L0G0_USART3
-# error not supported yet
-#endif
-#ifdef CONFIG_STM32F0L0G0_USART4
-# error not supported yet
-#endif
-
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -349,9 +342,113 @@ static struct up_dev_s g_usart2priv =
};
#endif
-/* TODO: USART3 */
+/* This describes the state of the STM32 USART3 port. */
+
+#ifdef CONFIG_STM32F0L0G0_USART3
+static struct up_dev_s g_usart3priv =
+{
+ .dev =
+ {
+#if CONSOLE_USART == 3
+ .isconsole = true,
+#endif
+ .recv =
+ {
+ .size = CONFIG_USART3_RXBUFSIZE,
+ .buffer = g_usart3rxbuffer,
+ },
+ .xmit =
+ {
+ .size = CONFIG_USART3_TXBUFSIZE,
+ .buffer = g_usart3txbuffer,
+ },
+ .ops = &g_uart_ops,
+ .priv = &g_usart3priv,
+ },
+
+ .irq = STM32_IRQ_USART3,
+ .rxftcfg = 0, /* No FIFO */
+ .parity = CONFIG_USART3_PARITY,
+ .bits = CONFIG_USART3_BITS,
+ .stopbits2 = CONFIG_USART3_2STOP,
+ .baud = CONFIG_USART3_BAUD,
+ .apbclock = STM32_PCLK1_FREQUENCY,
+ .usartbase = STM32_USART3_BASE,
+ .tx_gpio = GPIO_USART3_TX,
+ .rx_gpio = GPIO_USART3_RX,
+#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART3_OFLOWCONTROL)
+ .oflow = true,
+ .cts_gpio = GPIO_USART3_CTS,
+#endif
+#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART3_IFLOWCONTROL)
+ .iflow = true,
+ .rts_gpio = GPIO_USART3_RTS,
+#endif
-/* TODO: USART4 */
+#ifdef CONFIG_USART3_RS485
+ .rs485_dir_gpio = GPIO_USART3_RS485_DIR,
+# if (CONFIG_USART3_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
+};
+#endif
+
+/* This describes the state of the STM32 USART4 port. */
+
+#ifdef CONFIG_STM32F0L0G0_USART4
+static struct up_dev_s g_usart4priv =
+{
+ .dev =
+ {
+#if CONSOLE_USART == 4
+ .isconsole = true,
+#endif
+ .recv =
+ {
+ .size = CONFIG_USART4_RXBUFSIZE,
+ .buffer = g_usart4rxbuffer,
+ },
+ .xmit =
+ {
+ .size = CONFIG_USART4_TXBUFSIZE,
+ .buffer = g_usart4txbuffer,
+ },
+ .ops = &g_uart_ops,
+ .priv = &g_usart4priv,
+ },
+
+ .irq = STM32_IRQ_USART4,
+ .rxftcfg = 0, /* No FIFO */
+ .parity = CONFIG_USART4_PARITY,
+ .bits = CONFIG_USART4_BITS,
+ .stopbits2 = CONFIG_USART4_2STOP,
+ .baud = CONFIG_USART4_BAUD,
+ .apbclock = STM32_PCLK1_FREQUENCY,
+ .usartbase = STM32_USART4_BASE,
+ .tx_gpio = GPIO_USART4_TX,
+ .rx_gpio = GPIO_USART4_RX,
+#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART4_OFLOWCONTROL)
+ .oflow = true,
+ .cts_gpio = GPIO_USART4_CTS,
+#endif
+#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART4_IFLOWCONTROL)
+ .iflow = true,
+ .rts_gpio = GPIO_USART4_RTS,
+#endif
+
+#ifdef CONFIG_USART4_RS485
+ .rs485_dir_gpio = GPIO_USART4_RS485_DIR,
+# if (CONFIG_USART4_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
+};
+#endif
/* This table lets us iterate over the configured USARTs */