<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113001/nrf52840-uarte0-easydma-receives-more-bytes-than-expected</link><description>Greetings! 
 
 I&amp;#39;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&amp;#39;m enabling</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Sep 2024 12:39:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113001/nrf52840-uarte0-easydma-receives-more-bytes-than-expected" /><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/502126?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2024 12:39:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b956f93-691b-440b-9453-ea60da07671b</guid><dc:creator>LaszloUA</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;is there any new updates regarding this topic?&lt;/p&gt;
&lt;p&gt;BR&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/500752?ContentTypeID=1</link><pubDate>Mon, 02 Sep 2024 11:51:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df594399-513f-4434-bc35-ea654a889ffc</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Vlad,&lt;/p&gt;
&lt;p&gt;Naeem is away and wont be back soon. I was assigned to this thread. I will try soon to replicate the issue using the instruction you gave below.&amp;nbsp;Will come back to you when I have some new observations.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/499974?ContentTypeID=1</link><pubDate>Tue, 27 Aug 2024 12:00:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79315251-d157-4694-99c6-0c030cd0b6b2</guid><dc:creator>LaszloUA</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Naeem,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sorry, took a long vacation without visiting web. It is really strange that my code is not working on your side since I tested this simple example several times, but OK, I can make more confident example.&amp;nbsp;uart_rx_enable()&amp;nbsp;in loop was just needed to &amp;quot;restart&amp;quot; UART automatically. Bad example, agree.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Echo bot works very fine since it explicitly drops all data (custom logic implemented in interrupt). I use ASYNC driver so &amp;quot;under the hood&amp;quot; reception is not available for me.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have rewritten the code for it to work more correctly, could you please try it to see if you can reproduce my behavior? Now I have added BUTTON 1 to work. I use nRF52840-DK to run this application.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What you can do to reproduce this issue: &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Variant 1:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Connect to serial port and see&amp;nbsp;*** Booting nRF Connect SDK v3.5.99-ncs1-1 *** message (or your version).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Write some &amp;gt; 10 bytes message from your keyboard. You can just mash buttons.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Press Button 1 on the board. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Expected to see: UART IS RESTARTED.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; I see:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span&gt;UART IS RESTARTED&lt;br /&gt;RX READY&lt;br /&gt;Received: 10 bytes&lt;br /&gt;RX Stopped&lt;br /&gt;RX Disabled&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;So as you can see, uart_rx wasn&amp;#39;t even turned on while some data came in. Then you have turned it on by the push of the button and it INSTANTLY got some data you have entered while uart_rx was disabled. And I&amp;#39;m interested in how could it possibly function so nRF52 somehow still stores data inside even with uart_rx is off, how can I determine this buffer and prevent this behavior?&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Variant 2:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Connect to serial port and see&amp;nbsp;*** Booting nRF Connect SDK v3.5.99-ncs1-1 *** message (or your version).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Press Button 1 on the board. Observe&amp;nbsp;UART IS RESTARTED line.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Write some data. See how after 10 bytes you get&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span&gt;RX READY&lt;br /&gt;Received: 10 bytes&lt;br /&gt;RX Stopped&lt;br /&gt;RX Disabled&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now uart_rx is off. Now continue writing something while uart is off. Write at least 10 bytes.&lt;/p&gt;
&lt;p&gt;Press Button 1 on the board once again.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Observe:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span&gt;RX READY&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span&gt;Received: 10 bytes&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span&gt;RX Stopped&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span&gt;RX Disabled&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Hopefully this code will work better since I&amp;#39;ve upgraded it to rely only on button, not on some delays.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/uart.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;

static bool is_uart_enabled = false;
static uint8_t rx_buf[10] = {0};
const struct device* uart = DEVICE_DT_GET(DT_NODELABEL(uart0));
const static struct gpio_dt_spec button = GPIO_DT_SPEC_GET(DT_NODELABEL(button0), gpios);


static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{

    switch (evt-&amp;gt;type) {

    case UART_TX_DONE:
        break;

    case UART_TX_ABORTED:
        break;

    case UART_RX_RDY:
        printk(&amp;quot;RX READY\n&amp;quot;);
        printk(&amp;quot;Received: %d bytes\n&amp;quot;, evt-&amp;gt;data.rx.len);
        break;

    case UART_RX_BUF_REQUEST:
        break;

    case UART_RX_BUF_RELEASED:
        break;

    case UART_RX_DISABLED:
        printk(&amp;quot;RX Disabled\n&amp;quot;);
        is_uart_enabled = false;
        break;

    case UART_RX_STOPPED:
        printk(&amp;quot;RX Stopped\n&amp;quot;);
        break;

    default:
        break;
    }
}


int main(void)
{
    int err = 0;

    if (!device_is_ready(uart)) {
        return err;
    }

    if (!gpio_is_ready_dt(&amp;amp;button)) {
        return err;
    }

    gpio_pin_configure_dt(&amp;amp;button, (GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW));

    err = uart_callback_set(uart, uart_cb, NULL);
    if (err) {
        return err;
    }

    while (1)
    {
        if (gpio_pin_get_dt(&amp;amp;button) == 1)
        {
            if (is_uart_enabled == 0)
            {
                printk(&amp;quot;UART IS RESTARTED\n&amp;quot;);
                uart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);
                is_uart_enabled = true;
            }
        }
        k_msleep(500);
    }

    return 0;
}&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;prj.conf:&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Best regards,&lt;/div&gt;
&lt;div&gt;Vlad&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/495678?ContentTypeID=1</link><pubDate>Thu, 25 Jul 2024 15:20:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50c7a069-4eb8-4ba9-bed7-3f11da0efbb8</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Vlad,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am sorry for the delayed response due to high workload during this period.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;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&amp;nbsp;(I have tried to debug as well but it would go into idle after entering callback set function).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, I have tried with the &lt;a href="https://docs.zephyrproject.org/latest/samples/drivers/uart/echo_bot/README.html"&gt;echo-bot sample&lt;/a&gt;. 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.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have also seen that you are calling uart_rx_enable() in the while(1) loop, why?&lt;/p&gt;
&lt;p&gt;this function is supposed to be called only once and then the call back will be called as per events generated.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/494387?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2024 13:22:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4582aef1-5cec-4b6b-b6ce-6b16e49488aa</guid><dc:creator>LaszloUA</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Naeem,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;are there any additional&amp;nbsp;updates&amp;nbsp;regarding this situation?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BR&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/493855?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 10:30:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c300c5fb-21d2-4c76-bee4-923ce931cf7d</guid><dc:creator>LaszloUA</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Naeem,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let&amp;#39;s split my task on simple parts.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;m indeed using two separate UARTs to transfer data in a special way, but it&amp;#39;s not the point here, I will simplify the setup as&amp;nbsp;much as possible to still be able to reproduce this behavior.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So, for this simple setup I have: PC connected to the nRF52840 UARTE0 via USB cable (On board Interface Chip).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I send the data FROM PC (using Minicom but everything will work, puTTY, nRF Serial Term etc.) to my board. Board only receives data.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My board in EasyDMA mode accepts some bytes of data till 50 bytes will arrive OR till it will be stopped by Bluetooth interrupt to read it earlier.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The thing is: if you send less or equal to 50 bytes from PC to board, everything is fine. If you send more, the next time you will start and stop RX routine, buffer will already have some data inside (that data which was sent after initial 50 bytes).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I use 2.6.1 toolchain, nothing more special to tell, just a basic project. I will send you the code below. For simplicity, I put len of buffer equal 10 bytes. As soon as the board will boot, try to send at least 20 bytes or more data to it, you can for example mash your keyboard buttons and wait. After 5 seconds you will see the next thing in the console:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
RX READY
Received: 10 bytes // THIS WILL SHOW ASAP AFTER YOU ENTER 10 BYTES
RX Disabled
RX READY
Received: 10 bytes // THIS WILL SHOW AFTER UART_RX WILL BE RESTARTED IN WHILE LOOP
RX Stopped
RX Disabled&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Code:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/uart.h&amp;gt;

static uint8_t rx_buf[10] = {0};
const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{

    switch (evt-&amp;gt;type) {

    case UART_TX_DONE:
        break;

    case UART_TX_ABORTED:
        break;

    case UART_RX_RDY:
        printk(&amp;quot;RX READY\n&amp;quot;);
        printk(&amp;quot;Received: %d bytes\n&amp;quot;, evt-&amp;gt;data.rx.len);
        break;

    case UART_RX_BUF_REQUEST:
        break;

    case UART_RX_BUF_RELEASED:
        break;

    case UART_RX_DISABLED:
        printk(&amp;quot;RX Disabled\n&amp;quot;);
        break;

    case UART_RX_STOPPED:
        printk(&amp;quot;RX Stopped\n&amp;quot;);
        break;

    default:
        break;
    }
}


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);
        uart_rx_enable(uart, rx_buf, 10, SYS_FOREVER_US);
    }

    return 0;
}
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Config:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BR&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 UARTE0 EasyDMA receives more bytes than expected</title><link>https://devzone.nordicsemi.com/thread/493685?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2024 15:40:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70b8bd5e-f3cb-4e4c-893d-0e23b0f7c641</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Vlad&lt;/p&gt;
[quote user=""]After that I&amp;#39;m sending &amp;gt;10, let&amp;#39;s say 20 bytes. After 10 bytes received I get an&amp;nbsp;UART_RX_RDY callback, everything is very fine, but if I will restart the reception[/quote]
&lt;p&gt;I do not fully understand your setup. You are sending and receiving, or receiving at the other end?&lt;/p&gt;
&lt;p&gt;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.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please do mention the SDK version you are using, and any other details regarding the setup if any.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>