From 14b83e7fdfb2066bc21c13119956557d800b1cfe Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Fri, 7 Jun 2019 15:36:21 +0200 Subject: [PATCH] STM32WB: Fix serial IRQ handling Check that the RX or TX interrupt is enabled before calling a registered handler with RxIrq or TxIrq arg. --- targets/TARGET_STM/TARGET_STM32WB/serial_device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32WB/serial_device.c b/targets/TARGET_STM/TARGET_STM32WB/serial_device.c index 03283498cb..c0262aac1f 100644 --- a/targets/TARGET_STM/TARGET_STM32WB/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32WB/serial_device.c @@ -55,12 +55,12 @@ static void uart_irq(UARTName uart_name) UART_HandleTypeDef *huart = &uart_handlers[id]; if (serial_irq_ids[id] != 0) { if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) { - if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) { + if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE)) { irq_handler(serial_irq_ids[id], TxIrq); } } if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) { - if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) { + if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE)) { irq_handler(serial_irq_ids[id], RxIrq); /* Flag has been cleared when reading the content */ }