/** ****************************************************************************** * File Name : USART.h * Description : This file provides code for the configuration * of the USART instances. ****************************************************************************** * @attention * *

© Copyright (c) 2021 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under Ultimate Liberty license * SLA0044, the "License"; You may not use this file except in compliance with * the License. You may obtain a copy of the License at: * www.st.com/SLA0044 * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __usart_H #define __usart_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" typedef enum { RS485_RECV = 0, RS485_SEND }RS485DirCtrl_e; #define RS485_DIR_PORT GPIOA #define RS485_DIR_PIN GPIO_PIN_1 /* RS485 TX/RX Control */ #define RS485_TX_ENABLE() HAL_Delay(100);\ HAL_GPIO_WritePin(RS485_DIR_PORT, RS485_DIR_PIN, GPIO_PIN_SET);\ HAL_Delay(100); #define RS485_RX_ENABLE() HAL_Delay(100);\ HAL_GPIO_WritePin(RS485_DIR_PORT, RS485_DIR_PIN, GPIO_PIN_RESET);\ HAL_Delay(100); #define PRINTF(...) VcomSend(__VA_ARGS__) #define ECHO_ERROR(x) PRINTF("[%s][%d]:%s\r\n", __FUNCTION__, __LINE__, x) #pragma pack(1) #define FreeUart1Buffer() Debug_Rxbuffer.Locked = 0; Debug_Rxbuffer.RxSize=0 #define Uart1BufferIsEmpty (Debug_Rxbuffer.RxSize == 0 ? 1 : 0) #define Uart1BufferIsReadable() (Debug_Rxbuffer.Locked ? 1 : 0) //#define LockUart3Buffer() Uart3_Rxbuffer.Locked = 1 //#define FreeUart3Buffer() Uart3_Rxbuffer.Locked = 0; Uart3_Rxbuffer.RxSize=0; memset(Uart3_Rxbuffer.RxBuffer, 0x0, UART_RINGBUF_SIZE) //#define Uart3BufferIsEmpty (Uart3_Rxbuffer.RxSize == 0 ? 1 : 0) //#define Uart3BufferIsReadable() (Uart3_Rxbuffer.Locked ? 1 : 0) #define UART_RINGBUF_SIZE 255 typedef struct Uart_Rxbuffer_s { uint8_t RxBuffer[UART_RINGBUF_SIZE]; /* UART receive buffer*/ uint32_t RxSize; /* Current data length in UART receive buffer */ uint32_t Time; /* Last receive time */ uint8_t Locked; /* Buffer is busy */ }Uart_Rxbuffer_t; typedef struct { uint8_t *pRear; //ÔÚÖжϺ¯ÊýÖиü¸Ä uint8_t *pFront; //ÔÚÖ÷Ñ­»·Öиü¸Ä } UartBuffer_t; #pragma pack() extern Uart_Rxbuffer_t Debug_Rxbuffer; //extern Uart_Rxbuffer_t Uart3_Rxbuffer; extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; void Board_USART1Init(void); void Board_USART1DeInit(void); void Board_USART1RX_Enable(void); void Board_USART1RX_Disable(void); void Board_USART2Init(void); void Board_USART2DeInit(void); int8_t Board_USART2Recv(uint8_t *pFmt, uint16_t u16TimeOut); int8_t Board_USART2end(const uint8_t *pFmt, uint8_t u8Len); //int8_t Board_USART2Test(void); void VcomSend( char *format, ... ); #ifdef __cplusplus } #endif #endif /*__ usart_H */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/