diff options
| author | hathach <[email protected]> | 2026-04-03 12:51:06 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-04-03 16:33:03 +0700 |
| commit | e82df22375ac22ffddf86234a818bb7f4d66af7c (patch) | |
| tree | e25bb44569b3700bb4bbdb0a21f62bd971298c86 /hw/bsp/stm32u0 | |
| parent | 9368e5d40f3d8e5ac323d288f969782a962d593e (diff) | |
stm32 add uart hwfifo if supported, otherwise usb tu_fifo_t for receive uart in irq
Diffstat (limited to 'hw/bsp/stm32u0')
| -rw-r--r-- | hw/bsp/stm32u0/family.c | 29 | ||||
| -rw-r--r-- | hw/bsp/stm32u0/family.mk | 3 |
2 files changed, 26 insertions, 6 deletions
diff --git a/hw/bsp/stm32u0/family.c b/hw/bsp/stm32u0/family.c index af39ae398..4acbb3437 100644 --- a/hw/bsp/stm32u0/family.c +++ b/hw/bsp/stm32u0/family.c @@ -115,6 +115,7 @@ void board_init(void) { UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; HAL_UART_Init(&UartHandle); + HAL_UARTEx_EnableFifoMode(&UartHandle); #endif #if CFG_TUSB_OS == OPT_OS_FREERTOS @@ -154,17 +155,35 @@ uint32_t board_button_read(void) { int board_uart_read(uint8_t* buf, int len) { #ifdef UART_DEV - (void) buf; (void) len; - return 0; + int count = 0; + while (count < len) { + if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_RXNE)) { + buf[count] = (uint8_t) UartHandle.Instance->RDR; + count++; + } else { + break; + } + } + return count; #else + (void) buf; (void) len; return 0; #endif } -int board_uart_write(void const * buf, int len) { +int board_uart_write(void const *buf, int len) { #ifdef UART_DEV - HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff); - return len; + const uint8_t *p = (const uint8_t *) buf; + int count = 0; + while (count < len) { + if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TXE)) { + UartHandle.Instance->TDR = p[count]; + count++; + } else { + break; + } + } + return count; #else (void) buf; (void) len; return 0; diff --git a/hw/bsp/stm32u0/family.mk b/hw/bsp/stm32u0/family.mk index 241323f62..9119f3652 100644 --- a/hw/bsp/stm32u0/family.mk +++ b/hw/bsp/stm32u0/family.mk @@ -35,7 +35,8 @@ SRC_C += \ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \ ${ST_HAL_DRIVER}/Src/stm32$(ST_FAMILY)xx_hal_pwr_ex.c \ - $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c + $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \ + $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c INC += \ $(TOP)/$(BOARD_PATH) \ |
