当前位置:网站首页>重定向printf到USB CDC、串口2
重定向printf到USB CDC、串口2
2022-08-03 02:06:00 【物极必反1024】
重定向printf到USB CDC、串口2
1 头文件
#include <stdarg.h>
2、 串口2
void USART2_Printf(const char *format, ...)
{
va_list args;
char Data_Buff[100];
uint32_t length;
va_start(args, format);
length = vsnprintf((char *)Data_Buff, 100, (char *)format, args);
va_end(args);
USART1_Send_Len((uint8_t *)Data_Buff, length);
}
/*------------------------------------------- //函数名:USART2_Send_Len //描述:串口2发送固定长度字符串 //参数: u8 *str 发送的字符串 u8 len字符串长度 //返回值:无 //函数调用列表:无 ---------------------------------------------*/
void USART2_Send_Len(u8 *str,int len)
{
for(; len>0; len--)
{
while((USART2->SR&0X40)==0);//等待上一次串口数据发送完成
USART2->DR =(u8)*str; //写DR,串口将发送数据
str++;
}
}
3、USB
#include <stdarg.h>
void usb_printf(const char *format, ...)
{
va_list args;
uint32_t length;
va_start(args, format);
length = vsnprintf((char *)UserTxBufferFS, APP_TX_DATA_SIZE, (char *)format, args);
va_end(args);
CDC_Transmit_FS(UserTxBufferFS, length);
}
边栏推荐
- Wei Dongshan Digital Photo Frame Project Learning (5) Transplantation of libjpeg-turbo
- vsftp容器搭建+go开发web用户管理界面(更新于2022.02.23)
- 一次偶然的钓鱼文件分析
- 370万欧元!西班牙iPronics加速可重构光子芯片商用
- 【社媒营销】Facebook速推帖子如何运作?值得吗?
- 怎么从零编写一个 v3 版本的 chrome 浏览器插件实现 CSDN 博客网站的暗黑和明亮主题切换?
- The cornerstone of high concurrency: multithreading, daemon threading, thread safety, thread synchronization, mutual exclusion lock, all in one article!...
- ldap创建公司组织、人员
- 梅科尔工作室-14天华为培训三
- 【静态类型和动态类型 编译检查和运行检查 Objective-C中】
猜你喜欢
Pro_07丨波动率因子3.0与斜率因子
Rust Web(三)—— 通过sqlx连接数据库(MySQL)
QT添加资源文件、样式表、qss文件使用
236. The binary tree in recent common ancestor
SPI机制是什么?
易购数码类电商商城网页设计与实现项目源码
The LVS load balancing cluster and the deployment of the LVS - NAT experiment
leetcode:139. 单词拆分
vsftp容器搭建+go开发web用户管理界面(更新于2022.02.23)
为什么要使用 playwright 做浏览器自动化测试?
随机推荐
Wireshark data capture and analysis of the transport layer protocol (TCP protocol)
【7.31】代码源 - 【矩阵操作】【宝箱】【New Stone Game】【等差数列】
如何准备考pmp?
YYGH-BUG-06
南瓜科学新品上线 开辟益智玩具新世界
VS2010 组件列表与对应名称
禁用token及无感知更新token功能实现
MySQL-Explain详解
openCV第一篇
问题记录:jenkins构建时报错The goal you specified requires a project to execute but there is no POM in...
ROS通信模块:秒懂话题通信
Fiddler基本使用
Linux定时任务脚本执行时mysqldump备份异常的问题
leetcode:172. 阶乘后的零
Interconversion between numpy PIL tensors
Wei Dongshan Digital Photo Frame Project Learning (5) Transplantation of libjpeg-turbo
kubernetes部署ldap
关于提高企业网络安全意识
程序员写代码日常 | 每日趣闻
【社媒营销】Facebook速推帖子如何运作?值得吗?