34
34
#include <string.h>
35
35
36
36
static const PinMap PinMap_UART_TX [] = {
37
- {PA_9 , UART_1 , STM_PIN_DATA (GPIO_Mode_AF_PP , 0 )},
38
- {PA_2 , UART_2 , STM_PIN_DATA (GPIO_Mode_AF_PP , 0 )},
39
- {NC , NC , 0 }
37
+ {PA_9 , UART_1 , STM_PIN_DATA (GPIO_Mode_AF_PP , 0 )},
38
+ {PA_2 , UART_2 , STM_PIN_DATA (GPIO_Mode_AF_PP , 0 )},
39
+ {PB_10 , UART_3 , STM_PIN_DATA (GPIO_Mode_AF_PP , 0 )},
40
+ {NC , NC , 0 }
40
41
};
41
42
42
43
static const PinMap PinMap_UART_RX [] = {
43
- {PA_10 , UART_1 , STM_PIN_DATA (GPIO_Mode_IN_FLOATING , 0 )},
44
- {PA_3 , UART_2 , STM_PIN_DATA (GPIO_Mode_IN_FLOATING , 0 )},
45
- {NC , NC , 0 }
44
+ {PA_10 , UART_1 , STM_PIN_DATA (GPIO_Mode_IN_FLOATING , 0 )},
45
+ {PA_3 , UART_2 , STM_PIN_DATA (GPIO_Mode_IN_FLOATING , 0 )},
46
+ {PB_11 , UART_3 , STM_PIN_DATA (GPIO_Mode_IN_FLOATING , 0 )},
47
+ {NC , NC , 0 }
46
48
};
47
49
48
- #define UART_NUM (2 )
50
+ #define UART_NUM (3 )
49
51
50
- static uint32_t serial_irq_ids [UART_NUM ] = {0 };
52
+ static uint32_t serial_irq_ids [UART_NUM ] = {0 , 0 , 0 };
51
53
52
54
static uart_irq_handler irq_handler ;
53
55
@@ -86,9 +88,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
86
88
// Enable USART clock
87
89
if (obj -> uart == UART_1 ) {
88
90
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 , ENABLE );
89
- }
90
- if (obj -> uart == UART_2 ) {
91
- RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2 , ENABLE );
91
+ } else if (obj -> uart == UART_2 ) {
92
+ RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2 , ENABLE );
93
+ } else if (obj -> uart == UART_3 ) {
94
+ RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART3 , ENABLE );
92
95
}
93
96
94
97
// Configure the UART pins
@@ -106,6 +109,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
106
109
// The index is used by irq
107
110
if (obj -> uart == UART_1 ) obj -> index = 0 ;
108
111
if (obj -> uart == UART_2 ) obj -> index = 1 ;
112
+ if (obj -> uart == UART_3 ) obj -> index = 2 ;
109
113
110
114
// For stdio management
111
115
if (obj -> uart == STDIO_UART ) {
@@ -176,6 +180,7 @@ static void uart_irq(USART_TypeDef* usart, int id) {
176
180
177
181
static void uart1_irq (void ) {uart_irq ((USART_TypeDef * )UART_1 , 0 );}
178
182
static void uart2_irq (void ) {uart_irq ((USART_TypeDef * )UART_2 , 1 );}
183
+ static void uart3_irq (void ) {uart_irq ((USART_TypeDef * )UART_3 , 2 );}
179
184
180
185
void serial_irq_handler (serial_t * obj , uart_irq_handler handler , uint32_t id ) {
181
186
irq_handler = handler ;
@@ -196,7 +201,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
196
201
irq_n = USART2_IRQn ;
197
202
vector = (uint32_t )& uart2_irq ;
198
203
}
199
-
204
+
205
+ if (obj -> uart == UART_3 ) {
206
+ irq_n = USART3_IRQn ;
207
+ vector = (uint32_t )& uart3_irq ;
208
+ }
209
+
200
210
if (enable ) {
201
211
202
212
if (irq == RxIrq ) {
0 commit comments