usart.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-03-03 ZZ the first version
  9. */
  10. #ifndef APPLICATIONS_USART_USART_H_
  11. #define APPLICATIONS_USART_USART_H_
  12. #include "stm32g0xx_hal.h"
  13. #include "stm32g0xx_hal_usart.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. extern UART_HandleTypeDef UartHandle;
  18. #define USART1_BUFF_LANGTH 1048
  19. uint8_t uart1_buff[4];
  20. typedef struct {
  21. uint32_t len;
  22. uint16_t ind;
  23. uint8_t buf[USART1_BUFF_LANGTH];
  24. }SerialBuffType; //发送暂存区
  25. #define TX_TIMEOUT ((uint32_t)1000)
  26. #define RX_TIMEOUT HAL_MAX_DELAY
  27. /* Exported macro ------------------------------------------------------------*/
  28. #define IS_CAP_LETTER(c) (((c) >= 'A') && ((c) <= 'F'))
  29. #define IS_LC_LETTER(c) (((c) >= 'a') && ((c) <= 'f'))
  30. #define IS_09(c) (((c) >= '0') && ((c) <= '9'))
  31. #define ISVALIDHEX(c) (IS_CAP_LETTER(c) || IS_LC_LETTER(c) || IS_09(c))
  32. #define ISVALIDDEC(c) IS_09(c)
  33. #define CONVERTDEC(c) (c - '0')
  34. #define CONVERTHEX_ALPHA(c) (IS_CAP_LETTER(c) ? ((c) - 'A'+10) : ((c) - 'a'+10))
  35. #define CONVERTHEX(c) (IS_09(c) ? ((c) - '0') : CONVERTHEX_ALPHA(c))
  36. void MX_USART1_UART_Init(void);
  37. //void HAL_UART1_MspInit(void);
  38. //void HAL_UART1_MspDeInit(void);
  39. //void USART1_IRQHandler(void);
  40. void Int2Str(uint8_t *p_str, uint32_t intnum);
  41. uint32_t Str2Int(uint8_t *inputstr, uint32_t *intnum);
  42. void Serial_PutString(uint8_t *p_string,uint8_t p_len);
  43. HAL_StatusTypeDef Serial_PutByte(uint8_t param);
  44. #endif /* APPLICATIONS_USART_USART_H_ */