From 82f489bf5c646bdf76c1af29af3c6aac5e2fdb1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=B2=B9=E7=82=B8=E9=B8=A1?= <1425962791@qq.com> Date: Sun, 19 Oct 2025 12:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E4=B8=B2=E5=8F=A3=E6=8E=A5?= =?UTF-8?q?=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Power_Pico/Core/Inc/usart.h | 3 ++- Power_Pico/Core/Src/stm32f4xx_it.c | 3 ++- Power_Pico/Core/Src/usart.c | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Power_Pico/Core/Inc/usart.h b/Power_Pico/Core/Inc/usart.h index c7eeb59..e79edbb 100644 --- a/Power_Pico/Core/Inc/usart.h +++ b/Power_Pico/Core/Inc/usart.h @@ -36,7 +36,8 @@ extern UART_HandleTypeDef huart6; /* USER CODE BEGIN Private defines */ #define USART_RX_BUFFER_SIZE 25 -extern uint8_t uart_receive_str[USART_RX_BUFFER_SIZE + 1]; +extern uint8_t uart_receive_buf[USART_RX_BUFFER_SIZE + 1]; +extern uint8_t uart_receive_flag; /* USER CODE END Private defines */ void MX_USART6_UART_Init(void); diff --git a/Power_Pico/Core/Src/stm32f4xx_it.c b/Power_Pico/Core/Src/stm32f4xx_it.c index 44b129a..3940eea 100644 --- a/Power_Pico/Core/Src/stm32f4xx_it.c +++ b/Power_Pico/Core/Src/stm32f4xx_it.c @@ -250,9 +250,10 @@ void USART6_IRQHandler(void) /* USER CODE BEGIN USART6_IRQn 0 */ if(__HAL_UART_GET_FLAG(&huart6, UART_FLAG_IDLE) != RESET) { + uart_receive_flag = 1; __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_IDLE); HAL_UART_DMAStop(&huart6); - HAL_UART_Receive_DMA(&huart6, uart_receive_str, USART_RX_BUFFER_SIZE); + HAL_UART_Receive_DMA(&huart6, uart_receive_buf, USART_RX_BUFFER_SIZE); } /* USER CODE END USART6_IRQn 0 */ diff --git a/Power_Pico/Core/Src/usart.c b/Power_Pico/Core/Src/usart.c index c4050b0..5876168 100644 --- a/Power_Pico/Core/Src/usart.c +++ b/Power_Pico/Core/Src/usart.c @@ -21,9 +21,11 @@ #include "usart.h" /* USER CODE BEGIN 0 */ +#include "stdio.h" // memeory for receive string -uint8_t uart_receive_str[USART_RX_BUFFER_SIZE + 1]; +uint8_t uart_receive_buf[USART_RX_BUFFER_SIZE + 1]; +uint8_t uart_receive_flag = 0; // flag for receive complete /* USER CODE END 0 */ @@ -162,6 +164,12 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) /* USER CODE BEGIN 1 */ +int fputc(int ch, FILE *f) +{ + HAL_UART_Transmit(&huart6, (uint8_t *)&ch, 1, 0xffff); + return ch; +} + //串口6发送 void UART6_TX_Send(uint8_t *buffer, uint16_t length) {