Skip to content

Commit 2305db6

Browse files
committed
STM32 serial: use uart_name in serial_irq_set function for F4
1 parent a908d28 commit 2305db6

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

targets/TARGET_STM/TARGET_STM32F4/serial_device.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,59 +168,63 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
168168
IRQn_Type irq_n = (IRQn_Type)0;
169169
uint32_t vector = 0;
170170

171-
switch (obj_s->index) {
172-
case 0:
171+
switch (obj_s->uart) {
172+
#if defined(USART1_BASE)
173+
case UART_1:
173174
irq_n = USART1_IRQn;
174175
vector = (uint32_t)&uart1_irq;
175176
break;
176-
case 1:
177+
#endif
178+
#if defined(USART2_BASE)
179+
case UART_2:
177180
irq_n = USART2_IRQn;
178181
vector = (uint32_t)&uart2_irq;
179182
break;
183+
#endif
180184
#if defined(USART3_BASE)
181-
case 2:
185+
case UART_3:
182186
irq_n = USART3_IRQn;
183187
vector = (uint32_t)&uart3_irq;
184188
break;
185189
#endif
186190
#if defined(UART4_BASE)
187-
case 3:
191+
case UART_4:
188192
irq_n = UART4_IRQn;
189193
vector = (uint32_t)&uart4_irq;
190194
break;
191195
#endif
192196
#if defined(UART5_BASE)
193-
case 4:
197+
case UART_5:
194198
irq_n = UART5_IRQn;
195199
vector = (uint32_t)&uart5_irq;
196200
break;
197201
#endif
198202
#if defined(USART6_BASE)
199-
case 5:
203+
case UART_6:
200204
irq_n = USART6_IRQn;
201205
vector = (uint32_t)&uart6_irq;
202206
break;
203207
#endif
204208
#if defined(UART7_BASE)
205-
case 6:
209+
case UART_7:
206210
irq_n = UART7_IRQn;
207211
vector = (uint32_t)&uart7_irq;
208212
break;
209213
#endif
210214
#if defined(UART8_BASE)
211-
case 7:
215+
case UART_8:
212216
irq_n = UART8_IRQn;
213217
vector = (uint32_t)&uart8_irq;
214218
break;
215219
#endif
216220
#if defined(UART9_BASE)
217-
case 8:
221+
case UART_9:
218222
irq_n = UART9_IRQn;
219223
vector = (uint32_t)&uart9_irq;
220224
break;
221225
#endif
222226
#if defined(UART10_BASE)
223-
case 9:
227+
case UART_10:
224228
irq_n = UART10_IRQn;
225229
vector = (uint32_t)&uart10_irq;
226230
break;
@@ -233,8 +237,8 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
233237
} else { // TxIrq
234238
__HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
235239
}
236-
NVIC_SetVector(irq_n, vector);
237-
NVIC_EnableIRQ(irq_n);
240+
NVIC_SetVector(irq_n, vector);
241+
NVIC_EnableIRQ(irq_n);
238242

239243
} else { // disable
240244
int all_disabled = 0;
@@ -253,7 +257,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
253257
}
254258

255259
if (all_disabled) {
256-
NVIC_DisableIRQ(irq_n);
260+
NVIC_DisableIRQ(irq_n);
257261
}
258262
}
259263
}
@@ -284,7 +288,7 @@ void serial_clear(serial_t *obj)
284288
{
285289
struct serial_s *obj_s = SERIAL_S(obj);
286290
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
287-
291+
288292
huart->TxXferCount = 0;
289293
huart->RxXferCount = 0;
290294
}
@@ -293,7 +297,7 @@ void serial_break_set(serial_t *obj)
293297
{
294298
struct serial_s *obj_s = SERIAL_S(obj);
295299
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
296-
300+
297301
HAL_LIN_SendBreak(huart);
298302
}
299303

0 commit comments

Comments
 (0)