本文对应的开发板是:stm32
在kail环境中(参考野火f429源代码):
#include<stdio.h>
//重写printf的底层函数fputc
int fputc(int ch, FILE *f)
{
/* 等待串口发送寄存器为空 */
while (USART_GetFlagStatus(DEBUG_USART, USART_FLAG_TXE) == RESET);
/* 发送串口数据 */
USART_SendData(DEBUG_USART, (uint8_t) ch);
return (ch);
}
int mian()
{
uart_init();
printf("****** uart test*****\n");
}
在 GCC环境中
#include<stdio.h>
//在本地文件中重写printf的底层函数_write
int _write (int fd, char *pBuffer, int size)
{
for (int i = 0; i < size; i++)
{
while (UART_GetFlagStatus(uart1, UART_FLAG_TXE) == RESET);
UART_SendData(uart1, (uint8_t) *pBuffer++);
}
return size;
}
int mian()
{
uart_init();
printf("****** uart test*****\n");
}