Skip to content

Commit 14ad877

Browse files
committed
Merge pull request #270 from cfb95/patch-5
Update serial_api.c
2 parents ab84750 + b82f468 commit 14ad877

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/PeripheralNames.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ typedef enum {
4343

4444
typedef enum {
4545
UART_1 = (int)USART1_BASE,
46-
UART_2 = (int)USART2_BASE
46+
UART_2 = (int)USART2_BASE,
47+
UART_3 = (int)USART3_BASE
4748
} UARTName;
4849

4950
#define STDIO_UART_TX PA_2

libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/serial_api.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@
3434
#include <string.h>
3535

3636
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}
4041
};
4142

4243
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}
4648
};
4749

48-
#define UART_NUM (2)
50+
#define UART_NUM (3)
4951

50-
static uint32_t serial_irq_ids[UART_NUM] = {0};
52+
static uint32_t serial_irq_ids[UART_NUM] = {0,0,0};
5153

5254
static uart_irq_handler irq_handler;
5355

@@ -86,9 +88,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
8688
// Enable USART clock
8789
if (obj->uart == UART_1) {
8890
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);
9295
}
9396

9497
// Configure the UART pins
@@ -106,6 +109,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
106109
// The index is used by irq
107110
if (obj->uart == UART_1) obj->index = 0;
108111
if (obj->uart == UART_2) obj->index = 1;
112+
if (obj->uart == UART_3) obj->index = 2;
109113

110114
// For stdio management
111115
if (obj->uart == STDIO_UART) {
@@ -176,6 +180,7 @@ static void uart_irq(USART_TypeDef* usart, int id) {
176180

177181
static void uart1_irq(void) {uart_irq((USART_TypeDef*)UART_1, 0);}
178182
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);}
179184

180185
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
181186
irq_handler = handler;
@@ -196,7 +201,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
196201
irq_n = USART2_IRQn;
197202
vector = (uint32_t)&uart2_irq;
198203
}
199-
204+
205+
if (obj->uart == UART_3) {
206+
irq_n = USART3_IRQn;
207+
vector = (uint32_t)&uart3_irq;
208+
}
209+
200210
if (enable) {
201211

202212
if (irq == RxIrq) {

0 commit comments

Comments
 (0)