Skip to content

Commit eaa3e9d

Browse files
committed
STM32F0 usart irq: fix issue with F070/F072
1 parent b6c9178 commit eaa3e9d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

targets/TARGET_STM/TARGET_STM32F0/serial_device.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,34 @@ static uart_irq_handler irq_handler;
5151
* INTERRUPTS HANDLING
5252
******************************************************************************/
5353

54-
static void uart_irq(int id)
54+
static uint32_t uart_irq(int id)
5555
{
5656
UART_HandleTypeDef * huart = &uart_handlers[id];
57-
57+
uint32_t status = 0;
58+
5859
if (serial_irq_ids[id] != 0) {
5960
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
6061
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) {
6162
irq_handler(serial_irq_ids[id], TxIrq);
63+
status = 1;
6264
}
6365
}
6466
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
6567
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) {
6668
irq_handler(serial_irq_ids[id], RxIrq);
6769
/* Flag has been cleared when reading the content */
70+
status = 1;
6871
}
6972
}
7073
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
7174
if (__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) {
7275
__HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF);
76+
status = 1;
7377
}
7478
}
7579
}
80+
81+
return status;
7682
}
7783

7884
static void uart1_irq(void)
@@ -90,42 +96,42 @@ static void uart2_irq(void)
9096
// Used for both USART3_4_IRQn and USART3_8_IRQn
9197
static void uart3_8_irq(void)
9298
{
99+
#if defined(TARGET_STM32F091RC)
93100
#if defined(USART3_BASE)
94-
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART3) != RESET)
95-
{
101+
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART3) != RESET) {
96102
uart_irq(2);
97103
}
98104
#endif
99105
#if defined(USART4_BASE)
100-
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART4) != RESET)
101-
{
106+
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART4) != RESET) {
102107
uart_irq(3);
103108
}
104109
#endif
105110
#if defined(USART5_BASE)
106-
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART5) != RESET)
107-
{
111+
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART5) != RESET) {
108112
uart_irq(4);
109113
}
110114
#endif
111115
#if defined(USART6_BASE)
112-
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART6) != RESET)
113-
{
116+
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART6) != RESET) {
114117
uart_irq(5);
115118
}
116119
#endif
117120
#if defined(USART7_BASE)
118-
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART7) != RESET)
119-
{
121+
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART7) != RESET) {
120122
uart_irq(6);
121123
}
122124
#endif
123125
#if defined(USART8_BASE)
124-
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART8) != RESET)
125-
{
126+
if (__HAL_GET_PENDING_IT(HAL_ITLINE_USART8) != RESET) {
126127
uart_irq(7);
127128
}
128129
#endif
130+
#else // TARGET_STM32F070RB, TARGET_STM32F072RB
131+
if (uart_irq(2) == 0) { // Check if it's USART3
132+
uart_irq(3); // Otherwise it's USART4
133+
}
134+
#endif
129135
}
130136

131137
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)

0 commit comments

Comments
 (0)