新手上路
- 积分
- 28
- 金钱
- 28
- 注册时间
- 2022-8-8
- 在线时间
- 4 小时
|
3金钱
向大家请教一个问题,printf函数重定向后不能输出内容。之前也是这么做的可以使用printf函数打印到串口助手,但是现在一样的操作不知道哪里出问题了,麻烦大家帮忙看一下,下面是我的代码和串口助手显示的内容。
使用原子的printf重定向(直接复制的),也包含了相应的头文件stdio.h。- #if 1
- #pragma import(__use_no_semihosting)
- //±ê×¼¿aDèòaμÄÖ§3Öoˉêy
- struct __FILE
- {
- int handle;
- };
- FILE __stdout;
- void _sys_exit(int x)
- {
- x = x;
- }
- int fputc(int ch, FILE *f)
- {
- while((USART1->SR&0X40)==0);
- USART1->DR = (uint8_t) ch;
- return ch;
- }
- #endif
复制代码 主函数为- int main(void)
- {
- uint8_t rec=0;
- uint8_t ch[]={0};
- HAL_Init();
- SystemClock_Config();
- MX_GPIO_Init();
- MX_USART1_UART_Init();
- while (1)
- {
- printf("串口通信测试\r\n");
- HAL_UART_Transmit (&huart1,"uart test\r\n",strlen("uart test\r\n"),100);
- }
- }
复制代码 但是串口助手中只显示HAL库函数发送的内容

|
|