<?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>Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90099/asynchronous-uart-api-dma-not-working-like-expected-on-nrf52840</link><description>hi, i am trying to use the async uart api on a nrf52840 for communicating to a quectel bg95 modem. no matter which timeout or buffer-size i am using, i am experiencing the problem that that some (1-2) bytes of the modem response are not received (or forwarded</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 27 Jul 2022 12:22:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90099/asynchronous-uart-api-dma-not-working-like-expected-on-nrf52840" /><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/378904?ContentTypeID=1</link><pubDate>Wed, 27 Jul 2022 12:22:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a742e991-9e29-431e-b383-c8febd1be6c4</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;Finally I managed to find the solution by myself:&lt;/p&gt;
&lt;p&gt;add the following lines to prj.conf:&lt;/p&gt;
&lt;p&gt;CONFIG_UART_0_ASYNC=y&lt;br /&gt;CONFIG_UART_0_NRF_HW_ASYNC=y&lt;br /&gt;CONFIG_UART_0_NRF_HW_ASYNC_TIMER=0&lt;/p&gt;
&lt;p&gt;some kind of documentation about this would have helped me a lot.&lt;br /&gt;menuconfig did not help either, because when setting the timer instance number there, compilation fails afterwards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/378765?ContentTypeID=1</link><pubDate>Tue, 26 Jul 2022 15:23:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2314fc15-00a8-46c6-a1a0-9ad4145abeb3</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;The async uart dma driver counts the RXRDY events which are raised by the nrf-hardware immediately after detecting a fully received byte, but potentially before transferring it to the dma memory buffer (see nrf52840 datasheet). This counting is done within an ISR. And this counted value is used by the driver logic when executing the timer-timeout event.&lt;/p&gt;
&lt;p&gt;There is some comment within the driver source code (around line 1075 in uart_nrfx_uarte.c) that it might happen that this counting is wrong due to latencies in handling interrupts.&lt;/p&gt;
&lt;p&gt;With the debugger I can confirm, that the driver falls into this &amp;quot;if (len&amp;lt;0) {...}&amp;quot;, where wrong counts are handled, in the case that the problem occurs.&lt;/p&gt;
&lt;p&gt;It does not fall into this branch, when CONFIG_NETWORKING is disabled.This is the case where everything works fine.&lt;/p&gt;
&lt;p&gt;So for me it seems that CONFIG_NETWORKING does some ISR handling which takes too long time, blocking the RXRDY isr handling for too long time, which leads to wrong byte counting.&lt;/p&gt;
&lt;p&gt;CONFIG_NETWORKING adds quite a big amount of source code to the project, therefore I am kind of lost where to look for the long-lasting isr handling.&lt;/p&gt;
&lt;p&gt;So I would really appreciate any hint for how to get out of this problem!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/378340?ContentTypeID=1</link><pubDate>Fri, 22 Jul 2022 13:54:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cac6fe2c-9a6c-4053-9a08-6ed0502ef0f7</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;I made an interesting experience:&lt;br /&gt;The async dma uart handling works fine until the &amp;quot;CONFIG_NETWORKING&amp;quot; config option is added to the prj.conf file.&lt;br /&gt;Building and running the identical application code, it then runs into the described problem.&lt;/p&gt;
&lt;p&gt;I tried the app without CONFIG_NETWORKING ... then I had no problem with sending/receiving 2000 AT-commands to/from the modem.&lt;/p&gt;
&lt;p&gt;After adding CONFIG_NETWORKING with no other change ... then the app ran into the problem while waiting for the first two status messages from the modem.&lt;/p&gt;
&lt;p&gt;Networking is unfortunately required as the application is going to use mqtt as communication protocol.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/378082?ContentTypeID=1</link><pubDate>Thu, 21 Jul 2022 12:02:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7bc4ebc-67b6-48d1-abad-5f00c056716d</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;thanks for trying that out. Please update this thread once you find out the issue so that this thread can be complete.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377923?ContentTypeID=1</link><pubDate>Wed, 20 Jul 2022 14:53:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9c14ae7-1ffc-4874-a7da-5528692eb523</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;With the standallone demo example, I am not able to reproduce the problem.&lt;/p&gt;
&lt;p&gt;So there must be some side-effects from other software running in parallel.&lt;/p&gt;
&lt;p&gt;I have to investigate this further ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377848?ContentTypeID=1</link><pubDate>Wed, 20 Jul 2022 11:55:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ce7405f-bc02-402c-a998-14fb1fb4bd98</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="Volker"]I can try to prepare some isolated example for a nrf52840dk eval board. Would that help?[/quote]
&lt;p&gt;That would help a lot. Thanks, will wait for your minimal example to reproduce the issue and debug on my desk.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377766?ContentTypeID=1</link><pubDate>Wed, 20 Jul 2022 06:50:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bcf8e78-74e8-4631-ae48-74f49dc5d792</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define QUD_RX_QUEUE_ENTRY_INIT \
{                               \
    .data = { 0 },              \ 
    .length = 0                 \
}

typedef struct Qud_RxQueueEntry_Tag Qud_RxQueueEntry_T;
struct Qud_RxQueueEntry_Tag
{
    uint8_t data[ 8 ];
    uint8_t length;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &amp;quot;e&amp;quot; variable is a local variable of a struct type, containing data bytes and length.&lt;br /&gt;As this variable is local and immediately put into a queue, I cannot imagine, that there is some accessing problem.&lt;/p&gt;
&lt;p&gt;I can try to prepare some isolated example for a nrf52840dk eval board. Would that help?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377713?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 17:34:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:585cb699-288d-4e3b-9c8b-0c40960e466f</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;That kind of issues normally happens in some variables (normally global variables) when accessed in different contexts.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In you code&amp;nbsp;&lt;/p&gt;
&lt;p&gt;k_msgq_put( &amp;amp;Qud_rxQueue, &lt;strong&gt;&amp;amp;e&lt;/strong&gt;, K_NO_WAIT );&lt;/p&gt;
&lt;p&gt;Check how you declared &amp;quot;e&amp;quot; and how you are accessing it. It looks like there could data access issue. I cannot be sure that the issue is just with this variable, but there is not much code to review.&amp;nbsp; In any case, i am quite confident that the issue is most likely in the code changes you did in your application. It would help to attach the whole setup (files) so that I can replicate this issue and assist you better.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377701?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 15:59:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:074e0a53-07e1-435d-af42-c305deadf1e2</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;After some more hours of testing the problem occurred also in release mode. But substantially less often.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377618?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 12:14:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e3d3fab-94b4-46f4-8b1c-3a3e00a3868f</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;I made the observation that the problem seems to show up only in debug mode. When building in release mode, I cannot see that kind of problem.&lt;br /&gt;In our configuration the debug mode is mainly specified as:&lt;/p&gt;
&lt;p&gt;CONFIG_DEBUG=y&lt;br /&gt;CONFIG_SIZE_OPTIMIZATIONS=n&lt;br /&gt;CONFIG_DEBUG_OPTIMIZATIONS=y&lt;br /&gt;CONFIG_ASSERT=y&lt;br /&gt;CONFIG_LOG=y&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377516?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 06:52:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45b23625-c787-4b80-bd52-6645cab48b9f</guid><dc:creator>Volker</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void Qud_Init()
{
    uart_callback_set( Qud_uartDevice, 
                       Qud_DmaUartCallback, 
                       NULL );

    uart_rx_enable( Qud_uartDevice,
                    dmaBuffer-&amp;gt;data,  
                    sizeof( dmaBuffer-&amp;gt;data ), 
                    1000 /* us */ );
}




static void Qud_DmaUartCallback( const struct device* dev,
                                 struct uart_event*   evt,
                                 void*                user_data)
{
    switch ( evt-&amp;gt;type )
    {
        case UART_RX_RDY:
            {
                Qud_RxQueueEntry_T e = QUD_RX_QUEUE_ENTRY_INIT;

                e.length = evt-&amp;gt;data.rx.len;
                memcpy( e.data, 
                        &amp;amp;( evt-&amp;gt;data.rx.buf[ evt-&amp;gt;data.rx.offset ] ),
                        evt-&amp;gt;data.rx.len );

                k_msgq_put( &amp;amp;Qud_rxQueue, 
                            &amp;amp;e, 
                            K_NO_WAIT );
            }
            break;
            
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;There is also a logic analyzer connected. The modem sends the data properly.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;As mentioned in my post before: The data is not lost, but it is received with a more or less big delay .... depending on point when the modem sends the next bytes (usually part of the next command).&lt;/p&gt;
&lt;p&gt;The code is part of a battery-powered device, where the activation time of the modem is quite critical for the overall power-consumption. Therefore we are interested in having as short delays as possible during the modem communication.&lt;/p&gt;
&lt;p&gt;As the uart-callback function is called from an isr-context I tried various different message passing variants. It seemed that all of them did not make any difference for this problem. The one here uses a very simple message queue without any optimizations.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART API (DMA) not working like expected on nrf52840</title><link>https://devzone.nordicsemi.com/thread/377501?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 05:00:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7d7da4a-5fee-47d0-b1d9-9e6801503979</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Can you please post some code snippets of how you have initialized the asyn uart and code snippets to show transfers from nrf side.&lt;/p&gt;
&lt;p&gt;Have you already verified on the the modem transmit lines (using logic analyzer of oscilloscope) that modem is sending the data correctly?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>