Skip to content

Commit e446c26

Browse files
committed
STM32 serial: use uart_name instead of uart_base
1 parent 7256af0 commit e446c26

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

targets/TARGET_STM/TARGET_STM32F4/serial_device.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ int8_t get_uart_index(int uart_base);
5656
* INTERRUPTS HANDLING
5757
******************************************************************************/
5858

59-
static void uart_irq(int uart_base)
59+
static void uart_irq(UARTName uart_name)
6060
{
61-
int8_t id = get_uart_index(uart_base);
61+
int8_t id = get_uart_index(uart_name);
62+
6263
if (id >= 0) {
6364
UART_HandleTypeDef * huart = &uart_handlers[id];
6465
if (serial_irq_ids[id] != 0) {
@@ -85,70 +86,70 @@ static void uart_irq(int uart_base)
8586
#if defined(USART1_BASE)
8687
static void uart1_irq(void)
8788
{
88-
uart_irq(USART1_BASE);
89+
uart_irq(UART_1);
8990
}
9091
#endif
9192

9293
#if defined(USART2_BASE)
9394
static void uart2_irq(void)
9495
{
95-
uart_irq(USART2_BASE);
96+
uart_irq(UART_2);
9697
}
9798
#endif
9899

99100
#if defined(USART3_BASE)
100101
static void uart3_irq(void)
101102
{
102-
uart_irq(USART3_BASE);
103+
uart_irq(UART_3);
103104
}
104105
#endif
105106

106107
#if defined(UART4_BASE)
107108
static void uart4_irq(void)
108109
{
109-
uart_irq(UART4_BASE);
110+
uart_irq(UART_4);
110111
}
111112
#endif
112113

113114
#if defined(UART5_BASE)
114115
static void uart5_irq(void)
115116
{
116-
uart_irq(UART5_BASE);
117+
uart_irq(UART_5);
117118
}
118119
#endif
119120

120121
#if defined(USART6_BASE)
121122
static void uart6_irq(void)
122123
{
123-
uart_irq(USART6_BASE);
124+
uart_irq(UART_6);
124125
}
125126
#endif
126127

127128
#if defined(UART7_BASE)
128129
static void uart7_irq(void)
129130
{
130-
uart_irq(UART7_BASE);
131+
uart_irq(UART_7);
131132
}
132133
#endif
133134

134135
#if defined(UART8_BASE)
135136
static void uart8_irq(void)
136137
{
137-
uart_irq(UART8_BASE);
138+
uart_irq(UART_8);
138139
}
139140
#endif
140141

141142
#if defined(UART9_BASE)
142143
static void uart9_irq(void)
143144
{
144-
uart_irq(UART9_BASE);
145+
uart_irq(UART_9);
145146
}
146147
#endif
147148

148149
#if defined(UART10_BASE)
149150
static void uart10_irq(void)
150151
{
151-
uart_irq(UART10_BASE);
152+
uart_irq(UART_10);
152153
}
153154
#endif
154155

targets/TARGET_STM/serial_api.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -558,81 +558,82 @@ HAL_StatusTypeDef init_uart(serial_t *obj)
558558

559559
// Warning: the list of UART/USART in this function must be aligned with the list
560560
// written in serial_init function.
561-
inline int8_t get_uart_index(int uart_base)
561+
inline int8_t get_uart_index(UARTName uart_name)
562562
{
563563
uint8_t index = 0;
564+
564565
#if defined(USART1_BASE)
565-
if (uart_base == USART1_BASE) return index;
566+
if (uart_name == UART_1) return index;
566567
index++;
567568
#endif
568569

569570
#if defined(USART2_BASE)
570-
if (uart_base == USART2_BASE) return index;
571+
if (uart_name == UART_2) return index;
571572
index++;
572573
#endif
573574

574575
#if defined(USART3_BASE)
575-
if (uart_base == USART3_BASE) return index;
576+
if (uart_name == UART_3) return index;
576577
index++;
577578
#endif
578579

579580
#if defined(UART4_BASE)
580-
if (uart_base == UART4_BASE) return index;
581+
if (uart_name == UART_4) return index;
581582
index++;
582583
#endif
583584

584585
#if defined(USART4_BASE)
585-
if (uart_base == USART4_BASE) return index;
586+
if (uart_name == UART_4) return index;
586587
index++;
587588
#endif
588589

589590
#if defined(UART5_BASE)
590-
if (uart_base == UART5_BASE) return index;
591+
if (uart_name == UART_5) return index;
591592
index++;
592593
#endif
593594

594595
#if defined(USART5_BASE)
595-
if (uart_base == USART5_BASE) return index;
596+
if (uart_name == UART_5) return index;
596597
index++;
597598
#endif
598599

599600
#if defined(USART6_BASE)
600-
if (uart_base == USART6_BASE) return index;
601+
if (uart_name == UART_6) return index;
601602
index++;
602603
#endif
603604

604605
#if defined(UART7_BASE)
605-
if (uart_base == UART7_BASE) return index;
606+
if (uart_name == UART_7) return index;
606607
index++;
607608
#endif
608609

609610
#if defined(USART7_BASE)
610-
if (uart_base == USART7_BASE) return index;
611+
if (uart_name == UART_7) return index;
611612
index++;
612613
#endif
613614

614615
#if defined(UART8_BASE)
615-
if (uart_base == UART8_BASE) return index;
616+
if (uart_name == UART_8) return index;
616617
index++;
617618
#endif
618619

619620
#if defined(USART8_BASE)
620-
if (uart_base == USART8_BASE) return index;
621+
if (uart_name == UART_8) return index;
621622
index++;
622623
#endif
623624

624625
#if defined(UART9_BASE)
625-
if (uart_base == UART9_BASE) return index;
626+
if (uart_name == UART_9) return index;
626627
index++;
627628
#endif
628629

629630
#if defined(UART10_BASE)
630-
if (uart_base == UART10_BASE) return index;
631+
if (uart_name == UART_10) return index;
631632
index++;
632633
#endif
633634

634635
#if defined(LPUART1_BASE)
635-
if (uart_base == LPUART1_BASE) return index;
636+
if (uart_name == LPUART_1) return index;
636637
index++;
637638
#endif
638639

0 commit comments

Comments
 (0)