I am running the example application CE219656 for low-level UART w/ ISR. The part has been changed to run on the PSOC6 WiFi board.

Non-modified code works as expected. However, for my application, I am trying to see what the latest received byte is on the RX FIFO stack before performing a FIFO read, ie I want to 'peek' before I 'pop' the FIFO.

This should be achievable by reading the RX_FIFO_RD_SILENT register instead of the RX_FIFO_RD register in the interrupt service routine.

However, when I add this line to the ISR code:

read_data = UART_HW->RX_FIFO_RD_SILENT

before the call to

read_data = Cy_SCB_UART_Get(UART_HW)

the data is corrupted; ie the incorrect characters are written to the terminal.

I was just reviewing this code and noticed that there is a bug in the interrupt code. Your use case caused this bug to show up.

The bug is that the RX fifo not empty interrupt is cleared before data is read out of the FIFO. In the code example the FIFO was read directly after the interrupt was cleared which I believe was fast enough to not cause the interrupt to retrigger. In your case you inserted code between the interrupt clear and the actual read, which causes the interrupt to fire again. So the ISR gets entered again which causes it to read out of an empty fifo...

To fix the issue move the interrupt clear code below the read of the FIFO:

read_data = UART_HW->RX_FIFO_RD_SILENT;

/* Get the character from terminal */

read_data = Cy_SCB_UART_Get(UART_HW);

/* Clear UART "RX fifo not empty interrupt" */

UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;

However with this code there is still an issue which causes the interrupt to fire for a different reason I haven't debugged yet. So for your use case to fully work you need to change your ISR to look like: