/**************************************************************************** * Copyright: (C)2014 Î人ÁèÔÆÇ¶ÈëʽʵÑéÊÒ www.emblinux.com * Author: GuoWenxue QQ: 281143292 * Description: ·Ü¶·STM32v5¿ª·¢°å´®¿Ú²Ù×÷º¯Êý½Ó¿Ú,printf¹³×Óº¯Êýfputc * * ChangeLog: * °æ±¾ºÅ ÈÕÆÚ ×÷Õß ËµÃ÷ * V1.0.0 2014.08.25 GuoWenxue ·¢²¼¸Ã°æ±¾ ****************************************************************************/ #include "stm32f10x.h" #include "stm32f10x_usart.h" #include "stm32v5_uart.h" #include /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ void USART_Config(USART_TypeDef* USARTx) { USART_InitTypeDef USART_InitStructure; /* Configure USART1 */ USART_InitStructure.USART_BaudRate = 115200; //ËÙÂÊ115200bps USART_InitStructure.USART_WordLength = USART_WordLength_8b; //Êý¾Ýλ8λ USART_InitStructure.USART_StopBits = USART_StopBits_1; //ֹͣλ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(USARTx, &USART_InitStructure); //ÅäÖô®¿Ú²ÎÊýº¯Êý #if 0 /* Enable USARTx Receive and Transmit interrupts */ USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE); //ʹÄܽÓÊÕÖÐ¶Ï USART_ITConfig(USARTx, USART_IT_TXE, ENABLE); //ʹÄÜ·¢ËÍ»º³å¿ÕÖÐ¶Ï #endif /* Enable the USARTx */ USART_Cmd(USARTx, ENABLE); } void dbg_setup_uart(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE); /* ĬÈϸ´Óù¦ÄÜ */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö GPIO_Init(GPIOA, &GPIO_InitStructure); /* ¸´Óù¦ÄܵÄÊäÈëÒý½Å±ØÐëÅäÖÃΪÊäÈëģʽ£¨¸¡¿Õ/ÉÏÀ­/ÏÂÀ­µÄÒ»ÖÖ£©*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸´Óø¡¿ÕÊäÈë GPIO_Init(GPIOA, &GPIO_InitStructure); USART_Config(DBG_UART); USART_SendData(DBG_UART, '\n'); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); } int fputc(int ch, FILE *f) { if('\n' == ch) { USART_SendData(DBG_UART, (uint8_t) '\r'); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) ; } USART_SendData(DBG_UART, (uint8_t) ch); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); return ch; }