This is send by HAL This is send by HAL This is send by HAL This is send by HAL This is send by HAL This is send by HAL This is send by HAL
这个方案只显示了通过串口发送的数据,没有显示通过printf发送的数据
方案二
1 2 3 4 5
int __io_putchar(int ch) { HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xFFFF); return ch; }
1 2 3 4 5 6 7 8 9 10 11
HelloWorld This is send by HAL HelloWorld This is send by HAL HelloWorld This is send by HAL HelloWorld This is send by HAL HelloWorld This is send by HAL HelloWorld
voidStartDefaultTask(void *argument) { /* USER CODE BEGIN StartDefaultTask */ /* Infinite loop */ char hal_msg[] = "This is send by HAL\n"; while (1) { printf("HelloWorld\n"); HAL_UART_Transmit(&huart1,hal_msg,strlen(hal_msg),0xffff); HAL_Delay(1000); /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ } /* USER CODE END StartDefaultTask */ }
非常奇怪,上面这段代码有时候能正常工作,有时候会出现下面的问题
1 2 3 4
writer.c:(.text._write_r+0x14): undefined reference to `_write' closer.c:(.text._close_r+0xc): undefined reference to `_close' fstatr.c:(.text._fstat_r+0x12): undefined reference to `_fstat' isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'