forked from LonelyWolf/stm32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart.h
53 lines (44 loc) · 1.78 KB
/
uart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define _UART_PORT 1
#if _UART_PORT == 1
#define UART_PORT USART1
#define UART_TX_PIN GPIO_Pin_9 // PA9 (USART1_TX)
#define UART_RX_PIN GPIO_Pin_10 // PA10 (USART1_RX)
#define UART_GPIO_PORT_TX GPIOA
#define UART_GPIO_PORT_RX UART_GPIO_PORT_TX
#elif _UART_PORT == 2
#define UART_PORT USART2
#define UART_TX_PIN GPIO_Pin_2 // PA2 (USART2_TX)
#define UART_RX_PIN GPIO_Pin_3 // PA3 (USART2_RX)
#define UART_GPIO_PORT_TX GPIOA
#define UART_GPIO_PORT_RX UART_GPIO_PORT_TX
#elif _UART_PORT == 3
#define UART_PORT USART3
#define UART_TX_PIN GPIO_Pin_10 // PB10 (USART3_TX)
#define UART_RX_PIN GPIO_Pin_11 // PB11 (USART3_RX)
#define UART_GPIO_PORT_TX GPIOB
#define UART_GPIO_PORT_RX UART_GPIO_PORT_TX
#elif _UART_PORT == 4
#define UART_PORT UART4
#define UART_TX_PIN GPIO_Pin_10 // PC10 (UART4_TX)
#define UART_RX_PIN GPIO_Pin_11 // PC11 (UART4_RX)
#define UART_GPIO_PORT_TX GPIOC
#define UART_GPIO_PORT_RX UART_GPIO_PORT_TX
#elif _UART_PORT == 5
#define UART_PORT UART5
#define UART_TX_PIN GPIO_Pin_12 // PC12 (UART5_TX)
#define UART_RX_PIN GPIO_Pin_2 // PD2 (UART5_RX)
#define UART_GPIO_PORT_TX GPIOC
#define UART_GPIO_PORT_RX GPIOD
#endif
#define HEX_CHARS "0123456789ABCDEF"
void UART_Init(void);
void UART_SendChar(char ch);
void UART_SendInt(int32_t num);
void UART_SendHex8(uint16_t num);
void UART_SendHex16(uint16_t num);
void UART_SendHex32(uint32_t num);
void UART_SendStr(char *str);
void UART_SendBuf(char *buf, uint16_t bufsize);
void UART_SendBufPrintable(char *buf, uint16_t bufsize, char subst);
void UART_SendBufHex(char *buf, uint16_t bufsize);
void UART_SendBufHexFancy(char *buf, uint16_t bufsize, uint8_t column_width, char subst);