bs_bcu_app/drv/drv_usart.h

101 lines
3.1 KiB
C
Raw Normal View History

2024-11-07 17:24:19 +08:00
/**
****************************************************************************************************
* @file usart.h
* @author XX<EFBFBD>Ŷ<EFBFBD>
* @version V1.0
* @date 2021-10-14
* @brief <EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(һ<EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><EFBFBD><EFBFBD>1)<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>printf
* @license Copyright (c) 2020-2032,
****************************************************************************************************
* @attention
*
* <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD>ϵͳƽ̨<EFBFBD><EFBFBD>STM32F407
*
* <EFBFBD>޸<EFBFBD>˵<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>һ<EFBFBD>η<EFBFBD><EFBFBD><EFBFBD>
*
****************************************************************************************************
*/
#ifndef _USART_H
#define _USART_H
#include "stdio.h"
#include "drv_sys.h"
2024-11-20 15:33:37 +08:00
#include "stm32f4xx_hal.h"
#define USART_EN_RX 1 /* ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD> */
typedef struct {
USART_TypeDef* Instance; // UARTʵ<54><CAB5>
GPIO_TypeDef* TxPort; // Tx<54><78><EFBFBD>ŵ<EFBFBD>GPIO<49>˿<EFBFBD>
uint16_t TxPin; // Tx<54><78><EFBFBD>ŵ<EFBFBD>GPIO<49><4F><EFBFBD><EFBFBD>
GPIO_TypeDef* RxPort; // Rx<52><78><EFBFBD>ŵ<EFBFBD>GPIO<49>˿<EFBFBD>
uint16_t RxPin; // Rx<52><78><EFBFBD>ŵ<EFBFBD>GPIO<49><4F><EFBFBD><EFBFBD>
uint32_t WordLength; // <20>ֳ<EFBFBD>
uint32_t StopBits; // ֹͣλ
uint32_t Parity; // У<><D0A3>
uint32_t Mode; // <20><><EFBFBD><EFBFBD>ģʽ
uint32_t HwFlowCtl; // Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint32_t OverSampling; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} UARTConfig;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>UART<52><54><EFBFBD><EFBFBD>
void InitUARTs(uint32_t baudRate);
2024-11-07 17:24:19 +08:00
/*******************************************************************************************************/
2024-11-11 17:18:25 +08:00
/* <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> A2TX <20><>A3RX
2024-11-07 17:24:19 +08:00
* Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USART1<EFBFBD><EFBFBD>.
* ע<EFBFBD><EFBFBD>: ͨ<EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>12<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>USART1~UART7<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
*/
2024-11-11 17:18:25 +08:00
#define USART_TX_GPIO_PORT GPIOA
#define USART_TX_GPIO_PIN GPIO_PIN_2
2024-11-07 17:24:19 +08:00
#define USART_TX_GPIO_AF GPIO_AF7_USART1
2024-11-11 17:18:25 +08:00
#define USART_TX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9> */
2024-11-07 17:24:19 +08:00
2024-11-11 17:18:25 +08:00
#define USART_RX_GPIO_PORT GPIOA
#define USART_RX_GPIO_PIN GPIO_PIN_3
2024-11-07 17:24:19 +08:00
#define USART_RX_GPIO_AF GPIO_AF7_USART1
2024-11-11 17:18:25 +08:00
#define USART_RX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9> */
2024-11-07 17:24:19 +08:00
2024-11-11 17:18:25 +08:00
#define USART_UX USART2
#define USART_UX_IRQn USART2_IRQn
#define USART_UX_IRQHandler USART2_IRQHandler
#define USART_UX_CLK_ENABLE() do{ __HAL_RCC_USART2_CLK_ENABLE(); }while(0) /* USART2 ʱ<><CAB1>ʹ<EFBFBD><CAB9> */
2024-11-07 17:24:19 +08:00
/*******************************************************************************************************/
#define USART_REC_LEN 200 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200 */
2024-11-20 15:33:37 +08:00
#define RXBUFFERSIZE 1 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С */
2024-11-07 17:24:19 +08:00
2024-11-20 15:33:37 +08:00
extern UART_HandleTypeDef g_uart1_handle; /* UART<52><54><EFBFBD><EFBFBD> */
extern UART_HandleTypeDef g_uart3_handle; /* UART<52><54><EFBFBD><EFBFBD> */
extern UART_HandleTypeDef g_uart4_handle; /* UART<52><54><EFBFBD><EFBFBD> */
2024-11-07 17:24:19 +08:00
extern uint8_t g_usart_rx_buf[USART_REC_LEN]; /* <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD> */
extern uint16_t g_usart_rx_sta; /* <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD> */
2024-11-20 15:33:37 +08:00
extern uint8_t rx_buffer[RXBUFFERSIZE]; /* HAL<41><4C>USART<52><54><EFBFBD><EFBFBD>Buffer */
2024-11-07 17:24:19 +08:00
void usart_init(uint32_t baudrate); /* <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#endif