#include "stm32f4xx.h"
#include "printf.h"
void Printf_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//PB6->TX PB7->Rx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource10,GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_UART4);
USART_InitStructure.USART_BaudRate = 19200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(UART4,&USART_InitStructure);
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);
USART_Cmd(UART4,ENABLE);
}
int fputc(int ch, FILE *f)
{
while (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET);
USART_SendData(UART4, (uint8_t) ch);
while (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET);
return ch;
}
int fgetc(FILE *f)
{
int ch;
while (USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(UART4);
while (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET);
USART_SendData(UART4, (uint8_t) ch);
return ch;
}
STM32F4 UART4重定向printf和scanf函数
4星 · 超过85%的资源 需积分: 45 105 浏览量
2014-01-25
19:04:25
上传
评论 3
收藏 1KB ZIP 举报
转身落在清明上
- 粉丝: 32
- 资源: 28
- 1
- 2
- 3
- 4
- 5
前往页