#include "stm32g0xx_hal.h" #include "usart.h" void init_usart(void) { GPIO_InitTypeDef GPIO_InitStruct; USART_BRIDGE_TX_PORT_CLK_ENABLE USART_BRIDGE_RX_PORT_CLK_ENABLE GPIO_InitStruct.Pin = USART_BRIDGE_TX_PIN; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = USART_BRIDGE_AF; HAL_GPIO_Init(USART_BRIDGE_TX_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = USART_BRIDGE_RX_PIN; HAL_GPIO_Init(USART_BRIDGE_RX_PORT, &GPIO_InitStruct); USART_BRIDGE_CLK_ENABLE uart.Instance = USART_BRIDGE_USART; uart.Init.BaudRate = USART_BRIDGE_SPEED; uart.Init.WordLength = UART_WORDLENGTH_8B; uart.Init.StopBits = UART_STOPBITS_1; uart.Init.Parity = UART_PARITY_NONE; uart.Init.Mode = UART_MODE_TX_RX; uart.Init.HwFlowCtl = UART_HWCONTROL_NONE; uart.Init.OverSampling = UART_OVERSAMPLING_8; uart.Init.OneBitSampling= UART_ONE_BIT_SAMPLE_DISABLE; HAL_UART_Init(&uart); HAL_NVIC_SetPriority(USART_BRIDGE_IRQn, 6, 0); HAL_NVIC_EnableIRQ(USART_BRIDGE_IRQn); HAL_UART_Receive_IT(&uart, (uint8_t*)&m_uartByte, 1); }