STM32中printf重定向到串口
来源:互联网 发布:保险网络大学报名 编辑:程序博客网 时间:2024/04/27 16:55
STM32中printf重定向到串口
转载自:http://blog.csdn.net/wdscq1234/article/details/7944036
学习STM32过程中,经常打交道的莫过于串口,你可以将任何信息,当然重要的是调试信息打印到串口中输出,总是用一个字节发送函数或者字符串发送函数
总是有些不放便,之前编程中熟悉的莫过于printf了,下面就给出了用printf打印到串口的方案,当然方案不止一个,仅供参考。
1、 添加printf的头文件 #include <stdio.h>
2、重写int fputc(int ch, FILE *f)函数
int fputc(int ch, FILE *f);
函数
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}
3、修改一下选中Use MicroLIB Target——Code Generation——选中Use MicroLIB
这样就可以像以前那样使用printf了。
重定向C库函数printf到USART1
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
return (ch);
}
重定向C库函数scanf到USART1
int fgetc(FILE *f)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART1);
}
- STM32中printf重定向到串口
- STM32中printf重定向到串口
- STM32中printf重定向到串口
- STM32输出调试信息-printf重定向到串口
- STM32串口通信printf重定向方法
- STM32-串口通信printf重定向
- STM32中重定向printf到SWO口
- STM32中重定位printf到串口输出
- STM32-printf重定向到USART
- 关于printf重定向到串口
- Keil C51重定向printf到串口
- Keil C51重定向printf到串口
- 串口输出重定向到 printf
- Keil C51重定向printf到串口
- keil C51 重定向printf到串口
- stm32为什么用printf重定向到串口第一个字符打印不出
- 【STM32】keil MDK下重定向printf到串口(基于STM32CubeMX)
- STM32 printf重定向
- InstallShield创建自定义对话框 实例2
- android 编译出来的执行文件 not executable: magic 7F45
- 【iOS解决方案】如何判断当前网络连接状态(网络是否正常)
- gdal应用-gdal_translate
- '_ConnectionPtr' : missing storage-class or type specifiers
- STM32中printf重定向到串口
- 一致性哈希算法
- Quartz2D之渐变使用初步
- mac 编辑 .bash_profile
- linux安装使用svn
- Qt程序发布
- Linux内核module_param的使用
- Linux设备驱动(一)
- spring MVC配置详解