Skip to content

Commit faee2bf

Browse files
author
Bogdan Marinescu
committed
[NUCLEO_F103RB] Serial interrupt fixes
- use TC flag instead of TXE for TX interrupt - clear interrupt flags to prevent possible interrupt storm
1 parent 2b8e05e commit faee2bf

File tree

1 file changed

+10
-19
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB

1 file changed

+10
-19
lines changed

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,30 +182,21 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
182182
******************************************************************************/
183183

184184
// not api
185-
void uart1_irq(void) {
186-
USART_TypeDef *usart = (USART_TypeDef *)UART_1;
187-
if (serial_irq_ids[0] != 0) {
188-
if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
189-
irq_handler(serial_irq_ids[0], TxIrq);
185+
static void uart_irq(USART_TypeDef* usart, int id) {
186+
if (serial_irq_ids[id] != 0) {
187+
if (USART_GetITStatus(usart, USART_IT_TC) != RESET) {
188+
irq_handler(serial_irq_ids[id], TxIrq);
189+
USART_ClearITPendingBit(usart, USART_IT_TC);
190190
}
191191
if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
192-
irq_handler(serial_irq_ids[0], RxIrq);
192+
irq_handler(serial_irq_ids[id], RxIrq);
193+
USART_ClearITPendingBit(usart, USART_IT_RXNE);
193194
}
194195
}
195196
}
196197

197-
// not api
198-
void uart2_irq(void) {
199-
USART_TypeDef *usart = (USART_TypeDef *)UART_2;
200-
if (serial_irq_ids[1] != 0) {
201-
if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
202-
irq_handler(serial_irq_ids[1], TxIrq);
203-
}
204-
if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
205-
irq_handler(serial_irq_ids[1], RxIrq);
206-
}
207-
}
208-
}
198+
static void uart1_irq(void) {uart_irq((USART_TypeDef*)UART_1, 0);}
199+
static void uart2_irq(void) {uart_irq((USART_TypeDef*)UART_2, 1);}
209200

210201
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
211202
irq_handler = handler;
@@ -233,7 +224,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
233224
USART_ITConfig(usart, USART_IT_RXNE, ENABLE);
234225
}
235226
else { // TxIrq
236-
USART_ITConfig(usart, USART_IT_TXE, ENABLE);
227+
USART_ITConfig(usart, USART_IT_TC, ENABLE);
237228
}
238229

239230
NVIC_SetVector(irq_n, vector);

0 commit comments

Comments
 (0)