This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART code execution priority

Hi,

I'm developing a peripheral driver which involves UART. I encounter an issue I'm not sure how to proceed.

In my design, I have 

main.c

device_drv.c

device_drv.h

uart_drv.c

uart_dev.h

device_drv.c calls nordic uart driver wrapped in uart_drv.c. For most of the time, everything works. However, I'll get a buffer overrun error if I instantiate a timer in device_drv.c, and send UART frames in the timer handler. I tried to increase the UART priority in sdk_config.h to 3, and the issue goes away. I later move the timer handler to main.c, and the same issue appears. But If I put the piece of code in while (1), the issue disappeared.

I'm pulling my hair out.

Ideas?

Thanks,

Ye-Sheng

  • Hi Ye-Sheng,

    There is not enough information here to pinpoint what the problem is in your application, but what you writes gives an indication.

    Coping with interrupt priorities is a general problem with embedded development. A typical issue is if you busy wait somewhere, for something that should be done somewhere else that has the same or lower priority. In that case, the stuff you are waiting for never happens, because the code responsible for it never has time to run. So I suggest that the first thing is that you make sure you have full controll over the inter-dependencies in your code and ensure this does not happen.

    With this in mind, you write that you make some UART related calls from a timer interrupt. So this code runs with the interrupt priority of the timer. If you her wait for something that will not happen until after a UART interrupt has occurred, this will always fail unless UART has higher priority (lower number). And so it makes sense that increasing the UART priority helps.

    I later move the timer handler to main.c, and the same issue appears.

    I am not sure what you mean by moving it to main.c? The file itself is not important, so I assume you also do something else? 

    But If I put the piece of code in while (1), the issue disappeared.

    I assume you here refer to the main loop in your main function? If so, that makes sense. You can busy wait on anything there without any problem, as the main function runs in thread / main context, and no interrupts. So any interrupt will have higher priority than this.

  • Hi Elinar,

    This makes a lot of sense. I was under the wrong impression that an interrupt handler could be preempted by others with the same priority. 

    Thanks for the insight!

Related