This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
CMS3in1/1.Cabin/4.MISC/PWM/Drivers/SYSTEM/usart/usart.h

76 lines
2.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
****************************************************************************************************
* @file usart.h
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2021-10-14
* @brief 串口初始化代码(一般是串口1)支持printf
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 探索者 F407开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
* 修改说明
* V1.0 20211014
* 第一次发布
*
****************************************************************************************************
*/
#ifndef _USART_H
#define _USART_H
#include "stdio.h"
#include "./SYSTEM/sys/sys.h"
/*******************************************************************************************************/
/* 引脚 和 串口 定义
* 默认是针对USART1的.
* 注意: 通过修改这12个宏定义,可以支持USART1~UART7任意一个串口.
*/
#define USART_TX_GPIO_PORT GPIOD
#define USART_TX_GPIO_PIN GPIO_PIN_8
#define USART_TX_GPIO_AF GPIO_AF7_USART3
#define USART_TX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOD_CLK_ENABLE(); }while(0) /* 发送引脚时钟使能 */
#define USART_RX_GPIO_PORT GPIOB
#define USART_RX_GPIO_PIN GPIO_PIN_11
#define USART_RX_GPIO_AF GPIO_AF7_USART3
#define USART_RX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOB_CLK_ENABLE(); }while(0) /* 接收引脚时钟使能 */
#define USART_UX USART3
#define USART_UX_IRQn USART3_IRQn
#define USART_UX_IRQHandler USART3_IRQHandler
#define USART_UX_CLK_ENABLE() do{ __HAL_RCC_USART3_CLK_ENABLE(); }while(0) /* USART1 时钟使能 */
/*******************************************************************************************************/
#define USART_REC_LEN 200 /* 定义最大接收字节数 200 */
#define USART_EN_RX 1 /* 使能1/禁止0串口1接收 */
#define RXBUFFERSIZE 1 /* 缓存大小 */
extern UART_HandleTypeDef g_uart1_handle; /* UART句柄 */
extern uint8_t g_usart_rx_buf[USART_REC_LEN]; /* 接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 */
extern uint16_t g_usart_rx_sta; /* 接收状态标记 */
extern uint8_t g_rx_buffer[RXBUFFERSIZE]; /* HAL库USART接收Buffer */
void usart_init(uint32_t baudrate); /* 串口初始化函数 */
#endif