summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Conrad <[email protected]>2020-03-28 11:19:50 -0400
committerNathan Conrad <[email protected]>2020-03-28 12:05:30 -0400
commit3926b28faa347b9984b2ebce76b122ec4718be4b (patch)
treed63cb9b54f2be966d637ada1c10a7473759d6b37
parent4191363c5585ffa0645e12da072b97f0da4c596a (diff)
Update UARTs for stm32f4xx discovery boards. Other minor cleanups.
-rw-r--r--hw/bsp/stm32f407disco/board.mk2
-rw-r--r--hw/bsp/stm32f407disco/stm32f407disco.c3
-rw-r--r--hw/bsp/stm32f407disco/stm32f4xx_hal_conf.h2
-rw-r--r--hw/bsp/stm32f411disco/board.mk1
-rw-r--r--hw/bsp/stm32f411disco/stm32f411disco.c34
-rw-r--r--hw/bsp/stm32f411disco/stm32f4xx_hal_conf.h2
-rw-r--r--hw/bsp/stm32f412disco/board.mk1
-rw-r--r--hw/bsp/stm32f412disco/stm32f412disco.c38
-rw-r--r--hw/bsp/stm32f412disco/stm32f4xx_hal_conf.h2
9 files changed, 71 insertions, 14 deletions
diff --git a/hw/bsp/stm32f407disco/board.mk b/hw/bsp/stm32f407disco/board.mk
index 92c349d09..92e021538 100644
--- a/hw/bsp/stm32f407disco/board.mk
+++ b/hw/bsp/stm32f407disco/board.mk
@@ -19,8 +19,8 @@ SRC_C += \
$(ST_CMSIS)/Source/Templates/system_stm32f4xx.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \
- $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
+ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c
SRC_S += \
diff --git a/hw/bsp/stm32f407disco/stm32f407disco.c b/hw/bsp/stm32f407disco/stm32f407disco.c
index d1e927f2a..c6cc5e9aa 100644
--- a/hw/bsp/stm32f407disco/stm32f407disco.c
+++ b/hw/bsp/stm32f407disco/stm32f407disco.c
@@ -36,7 +36,6 @@
#define BUTTON_PIN GPIO_PIN_0
#define BUTTON_STATE_ACTIVE 1
-
// Enable PA2 as the debug log UART
// It is not routed to the ST/Link on the Discovery board.
#define UARTx USART2
@@ -114,7 +113,7 @@ void board_init(void)
SystemClock_Config();
all_rcc_clk_enable();
-#if CFG_TUSB_OS == OPT_OS_NONE
+#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
diff --git a/hw/bsp/stm32f407disco/stm32f4xx_hal_conf.h b/hw/bsp/stm32f407disco/stm32f4xx_hal_conf.h
index 4ff7793f7..7864f8d5f 100644
--- a/hw/bsp/stm32f407disco/stm32f4xx_hal_conf.h
+++ b/hw/bsp/stm32f407disco/stm32f4xx_hal_conf.h
@@ -68,7 +68,7 @@
/* #define HAL_SD_MODULE_ENABLED */
// #define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */
-/* #define HAL_UART_MODULE_ENABLED */
+#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
diff --git a/hw/bsp/stm32f411disco/board.mk b/hw/bsp/stm32f411disco/board.mk
index 16d90e086..a5ea8cab2 100644
--- a/hw/bsp/stm32f411disco/board.mk
+++ b/hw/bsp/stm32f411disco/board.mk
@@ -20,6 +20,7 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
+ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c
SRC_S += \
diff --git a/hw/bsp/stm32f411disco/stm32f411disco.c b/hw/bsp/stm32f411disco/stm32f411disco.c
index acbcc405e..8f97eff01 100644
--- a/hw/bsp/stm32f411disco/stm32f411disco.c
+++ b/hw/bsp/stm32f411disco/stm32f411disco.c
@@ -28,6 +28,7 @@
#include "stm32f4xx_hal.h"
+// Orange LED
#define LED_PORT GPIOD
#define LED_PIN GPIO_PIN_13
#define LED_STATE_ON 1
@@ -36,11 +37,21 @@
#define BUTTON_PIN GPIO_PIN_0
#define BUTTON_STATE_ACTIVE 1
+// Enable PA2 as the debug log UART
+#define UARTx USART2
+#define UART_GPIO_PORT GPIOA
+#define UART_GPIO_AF GPIO_AF7_USART2
+#define UART_TX_PIN GPIO_PIN_2
+#define UART_RX_PIN GPIO_PIN_3
+
+UART_HandleTypeDef UartHandle;
+
// enable all LED, Button, Uart, USB clock
static void all_rcc_clk_enable(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button
__HAL_RCC_GPIOD_CLK_ENABLE(); // LED
+ __HAL_RCC_USART2_CLK_ENABLE(); // Uart module
}
/**
@@ -151,6 +162,25 @@ void board_init(void)
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+ GPIO_InitStruct.Alternate = UART_GPIO_AF;
+ HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
+
+ UartHandle = (UART_HandleTypeDef){
+ .Instance = UARTx,
+ .Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
+ .Init.WordLength = UART_WORDLENGTH_8B,
+ .Init.StopBits = UART_STOPBITS_1,
+ .Init.Parity = UART_PARITY_NONE,
+ .Init.HwFlowCtl = UART_HWCONTROL_NONE,
+ .Init.Mode = UART_MODE_TX_RX,
+ .Init.OverSampling = UART_OVERSAMPLING_16
+ };
+ HAL_UART_Init(&UartHandle);
+
// Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
@@ -181,8 +211,8 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len)
{
- (void) buf; (void) len;
- return 0;
+ HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
+ return len;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/stm32f411disco/stm32f4xx_hal_conf.h b/hw/bsp/stm32f411disco/stm32f4xx_hal_conf.h
index 4ff7793f7..7864f8d5f 100644
--- a/hw/bsp/stm32f411disco/stm32f4xx_hal_conf.h
+++ b/hw/bsp/stm32f411disco/stm32f4xx_hal_conf.h
@@ -68,7 +68,7 @@
/* #define HAL_SD_MODULE_ENABLED */
// #define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */
-/* #define HAL_UART_MODULE_ENABLED */
+#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
diff --git a/hw/bsp/stm32f412disco/board.mk b/hw/bsp/stm32f412disco/board.mk
index 2976464f4..2a3ecbddd 100644
--- a/hw/bsp/stm32f412disco/board.mk
+++ b/hw/bsp/stm32f412disco/board.mk
@@ -24,6 +24,7 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc_ex.c \
+ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_uart.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c
SRC_S += \
diff --git a/hw/bsp/stm32f412disco/stm32f412disco.c b/hw/bsp/stm32f412disco/stm32f412disco.c
index 4d60112f6..f64fa3f01 100644
--- a/hw/bsp/stm32f412disco/stm32f412disco.c
+++ b/hw/bsp/stm32f412disco/stm32f412disco.c
@@ -26,24 +26,31 @@
#include "../board.h"
-#include "stm32f4xx.h"
-#include "stm32f4xx_hal_conf.h"
+#include "stm32f4xx_hal.h"
#define LED_PORT GPIOE
#define LED_PIN GPIO_PIN_2
#define LED_STATE_ON 0
-// Joystick selection
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PIN_0
#define BUTTON_STATE_ACTIVE 1
+// Enable PA2 as the debug log UART
+#define UARTx USART2
+#define UART_GPIO_PORT GPIOA
+#define UART_GPIO_AF GPIO_AF7_USART2
+#define UART_TX_PIN GPIO_PIN_2
+#define UART_RX_PIN GPIO_PIN_3
+
+UART_HandleTypeDef UartHandle;
// enable all LED, Button, Uart, USB clock
static void all_rcc_clk_enable(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button
__HAL_RCC_GPIOE_CLK_ENABLE(); // LED
+ __HAL_RCC_USART2_CLK_ENABLE(); // Uart module
}
/**
@@ -104,6 +111,8 @@ static void SystemClock_Config(void)
PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CK48;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLI2SQ;
+ PeriphClkInitStruct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC;
+ PeriphClkInitStruct.PLLI2S.PLLI2SR = 7;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
@@ -118,7 +127,6 @@ static void SystemClock_Config(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
}
-
void board_init(void)
{
SystemClock_Config();
@@ -179,6 +187,24 @@ void board_init(void)
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
+ GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+ GPIO_InitStruct.Alternate = UART_GPIO_AF;
+ HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
+
+ UartHandle = (UART_HandleTypeDef){
+ .Instance = UARTx,
+ .Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
+ .Init.WordLength = UART_WORDLENGTH_8B,
+ .Init.StopBits = UART_STOPBITS_1,
+ .Init.Parity = UART_PARITY_NONE,
+ .Init.HwFlowCtl = UART_HWCONTROL_NONE,
+ .Init.Mode = UART_MODE_TX_RX,
+ .Init.OverSampling = UART_OVERSAMPLING_16
+ };
+ HAL_UART_Init(&UartHandle);
// Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
@@ -209,8 +235,8 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len)
{
- (void) buf; (void) len;
- return 0;
+ HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
+ return len;
}
#if CFG_TUSB_OS == OPT_OS_NONE
diff --git a/hw/bsp/stm32f412disco/stm32f4xx_hal_conf.h b/hw/bsp/stm32f412disco/stm32f4xx_hal_conf.h
index 4ff7793f7..7864f8d5f 100644
--- a/hw/bsp/stm32f412disco/stm32f4xx_hal_conf.h
+++ b/hw/bsp/stm32f412disco/stm32f4xx_hal_conf.h
@@ -68,7 +68,7 @@
/* #define HAL_SD_MODULE_ENABLED */
// #define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */
-/* #define HAL_UART_MODULE_ENABLED */
+#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */