- #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;
- }
- #ifndef __PRINTF_H__
- #define __PRINTF_H__
- #include <stdio.h>
- void Printf_Configuration(void);
- #endif
|