|
|
@@ -65,18 +65,18 @@ static void MX_USART3_UART_Init(void);
|
|
|
#include <stdio.h>
|
|
|
|
|
|
// 重定向fputc函数到USART1
|
|
|
-int _write(int file, char *ptr, int len)
|
|
|
-{
|
|
|
- HAL_UART_Transmit(&huart1, (uint8_t*)ptr, len, HAL_MAX_DELAY);
|
|
|
- return len;
|
|
|
-}
|
|
|
-
|
|
|
-int fputc(int ch, FILE *f)
|
|
|
-{
|
|
|
- uint8_t c = ch;
|
|
|
- HAL_UART_Transmit(&huart1, &c, 1, HAL_MAX_DELAY);
|
|
|
- return ch;
|
|
|
-}
|
|
|
+// int _write(int file, char *ptr, int len)
|
|
|
+// {
|
|
|
+// HAL_UART_Transmit(&huart1, (uint8_t*)ptr, len, HAL_MAX_DELAY);
|
|
|
+// return len;
|
|
|
+// }
|
|
|
+//
|
|
|
+// int fputc(int ch, FILE *f)
|
|
|
+// {
|
|
|
+// uint8_t c = ch;
|
|
|
+// HAL_UART_Transmit(&huart1, &c, 1, HAL_MAX_DELAY);
|
|
|
+// return ch;
|
|
|
+// }
|
|
|
|
|
|
int __io_putchar(int ch)
|
|
|
{
|
|
|
@@ -121,11 +121,12 @@ int main(void)
|
|
|
MX_USART3_UART_Init();
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
// 启动 USART2 DMA 接收
|
|
|
- HAL_UART_Receive_DMA(&huart2, rx_buf, sizeof(rx_buf));
|
|
|
- // 使能 USART2 空闲中断
|
|
|
- __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
|
|
|
+ // HAL_UART_Receive_DMA(&huart2, rx_buf, sizeof(rx_buf));
|
|
|
+ // // 使能 USART2 空闲中断
|
|
|
+ // __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
|
|
|
|
|
|
printf("USART2 DMA + IDLE 中断接收已启动\r\n");
|
|
|
+ uint8_t i = 0;
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Infinite loop */
|
|
|
@@ -134,15 +135,18 @@ int main(void)
|
|
|
{
|
|
|
/* USER CODE END WHILE */
|
|
|
// 用 printf 输出(printf 已经重定向到 USART2)
|
|
|
- printf("hello world task 2\r\n");
|
|
|
+ // printf("hello world task 2\r\n");
|
|
|
|
|
|
// 发送一个字符串到UART2
|
|
|
const char *msg = "12345hhl789099999999999999999999999999999999999999999999999999999999899999999999999999999999999999999999999999999fdasfdeqrftewqtrewfgdaf9999999999999fdasffdsafdsafdsafdsafddsafsdddddddddddddddddd88888888888888888888888888888888888888888ddddddddddddddddddssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss99999999999999999999999999999999999999999990078rewqreqwrewqrewqfdsafdsafewqfdsafewqfdsafew fdsafe77xxy888";
|
|
|
- HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
|
|
|
-
|
|
|
- printf("Received data: %s\r\n", rx_buf);
|
|
|
- memset(rx_buf, '\0', 500);
|
|
|
- printf("111\r\n");
|
|
|
+ // HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
|
|
|
+ //
|
|
|
+ // printf("Received data: %s\r\n", rx_buf);
|
|
|
+ // memset(rx_buf, '\0', 500);
|
|
|
+ // printf("%02X\r\n",i++);
|
|
|
+ // printf("%d\r\n",strlen(msg));
|
|
|
+ HAL_UART_Transmit(&huart1, msg, strlen(msg), 100);
|
|
|
+ i++;
|
|
|
HAL_Delay(1000);
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
}
|