#include "main.h" //UARTx #define DEBUG_USARTx CW_UART3 #define DEBUG_USART_CLK RCC_APB1_PERIPH_UART3 #define DEBUG_USART_APBClkENx RCC_APBPeriphClk_Enable1 #define DEBUG_USART_BaudRate 115200 #define DEBUG_USART_UclkFreq 8000000 //UARTx GPIO #define DEBUG_USART_GPIO_CLK RCC_AHB_PERIPH_GPIOB #define DEBUG_USART_TX_GPIO_PORT CW_GPIOB #define DEBUG_USART_TX_GPIO_PIN GPIO_PIN_6 #define DEBUG_USART_RX_GPIO_PORT CW_GPIOB #define DEBUG_USART_RX_GPIO_PIN GPIO_PIN_7 //GPIO AF #define DEBUG_USART_AFTX PB06_AFx_UART3TXD() #define DEBUG_USART_AFRX PB07_AFx_UART3RXD() #ifdef __GNUC__ /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */ /** * @brief ÅäÖÃUART * */ void UART_Configuration(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; //UART TX RX ¸´ÓÃ DEBUG_USART_AFTX; DEBUG_USART_AFRX; GPIO_InitStructure.Pins = DEBUG_USART_TX_GPIO_PIN; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.Pins = DEBUG_USART_RX_GPIO_PIN; GPIO_InitStructure.Mode = GPIO_MODE_INPUT_PULLUP; GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = DEBUG_USART_BaudRate; USART_InitStructure.USART_Over = USART_Over_16; USART_InitStructure.USART_Source = USART_Source_PCLK; USART_InitStructure.USART_UclkFreq = DEBUG_USART_UclkFreq; USART_InitStructure.USART_StartBit = USART_StartBit_FE; 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(DEBUG_USARTx, &USART_InitStructure); } /** * @brief Retargets the C library printf function to the USART. * */ PUTCHAR_PROTOTYPE { USART_SendData_8bit(DEBUG_USARTx, (uint8_t)ch); while (USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE) == RESET); return ch; } /****************************************************************************** * EOF (not truncated) ******************************************************************************/ #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */