STM32F429新建一个工程。但是串口log都没有打出来,不知道开没有开机呢! main.h #define USART_LOG USART3 #define USART_LOG_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE() #define USART_LOG_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() #define USART_LOG_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() #define USART_LOG_FORCE_RESET() __HAL_RCC_USART3_FORCE_RESET() #define USART_LOG_RELEASE_RESET() __HAL_RCC_USART3_RELEASE_RESET() /* Definition for USART_LOG Pins */ #define USART_LOG_TX_PIN GPIO_PIN_10 #define USART_LOG_TX_GPIO_PORT GPIOB #define USART_LOG_TX_AF GPIO_AF7_USART3 #define USART_LOG_RX_PIN GPIO_PIN_11 #define USART_LOG_RX_GPIO_PORT GPIOB #define USART_LOG_RX_AF GPIO_AF7_USART3 /* Definition for USART_LOG's NVIC */ #define USART_LOG_IRQn USART3_IRQn #define USART_LOG_IRQHandler USART3_IRQHandler main.c static void Init_USART_Log_GPIO(void) { Uart_Log.Instance = USART3; Uart_Log.Init.BaudRate = 115200; Uart_Log.Init.WordLength = UART_WORDLENGTH_8B; Uart_Log.Init.StopBits = UART_STOPBITS_1; Uart_Log.Init.Parity = UART_PARITY_NONE; Uart_Log.Init.Mode = UART_MODE_TX_RX; Uart_Log.Init.HwFlowCtl = UART_HWCONTROL_NONE; Uart_Log.Init.OverSampling = UART_OVERSAMPLING_16; if(HAL_UART_Init(&Uart_Log) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /* USART3_IRQn interrupt configuration */ //HAL_NVIC_SetPriority(USART_LOG_IRQn, 5, 0); //HAL_NVIC_EnableIRQ(USART_LOG_IRQn); } #ifdef __GNUC__ /* With GCC, 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__ */ PUTCHAR_PROTOTYPE { /* Place your implementation of fputc here */ /* e.g. write a character to the USART3 and Loop until the end of transmission */ HAL_UART_Transmit(&Uart_Log, (uint8_t *)&ch, 1, 0xFFFF); return ch; } stm32f4xx_hal_msp.c void HAL_UART_MspInit(UART_HandleTypeDef *huart) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO TX/RX clock */ USART_LOG_TX_GPIO_CLK_ENABLE(); USART_LOG_RX_GPIO_CLK_ENABLE(); /* Enable USART1 clock */ USART_LOG_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* UART TX GPIO pin configuration */ GPIO_InitStruct.Pin = USART_LOG_TX_PIN; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = USART_LOG_TX_AF; HAL_GPIO_Init(USART_LOG_TX_GPIO_PORT, &GPIO_InitStruct); /* UART RX GPIO pin configuration */ GPIO_InitStruct.Pin = USART_LOG_RX_PIN; GPIO_InitStruct.Alternate = USART_LOG_RX_AF; HAL_GPIO_Init(USART_LOG_RX_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the NVIC for UART ########################################*/ /* NVIC for USART1 */ HAL_NVIC_SetPriority(USART_LOG_IRQn, 0, 1); HAL_NVIC_EnableIRQ(USART_LOG_IRQn); } 请大神指点一二,有与新人没有币,有酬必报。 |