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 secondsuart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);}return 0;}
Thanks in advance,
BR
Vlad