【记录】STM32 printf函数实现方法
2016-07-02 21:14
357 查看
概要
使用USART1,实现printf。printf是标准库函数,在使用的需要包含stdio.h头文件。在prinft内部最终调用fputc库函数,因此需要重写fputc库函数,将要输出的内容输出到串口上。实现
#include "usart.h" #pragma import(__use_no_semihosting) struct __FILE { int handle; /* Whatever you require here. If the only file you are using is */ /* standard output using printf() for debugging, no file handling */ /* is required. */ }; /* FILE is typedef’ d in stdio.h. */ FILE __stdout; _sys_exit(int x) { x = x; } //redefine fputc using USART1 int fputc(int ch, FILE *f) { //status register, [6]transmission complete while((USART1->SR & 0x40) == 0); USART1->DR = (u8)ch; return ch; } void uart_init(u32 pclk2, u32 bound) { //initialize usart1 }
参考
1. STM32 Printf函数实现方法2. 实现STM32的串口数据发送和printf函数重定向
相关文章推荐
- STL之优先级队列priority_queue
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- PHP面向对象继承的概念
- Android: Color State List Resource (颜色申明列表资源)
- Qt学习笔记4---网络编程
- 如何校验json格式的正确性
- GRE and VXLAN with Open vSwitch
- Nutz-使用Jspview跳转页面报404
- bzoj3029 守卫者的挑战
- 51定时器初值的计算
- io