当前位置:网站首页>07 printf redirection
07 printf redirection
2022-07-18 02:33:00 【haichuangdianzi】
Modify on the basis of the last experiment , Open it directly keil engineering , Configure the software first .
- open “USART.c” file , add to “#include<stdio.h>” The header file .

- Add the following program at the end of this file .
/* USER CODE BEGIN 1 */
int fputc(int ch, FILE *stream)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch,1, 0xFFFF);
return ch;
}
/* USER CODE END 1 */
- Return to the main function after the preparation , Add again “#include<stdio.h>” The header file .

- stay while Complete the code in the program .
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
printf("Hello World! \r\n");
HAL_Delay(1000);
}
/* USER CODE END 3 */
Final output .
notes : In many places \n You can change lines , But the actual measurement is not good , But through \r\n To achieve .
————————————————————————————————————
The second method :
stay USART.c Add the following program to the file .
/* USER CODE BEGIN 1 */
__align(8) char USART2_TxBuff[256];
void u2_printf(char* fmt,...)
{
unsigned int length=0;
va_list ap;
va_start(ap,fmt);
vsprintf(USART2_TxBuff,fmt,ap);
va_end(ap);
length=strlen((const char*)USART2_TxBuff);
HAL_UART_Transmit(&huart2, (uint8_t *)USART2_TxBuff, length, 0xffff);
while(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_TC)!=SET);
}
/* USER CODE END 1 */
At the same time USART.c Add the corresponding header file .
/* USER CODE BEGIN 0 */
#include "stdio.h"
#include "stdarg.h"
#include "string.h"
/* USER CODE END 0 */
stay usart.h Declare the header file .
/* USER CODE BEGIN Prototypes */
void u2_printf(char* fmt,...) ;
/* USER CODE END Prototypes */
Next, you can test in the main function .
/* USER CODE BEGIN 3 */
u2_printf("Hello XP\r\n");
HAL_Delay(1000);
/* USER CODE END 3 */
边栏推荐
- SVN下载以及中文包安装
- [computer level 3 information security] time node memory test questions
- 2022-04-19 Unity入门4——重要组件与API
- 一图看懂:国企数字化转型4个方向3个战略
- 2022-04-21 unity foundation 1 - 3D mathematics
- Dragon lizard community recruitment Promotion Ambassador & experience officer| Everyone can participate in open source
- How to encapsulate kotlin + Android databinding in a project
- Practice of kotlin stateflow search function DB + network
- Fragment (IV) common problems
- Single vehicle management system - 1 Document design and SQL code description
猜你喜欢

Young people abandon new beauty collection stores

Google recommends using sealed and remotemediator in projects

Easy gene encode histone chip SEQ and transcription factor chip SEQ data standard and processing flow
![[recruitment] 2022 Xiangguang award annual ESG influence investment award is officially launched!](/img/11/64ad076cee870bd1aa42a6691ad841.jpg)
[recruitment] 2022 Xiangguang award annual ESG influence investment award is officially launched!

Figure 1: four directions and three strategies for digital transformation of state-owned enterprises

Unemployed after graduation?

Google recommends using kotlin flow in MVVM architecture

Redis使用管道PipeLine

Alipay sandbox app login failed. There is no problem with the account

许式伟:Go+ 演进之路
随机推荐
许式伟:Go+ 演进之路
2022-04-20 Unity入门6——光源组件
2022-04-20 unity entry 6 - light source components
Open source real-time data warehouse Apache Doris graduated, how to go further in the future?
堆排序
荷兰储户后续
Easy gene encode histone chip SEQ and transcription factor chip SEQ data standard and processing flow
在 CDP中使用Iceberg 为数据湖仓增压
A---DMA串口通信
2022-04-21 Unity入门8——音效系统
支付宝沙箱版app登入失败账户不存在问题
MQTT---CONNECT连接
MQTT---SUBSCRIBE和SUBACK
2022-04-20 unity introduction 5 - Camera
配置Sublime的C语言环境
Latex數學公式
手机怎样控制led显示屏发视频?
推特大战马斯克:想走,哪那么容易
Involve yourself? After imagen, it launched an image model generated by 20billion text, which stunned netizens!
The end of kotlin plug-in and the rise of viewbinding