mirror of https://github.com/ARMmbed/mbed-os.git
Fix uart race condition dropping bytes on NRF52
In nordic_nrf5_uart_event_handler if the events NRF_UARTE_EVENT_ENDRX and NRF_UARTE_EVENT_RXSTARTED become pending after the check for NRF_UARTE_EVENT_ENDRX but before the check for NRF_UARTE_EVENT_RXSTARTED the RX DMA buffers will be setup incorrectly by nordic_nrf5_uart_event_handler_rxstarted because active_bank hasn't been updated. This cause dropped and incorrect data. This patch fixes that problem by adding a second check for NRF_UARTE_EVENT_ENDRX after checking for NRF_UARTE_EVENT_RXSTARTED and skipping processing if NRF_UARTE_EVENT_ENDRX is set. The subsequent interrupt will process both in the correct order. This ensures that these events cannot be handled out of order and thus fixes the corruption.pull/8784/head
parent
d643034941
commit
4cda158e55
|
@ -727,8 +727,14 @@ static void nordic_nrf5_uart_event_handler(int instance)
|
|||
}
|
||||
}
|
||||
|
||||
/* Rx DMA buffer has been armed. */
|
||||
if (nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_RXSTARTED))
|
||||
/* Rx DMA buffer has been armed.
|
||||
*
|
||||
* Warning - Do not process NRF_UARTE_EVENT_RXSTARTED if NRF_UARTE_EVENT_ENDRX is pending.
|
||||
* NRF_UARTE_EVENT_RXSTARTED must be processed first or nordic_nrf5_uart_event_handler_rxstarted
|
||||
* will setup the wrong DMA buffer and cause data to be lost.
|
||||
*/
|
||||
if (nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_RXSTARTED) &&
|
||||
!nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDRX))
|
||||
{
|
||||
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_RXSTARTED);
|
||||
|
||||
|
|
Loading…
Reference in New Issue