From faee2bf073820222f14e0baf95ec002e8cfec21e Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Mon, 9 Dec 2013 13:01:39 +0200 Subject: [PATCH] [NUCLEO_F103RB] Serial interrupt fixes - use TC flag instead of TXE for TX interrupt - clear interrupt flags to prevent possible interrupt storm --- .../TARGET_NUCLEO_F103RB/serial_api.c | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c index 0385485d6e..6168810632 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c @@ -182,30 +182,21 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b ******************************************************************************/ // not api -void uart1_irq(void) { - USART_TypeDef *usart = (USART_TypeDef *)UART_1; - if (serial_irq_ids[0] != 0) { - if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) { - irq_handler(serial_irq_ids[0], TxIrq); +static void uart_irq(USART_TypeDef* usart, int id) { + if (serial_irq_ids[id] != 0) { + if (USART_GetITStatus(usart, USART_IT_TC) != RESET) { + irq_handler(serial_irq_ids[id], TxIrq); + USART_ClearITPendingBit(usart, USART_IT_TC); } if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) { - irq_handler(serial_irq_ids[0], RxIrq); + irq_handler(serial_irq_ids[id], RxIrq); + USART_ClearITPendingBit(usart, USART_IT_RXNE); } } } -// not api -void uart2_irq(void) { - USART_TypeDef *usart = (USART_TypeDef *)UART_2; - if (serial_irq_ids[1] != 0) { - if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) { - irq_handler(serial_irq_ids[1], TxIrq); - } - if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) { - irq_handler(serial_irq_ids[1], RxIrq); - } - } -} +static void uart1_irq(void) {uart_irq((USART_TypeDef*)UART_1, 0);} +static void uart2_irq(void) {uart_irq((USART_TypeDef*)UART_2, 1);} void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { irq_handler = handler; @@ -233,7 +224,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { USART_ITConfig(usart, USART_IT_RXNE, ENABLE); } else { // TxIrq - USART_ITConfig(usart, USART_IT_TXE, ENABLE); + USART_ITConfig(usart, USART_IT_TC, ENABLE); } NVIC_SetVector(irq_n, vector);