I have multiple threads that try to read from a message queue via
osMessageQueueGet(MsgQueue, &msg, NULL, 0U)
The Event Recorder show me very frequent "Host Buffer Overflows". According to https://www.keil.com/support/man/docs/uv4/uv4_db_dbg_evr_view.htm this happens due to too frequent buffer writes, but it also happens when the queue is empty and nothing is actually written to the message buffer. When I set the timeout of osMessageQueueGet() to 1ms or more, the overflows get less fequent, but that also makes the algorithm less responsive.
Does someone have an idea why this happens? The code is running on a Cortex-M3. Is it too slow?
I followed the documentation and there it is described exactly as I have implemented it. The event switching doesn't look good.
Your code is spinning, which is causing too many messages for the debug link to handle. Find a way to slow down the calls to osMessageQueueGet(). For example, wait on an event to check the queue. Or, modify the event recorder message filter so that only the messages you want make it to the debugger.
Well that is what I've been thinking. The problem is that I can't start or suspend threads from ISRs. It reads the message queue that a UART ISR fills.
Does it mean that it is only an issue with the debug link? Then I could just leave it for now, since it is not crucial. I would then see if I can improve this later.
You can send an event from the UART ISR that fills the message queue (put the new message then send an event). The receiving thread is launched from main() or another thread -- anywhere that isn't an ISR.
In the receiving thread, loop like this:
The thread event flags are a free resource, in that you don't have to create an event flag.
View all questions in Keil forum