当前位置:网站首页>重定向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);
}
边栏推荐
- vs studio install opencv environment
- 常用工具链和虚拟环境-WSL
- mysql binlog日期解析成yyyy-MM-dd
- 【Flink】如何生成 Flink 作业的交互式火焰图?
- 程序员写代码日常 | 每日趣闻
- The cornerstone of high concurrency: multithreading, daemon threading, thread safety, thread synchronization, mutual exclusion lock, all in one article!...
- 能添加任意贴图超级复布局的初级智能文本提示器(超级版)
- Summary of some interviews
- Disable the token and update the token function without awareness
- 常用工具链和虚拟环境-msys2与mingw
猜你喜欢
随机推荐
rancher集成ldap,实现统一账号登录
win下使用vscode+wsl2
WordPress博客问答小插件
怎么从零编写一个 v3 版本的 chrome 浏览器插件实现 CSDN 博客网站的暗黑和明亮主题切换?
Summary of some interviews
一个循环,两个循环问题的思考及复现
MySQL里获取当前周、月、季的第一天/最后一天
粘包与拆包
能添加任意贴图超级复布局的初级智能文本提示器
Kook机器人开发日志01
部门之间,互不信任正常吗?(你是否遇到过)
梅科尔工作室-14天华为培训三
Fiddler基本使用
Topic Modeling of Short Texts: A Pseudo-Document View
Jenkins2.328+sonarqube7.9 实现代码自动化检测
The cornerstone of high concurrency: multithreading, daemon threading, thread safety, thread synchronization, mutual exclusion lock, all in one article!...
Get the first/last day of the current week, month, quarter in MySQL
思维+启发式合并
[Example构造方法增加notNull参数,默认false,允许值为null,值为null的时候不加入到条件中
openCV第一篇