UART ASYNC Cause k_busy_wait to miss timing requirement

As the title said, I'm currently on the nRF21540 DK. I turned on Async UART:

CONFIG_UART_1_INTERRUPT_DRIVEN=n
CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_NRF_HW_ASYNC=y
CONFIG_UART_1_NRF_HW_ASYNC_TIMER=2
CONFIG_NRFX_TIMER2=y
so that I can do serial DFU (zephyr,uart-mcumgr) via UART using the hardware counter. However, when I turned this on, my main application called k_busy_wait missed the timing requirement and doubled. The current consumption is higher as well (which is expected).
 
Below is the current consumption with async uart (CONFIG_UART_ASYNC_API=y) but doesn't have hardware counter:
And this is with async uart hardware timer enabled:
My application logic need to use k_busy_wait and I also have to enable hardware timer because without it, I keep getting bytes dropped when sending too many bytes or when the baudrate is high.
I'm not sure what is the best way to do this, any help is appreciated.
Thanks so much.
  • Hi,

    Using busy wait means counting CPU cycles, so all other interrupts will delay the busy waiting. I see that the time you wait here is qutie long as well (a good number of milli seconds), so I am wondering why you need to use busy wait? As long as. you rdevice also need to do other operation at the same time, busy waiting like this will cause problems and I would suggest looking into handling that differently first.

Related