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

[BUG] UART ZEPHYR Transport will (most likely) stop to work after a few transactions when using USB-CDC #420

Closed
ghost opened this issue Apr 5, 2024 · 1 comment · Fixed by #421
Labels

Comments

@ghost
Copy link

ghost commented Apr 5, 2024

Describe the bug

Problem is the way how ring buffer is used.

static void TransferCallback(const struct device *dev, void *user_data)
{
uint8_t c;
uint32_t size;
uint32_t rx_size;
uint32_t tx_size;
uint8_t *data;
int err;
if (!uart_irq_update(dev))
{
return;
}
if (uart_irq_rx_ready(dev))
{
size = ring_buf_put_claim(&uart_receive_buf, &data, UART_BUFFER_SIZE);
/* read until FIFO empty */
rx_size = uart_fifo_read(dev, data, size);
if (rx_size < 0)
{
/* Error */
}
if (rx_size == size)

A call to ring_buf_put_claim() does not return the free space in the buffer, but the number of bytes that can be written into the also returned buffer pointer until the wrap around point it hit.

image

In my case the ERPC packets are 26 bytes long, the default buffer size appears to be 256 bytes.
When sending the 1st packet ring_buf_put_claim() will return 256. When the 2nd packet is received however it will only return 230. On the next packet 204 and so on.

The problem now is that when the 10th packet arrives ring_buf_put_claim() will only return 22 and the current implementation thus does not empty the receive fifo.

The problematic condition is actually even tested for, but the 'Error' is not handled

if (rx_size == size)
{
if (uart_fifo_read(dev, &c, 1) == 1)
{
/* Error - more data in fifo */
}
}

As a consequence the erpc server on the device will stop responding - with the given example of 26 byte sized service requests this will happen at the 10th invocation.

With a 'regular' UART this current implementation should normally not be a problem as you get an Interrupt per single byte received, but of course that depends on actual HW used.

To Reproduce

Create an erpc server on MCU running ZephyrRTOS, create a service that results in packets with size

Expected behavior

Client should be able to invoke the service on the device indefinltely as many times as desired

Screenshots

n/a

Desktop (please complete the following information)

Steps you didn't forgot to do

  • [ x] I checked if there is no related issue opened/closed.
  • [ x] I checked that there doesn't exist opened PR which is solving this issue.

Additional context

@ghost ghost added the bug label Apr 5, 2024
Copy link

github-actions bot commented Apr 5, 2024

Hi eRPC user. Thank you for your interest and welcome. We hope you will enjoy this framework well.

ghost pushed a commit to Setec-BMPRO/erpc that referenced this issue Apr 5, 2024
fixes issue 420.
Not yet happy about error handling though ....

fixes: EmbeddedRPC#420
MichalPrincNXP pushed a commit that referenced this issue Apr 17, 2024
…ork after a few transactions when using USB-CDC (#421)

* fix for issue 420

fixes issue 420.
Not yet happy about error handling though ....

fixes: #420

* fix formatting

* fixing formatting 2nd attempt

this time replacing file with one provided via
#421 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 participants