Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug in the UART SW lib #430

Closed
vhdlnerd opened this issue Oct 16, 2022 · 1 comment · Fixed by #431
Closed

Possible bug in the UART SW lib #430

vhdlnerd opened this issue Oct 16, 2022 · 1 comment · Fixed by #431
Labels
bug Something isn't working as expected SW Software-related

Comments

@vhdlnerd
Copy link
Contributor

I'm writing some code in assembly and was looking at the neorv32_uart.c file for "inspiration" on how to interface to the UART. And, saw this C function:

/**********************************************************************//**
 * Check if UART0 has received a char.
 *
 * @note This function is non-blocking.
 * @note Use neorv32_uart0_char_received_get(void) to get the char.
 *
 * @return =!0 when a char has been received.
 **************************************************************************/
int neorv32_uart0_char_received(void) {

  if ((NEORV32_UART0.DATA & (1<<UART_DATA_AVAIL)) != 0) {
    return 1;
  }
  else {
    return 0;
  }
}

Although I did not test this, it seems wrong to me. If there are more than one chars in the UART RX FIFO, wouldn't neorv32_uart0_char_received() consume the first char (when checking the UART_DATA_AVAIL bit) in the FIFO and a later call to neorv32_uart0_char_received_get() would return the next char in the RX FIFO? (i.e., you would drop the first char).

When I coded this in assembly, I checked the UART_CTRL_RX_EMPTY bit in the NEORV32_UART0_CTRL control/status register instead -- it worked as expected.

Maybe, I'm missing something in the C code??

Thanks,
Brian

@stnolting
Copy link
Owner

Hey there!

If there are more than one chars in the UART RX FIFO, wouldn't neorv32_uart0_char_received() consume the first char

I think you are right. The function should check the RX FIFO flags in CTRL instead. Strange, that this has not caused any trouble so far... 😅

Thanks for identifying this bug!

@stnolting stnolting added bug Something isn't working as expected SW Software-related labels Oct 17, 2022
@stnolting stnolting linked a pull request Oct 17, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected SW Software-related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants