当前位置:网站首页>STM32CubeMX重定向printf输出至串口
STM32CubeMX重定向printf输出至串口
2022-04-22 13:00:00 【范子琦】
STM32CubeMX重定向printf输出至串口
第一步,CubeMX配置串口(GPIO配置略)

第二步,包含头文件
#include <stdio.h>
第三步,勾选Use Microlib

第四步,重定向printf,此处需要将huart2改为上面配置的串口
int fputc(int c, FILE *stream)
{
HAL_UART_Transmit(&huart2, (unsigned char *)&c, 1, 1000);
return 1;
}
此时即可使用
printf("%d\r\n",num);
代替
buf_len = sprintf(buf, "%d\r\n",num);
HAL_UART_Transmit(&huart2, (uint8_t *)buf, buf_len, 100);
版权声明
本文为[范子琦]所创,转载请带上原文链接,感谢
https://blog.csdn.net/oXiaoLingTong/article/details/123161235
边栏推荐
- JS random color
- Sprintf format string
- 21. merge two ordered linked lists
- 借助数商云房地产行业采购平台解决方案,实现简单、智能、合规的采购
- 21. 合并两个有序链表
- Under the pressure of sanctions, Russia plans to import electronic products in parallel through friendly countries
- ORB_ Slam3 learning: introduction to tracking thread
- 企业邮箱的边边角角
- 让cpolar获得固定TCP地址
- 如何使用Colormaps和自定义自己喜欢的colorbar?
猜你喜欢

C#中如何将图片添加为程序的资源

Machine learning 7- logistic regression to realize the binary classification of watermelon dataset 2.0

深度学习笔记(一 误差)

sprintf格式化字符串

Leetcode 206, reverse linked list

利用OpenCV的函数threshold()对图像作基于OTSU的阈值化处理---并附比较好的介绍OTSU原理的博文链接

rsync远程同步

R language splits dataframe into two or more dataframe actual combat (splitting tables): Using R native method, data Table, dplyr and other schemes

Mathematics - covariance

数商云集中采购系统 :集中采购内外协同, 最大程度减少异常支出
随机推荐
IDE Import Project
R language uses dhyper function to generate hypergeometric distribution density data and plot function to visualize hypergeometric distribution density data
自己动手写编译器:通过语法编译构建语法树并实现中间代码生成
C#自定义Button实现源码
Example accumulation of two-dimensional line drawing function plot () in MATLAB
Detailed explanation of C language preprocessing
396. Rotation function
There are four ways to traverse the mat class matrix elements of OpenCV
C# 是否管理员权限运行运行软件
Understanding of rxbus and rxbus2
R语言使用dhyper函数生成超几何分布密度数据、使用plot函数可视化超几何分布密度数据(Hypergeometric Distribution)
Redis advantages and disadvantages usage scenarios
NoSQL survey Part3: open source failure
@Preauthorize annotation for permission verification
CMD command and script learning notes_ Kali_ Station B
R语言绘制小提琴图geom_violin,如何添加额外的点geom_point?geom_violin + geom_boxplot + geom_point组合使用
sprintf格式化字符串
Redis的下载安装
The R language uses the rowsums function to calculate the row data sum value of all data rows in the dataframe
让cpolar获得固定TCP地址