Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 9 months ago.
How to handle multiple UARTs with single interrupt?
I'm pretty new to embedded development so I may simply miss something obvious here. I ported mbed to our custom board with a STM32F030CC. That has a lot in common with the STM32F091RC which was already present so I got it working rather quick. In contrast to the F091RC, it only has 6 UARTs. In common with the F091RC, it has most of them on a single interrupt. So UART3 to 6 are on the same IRQ.
In the business logic I try to implement now we get unsolicited messages on several of these ports. Two of them are time and mission critical (Modbus RS485, so we have to answer in a pretty short time frame). Since I don't know when a message arrives and how large the message is, I wanted to register ISRs for all possible UARTs. That would be UART3, 5 and 6 (UART2 as well, but that has a separate IRQ, so that is not a problem so far). The thing is, if I simply use (Raw)Serial::attach, I end up with the last called uart_irq method registered on the IRQ. If any of the other UARTs trigger now, I end up in an endless IRQ-loop (since the IRS it has been called for find's no bits set (neither ORE, nor RX nor TX) so it just quits just to be triggered again.
I guess the current way as handled for F091RC in serial_device.c, by setting
if (obj_s->uart == UART_3) { irq_n = USART3_8_IRQn; vector = (uint32_t)&uart3_irq; } if (obj_s->uart == UART_4) { irq_n = USART3_8_IRQn; vector = (uint32_t)&uart4_irq; } //...
... is not correct. Since it will just let the last call to ::attach win. I guess all of them have to provide the same method which then has to check what UARTs have any flags set and proceed with their registered callback. But that also doesn't feel quite right.
What is the idiomatic way to handle this? Should I even use interrupts or is there a better way to read from multiple UARTs without knowing when and what to receive?