第三步:串口重定向,在usart.c中添加如下代码。具体的参考上一篇文章串口使用
- // 需要调用stdio.h文件
- #include <stdio.h>
- //取消ARM的半主机工作模式
- #pragma import(__use_no_semihosting)//标准库需要的支持函数
- struct __FILE
- {
- int handle;
- };
- FILE __stdout;
- void _sys_exit(int x) //定义_sys_exit()以避免使用半主机模式
- {
- x = x;
- }
- int fputc(int ch, FILE *f)
- {
- HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff);
- return ch;
- }
|