nRF52840 UARTE0 EasyDMA receives more bytes than expected

Greetings!

I'm currently making a project that involves using UART in EasyDMA Mode (via Zephyr Async API).

I have noticed an interesting behavior when you try to receive via UARTE0 (provided by Interface/Debug chip VCOM).

For example, I'm enabling the reception with 

uart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);

After that I'm sending >10, let's say 20 bytes. After 10 bytes received I get an UART_RX_RDY callback, everything is very fine, but if I will restart the reception with

uart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);

I will instantly get one more UART_RX_RDY callback. Buffer will contain that second 10 bytes part.

My question is: Who is actually responsible for such a behavior? Is this some shadow UART buffer in RAM? If so, how can I control its size? Because I don't need it to buffer more than I have set up. Also I'm thinking about the Interface chip, probably if it has received something via VCOM, it stores some data inside in a hidden buffer.

If I switch to UARTE1, no such behavior is observed. Only UARTE0 via USB vcom.

Simple snippet for testing, some minimal editing may be needed:

#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
switch (evt->type) {
case UART_RX_RDY:
printk("RX READY\n");
printk("%d \n", evt->data.rx.len);
break;
}
}

static uint8_t rx_buf[10] = {0}; //A buffer to store incoming UART data

const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));
int main(void)
{
int err = 0;
if (!device_is_ready(uart)) {
return err;
}
err = uart_callback_set(uart, uart_cb, NULL);
if (err) {
return err;
}
uart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);
while (1)
{
k_msleep(5000); // Mash your keyboard here, make > 10 bytes in these 5 seconds
uart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);
}
return 0;
}

Thanks in advance,

BR

Vlad

Parents
  • Hi Vlad

    After that I'm sending >10, let's say 20 bytes. After 10 bytes received I get an UART_RX_RDY callback, everything is very fine, but if I will restart the reception

    I do not fully understand your setup. You are sending and receiving, or receiving at the other end?

    But if it is that it works for uarte1 and you see a problem with uart0, maybe you can send me a minimal project that compiles and I can test here. 

    Please do mention the SDK version you are using, and any other details regarding the setup if any.

    Regards,
    Naeem

  • Hi Naeem,

    are there any additional updates regarding this situation?

    BR

  • Hi Vlad,

    I am sorry for the delayed response due to high workload during this period.

    I have tried your code, but was not able to make it work. It would not go as you have described, and things were breaking (I have tried to debug as well but it would go into idle after entering callback set function).

    However, I have tried with the echo-bot sample. I was able to receive the exact amount as set in BUF_SIZE even if I press a lot of characters, only the specified amount is received.

    I have also seen that you are calling uart_rx_enable() in the while(1) loop, why?

    this function is supposed to be called only once and then the call back will be called as per events generated.

    Regards,
    Naeem

Reply
  • Hi Vlad,

    I am sorry for the delayed response due to high workload during this period.

    I have tried your code, but was not able to make it work. It would not go as you have described, and things were breaking (I have tried to debug as well but it would go into idle after entering callback set function).

    However, I have tried with the echo-bot sample. I was able to receive the exact amount as set in BUF_SIZE even if I press a lot of characters, only the specified amount is received.

    I have also seen that you are calling uart_rx_enable() in the while(1) loop, why?

    this function is supposed to be called only once and then the call back will be called as per events generated.

    Regards,
    Naeem

Children
No Data
Related