diff options
| author | hathach <[email protected]> | 2026-04-03 19:38:07 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-04-03 19:38:07 +0700 |
| commit | 81efb78d1655dcab31da5e03fd7e22e91491d186 (patch) | |
| tree | 0ea8eafc8730146e3a29f3e0349bfa3d02fa635a /hw/bsp/stm32c0 | |
| parent | 3ed9d6517485611b040ecdc4e5d327b6e86f3dee (diff) | |
update stm32 to use better uart id
Diffstat (limited to 'hw/bsp/stm32c0')
| -rw-r--r-- | hw/bsp/stm32c0/boards/stm32c071nucleo/board.h | 3 | ||||
| -rw-r--r-- | hw/bsp/stm32c0/family.c | 22 |
2 files changed, 18 insertions, 7 deletions
diff --git a/hw/bsp/stm32c0/boards/stm32c071nucleo/board.h b/hw/bsp/stm32c0/boards/stm32c071nucleo/board.h index 460b42a21..085d0d721 100644 --- a/hw/bsp/stm32c0/boards/stm32c071nucleo/board.h +++ b/hw/bsp/stm32c0/boards/stm32c071nucleo/board.h @@ -54,8 +54,7 @@ #define BUTTON_STATE_ACTIVE 0 // Enable UART serial communication with the ST-Link -#define UART_DEV USART2 -#define UART_CLK_EN __HAL_RCC_USART2_CLK_ENABLE +#define UART_ID 2 #define UART_GPIO_PORT GPIOA #define UART_GPIO_AF GPIO_AF1_USART2 #define UART_TX_PIN GPIO_PIN_2 diff --git a/hw/bsp/stm32c0/family.c b/hw/bsp/stm32c0/family.c index d99720a64..72af3ce7f 100644 --- a/hw/bsp/stm32c0/family.c +++ b/hw/bsp/stm32c0/family.c @@ -33,6 +33,16 @@ #include "bsp/board_api.h" #include "board.h" +#ifdef UART_ID + #if UART_ID == 1 + #define USARTn USART1 + #define UARTn_CLK_ENABLE __HAL_RCC_USART1_CLK_ENABLE + #elif UART_ID == 2 + #define USARTn USART2 + #define UARTn_CLK_ENABLE __HAL_RCC_USART2_CLK_ENABLE + #endif +#endif + //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler //--------------------------------------------------------------------+ @@ -49,7 +59,9 @@ void USB_IRQHandler(void) { //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM //--------------------------------------------------------------------+ +#ifdef UART_ID UART_HandleTypeDef UartHandle; +#endif void board_init(void) { HAL_Init(); @@ -93,8 +105,8 @@ void board_init(void) { HAL_GPIO_Init(BUTTON_PORT, &gpio_init); } -#ifdef UART_DEV - UART_CLK_EN(); +#ifdef UART_ID + UARTn_CLK_ENABLE(); // UART { GPIO_InitTypeDef gpio_init = { 0 }; @@ -107,7 +119,7 @@ void board_init(void) { } UartHandle = (UART_HandleTypeDef){ - .Instance = UART_DEV, + .Instance = USARTn, .Init.BaudRate = CFG_BOARD_UART_BAUDRATE, .Init.WordLength = UART_WORDLENGTH_8B, .Init.StopBits = UART_STOPBITS_1, @@ -149,7 +161,7 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) { } int board_uart_read(uint8_t *buf, int len) { -#ifdef UART_DEV +#ifdef UART_ID int count = 0; while (count < len) { if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_RXNE)) { @@ -167,7 +179,7 @@ int board_uart_read(uint8_t *buf, int len) { } int board_uart_write(void const *buf, int len) { -#ifdef UART_DEV +#ifdef UART_ID const uint8_t *p = (const uint8_t *) buf; int count = 0; while (count < len) { |
