<?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>UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running</link><description>I am noticing that particularly with the transmission of bytes over UART while scheduler is running, either some bytes go missing or the entire set of bytes aren&amp;#39;t sent or received. (I&amp;#39;m seeing the UART stuff in the serial port). Though, I can send bytes</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 04 Feb 2022 09:04:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running" /><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/351245?ContentTypeID=1</link><pubDate>Fri, 04 Feb 2022 09:04:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da0cf3c1-a525-48f8-87fb-01f2e9d2997e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My point about the setNrfEvent() function was more on the naming. Events are a specific type of register, and if you are also using this function to access task registers it might have been better to name it setNrfRegister() or something like that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Looking at the definition it seems generic enough to access any register.&amp;nbsp;&lt;/p&gt;
[quote user="morpho"]&lt;p&gt;After further debugging, it seemed to me the following was causing an issue. I was creating a local copy of Uart instance inside the class instead of a reference.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Though I&amp;#39;m not sure as to how was Uart instance created when it doesn&amp;#39;t match the constructor&lt;/p&gt;[/quote]
&lt;p&gt;That might explain the issue, at least it is something you should fix before doing further testing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Possibly the compiler is implementing a default void constructor?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/350977?ContentTypeID=1</link><pubDate>Wed, 02 Feb 2022 23:55:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d34f5445-a242-4fbf-a105-224108df243e</guid><dc:creator>morpho</dc:creator><description>[quote userid="2116" url="~/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running/350403#350403"]&lt;p&gt;Is StartTx() used in blocking or non blocking mode in Uart::PrintUart() ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;StartTx() does non blocking transfer via interrupts in Uart::PrintUart().&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running/350403#350403"]I assume the function declaration in the header file has a default value, since you don&amp;#39;t specify this parameter?[/quote]
&lt;p&gt;That&amp;#39;s right.&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running/350403#350403"]&lt;p&gt;How have you implemented the&amp;nbsp;setNrfEvent() function?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; void setNrfEvent(T reg, uint32_t value)
    {
        *((volatile uint32_t *)((uint8_t *)pUARTx + (uint32_t)reg)) = value;
        //volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)reg + (uint32_t)reg));
        volatile uint32_t dummy = *( (volatile uint32_t *) ((uint8_t *)pUARTx + (uint32_t)reg) );
        (void)dummy;
    }&lt;/pre&gt;&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running/350403#350403"]&lt;p&gt;Is it intentional that you are using this to access both events and tasks?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;are you saying why am I not using existing nRF UART driver and use my own functions? If so, it&amp;#39;s just to be confident in understanding the driver part.&lt;/p&gt;
&lt;p&gt;I really gotta add that it&amp;#39;s uber hard to debug on nRF particularly cause as you step into each calls, at some point, it ends up at an Unknown function&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;After further debugging, it seemed to me the following was causing an issue. I was creating a local copy of Uart instance inside the class instead of a reference.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Though I&amp;#39;m not sure as to how was Uart instance created when it doesn&amp;#39;t match the constructor&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;class NotificationManager : public Observer
{
    Subject *subscriptions[maxSubscriptions] = {nullptr};	// store references to Subject
    uint8_t subscriptionIdx = 0;
    Uart _uart;     // *** ISSUE *** a local copy
    BleCustomService &amp;amp;_bleCustSrv;
    Fifo&amp;lt;Notification&amp;gt; _notifications;

    public:
    
    // constructor
    template&amp;lt;typename ...Args&amp;gt;
    NotificationManager(BleCustomService &amp;amp;bleCustSrv, Uart &amp;amp;uart, Args ...args) : _bleCustSrv(bleCustSrv), _uart(uart), _notification{0}
    {
        ((subscriptions[subscriptionIdx] = args), ...);
        subscriptions[subscriptionIdx++]-&amp;gt;attach(this);
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/350403?ContentTypeID=1</link><pubDate>Mon, 31 Jan 2022 11:51:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1efcc58-8260-48b6-8ae8-bfc249488764</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is StartTx() used in blocking or non blocking mode in Uart::PrintUart() ?&lt;/p&gt;
&lt;p&gt;I assume the function declaration in the header file has a default value, since you don&amp;#39;t specify this parameter?&lt;/p&gt;
&lt;p&gt;How have you implemented the&amp;nbsp;setNrfEvent() function?&lt;/p&gt;
&lt;p&gt;Is it intentional that you are using this to access both events and tasks?&lt;/p&gt;
&lt;p&gt;Have you been able to figure out how many times the irqHandler is called as a result of a single UART transaction?&lt;/p&gt;
&lt;p&gt;(say you try to send 4 bytes, how often will the interrupt happen?)&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/350289?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 20:22:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecb116ee-7d07-468c-b04e-e0a3a14e3c7c</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/NotificationManager.cpp"&gt;devzone.nordicsemi.com/.../NotificationManager.cpp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/uart.cpp"&gt;devzone.nordicsemi.com/.../uart.cpp&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;it&amp;#39;s the following lines in NotificationManager.cpp that&amp;#39;s printing to UART being delayed&lt;/p&gt;
&lt;pre&gt;snprintf(_notification.msg, 50, &amp;quot;t=%uC&amp;quot;, tmpValue);
_uart.PrintUart(_notification.msg);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;here you go. thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/350252?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 14:59:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:336a8154-1e3f-41b2-b722-c25e3296a791</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I did, thank you &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The whole project might not be necessary, but at least the source code for the implementation of the driver, and&amp;nbsp;any files that use the driver.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regard&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/350100?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 04:44:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ac314aa-c9f4-40f0-8a9a-3cafc2d8f3b0</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Hi. No worries. I hope you had a great time off.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;My code hasn&amp;#39;t really changed since the last time. Do you want me to attach the whole project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/349531?ContentTypeID=1</link><pubDate>Tue, 25 Jan 2022 13:01:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b7be311-d7b4-4e93-afe7-142cae371bbb</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry for the slow response, I have been out in holiday for a while.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you still having issues with this?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If so, can you please share the current state of your code so I can have a look at it?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/345792?ContentTypeID=1</link><pubDate>Tue, 04 Jan 2022 04:27:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:706582b3-2a20-4c63-aee9-28ce27ea9ff2</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;UART interrupt is firing fine and so does the TxByte(). It&amp;#39;s not that I don&amp;#39;t see anything in terminal, but moreso the rate at which I see the output is waay too slow as you can see in the video shared above. And this only happens for the sensor data that I&amp;#39;m outputting over UART in a thread&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/341620?ContentTypeID=1</link><pubDate>Thu, 02 Dec 2021 07:05:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42e29ce2-dd4e-47f5-912f-878a3a4df8db</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Have you checked with the debugger if the UART interrupt is actually called?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And if it is called, will it get to the point where the TxByte() function is called to load the next byte?&lt;/p&gt;
&lt;p&gt;If you only see one byte of data every time you try to write a string it seems like the UART interrupt is not working properly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/341375?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 17:18:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d9e2d69-d41c-4909-9446-a63f22f605f6</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;No, _uart.PrintToTermina() is invoked within a thread context and not ISR I believe. &lt;br /&gt;I am setting&amp;nbsp;TWI_IRQ_PRIORITY as the interrupt priority for the I2C sensor and for UART, I&amp;#39;m passing in&amp;nbsp; APP_IRQ_PRIORITY_LOWEST as the priority.&amp;nbsp;So perhaps&amp;nbsp;it causes&amp;nbsp;the UART interrupt to be preempted by the I2C&amp;#39;s?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Although I don&amp;#39;t read I2C values until after 3 seconds and the UART transmission shouldn&amp;#39;t take that long before the next I2C interrupt occurs no?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)	   
{
    MCP9808 *obj = static_cast&amp;lt;MCP9808*&amp;gt;(p_context);
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    switch (p_event-&amp;gt;type)
    {
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
                // unblock the waiting thread (mainThread) once RX XFER is done
                vTaskNotifyGiveFromISR(obj-&amp;gt;taskHandle, &amp;amp;xHigherPriorityTaskWoken); 
            }
            else if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_TX)
            {
                NRF_LOG_INFO(&amp;quot;TX transfer done...\n&amp;quot;);
                m_xfer_done = true; 
            }
            break;
        default:
            break;
    }
}

void MCP9808::mainThread()
{
    xferData(tmpBuffer, 1);  
    vTaskDelay(pdMS_TO_TICKS(2000));
    uint32_t notifiedValue;

    while(true)
    {   
        uint32_t val = i2cRead(); // invokes TWI interrupt

        uint32_t taskNotify = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);  // blocks the current thread by decrementing ulNotifiedValue to 0 (taking a semaphore)
        if (taskNotify != 0)
        {
	        NRF_LOG_WARNING(&amp;quot;Transmission ended as expected...\n&amp;quot;);
        }
        else
        {
	        NRF_LOG_WARNING(&amp;quot;The call to ulTaskNotifyTake timed out\n&amp;quot;);
        }
        
        // if here, ISR is done executing and signalling to unblock this thread

        readTempInC();

        notify(this);       // calling _uart.PrintToTermina() within notify()
  
        vTaskDelay(pdMS_TO_TICKS(3000));
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/341203?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 08:43:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:385449ef-1125-4727-828f-ab3755d14fbb</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any chance you are calling _uart.PrintToTerminal() from interrupt context, with higher or equal interrupt priority to the UART interrupt?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/340991?ContentTypeID=1</link><pubDate>Mon, 29 Nov 2021 07:19:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fcebc2ab-9607-4ccc-9200-8747c0e536b3</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Thanks. It does make sense to clear the TXDRDY event inside StartTx so that when the interrupt is fired, it&amp;#39;s already enabled which can be disabled then and it does seem to do the trick in this case.&lt;/p&gt;
&lt;p&gt;However, I&amp;#39;m seeing an interesting behavior when I call&amp;nbsp;&lt;strong&gt;PrintToTerminal()&lt;/strong&gt; inside a sensor thread which is called as soon as a sensor value is read in a constant loop with a&amp;nbsp;delay of 3 seconds.&lt;/p&gt;
&lt;p&gt;That&amp;#39;s how I&amp;#39;m invoking PrintToTermina().&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;snprintf(_notification.msg, 50, &amp;quot;temp: %u&amp;quot;, tmpValue); // temp: 20 (for e.g)
_uart.PrintToTerminal(_notification.msg);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;seems like every byte is printed every 3 seconds or so as opposed to the&amp;nbsp;each message being printed rightaway so every 3 seconds, we should be seeing a new message. Do you see what could be going wrong here?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ntfMgrPrintDelay.mov"&gt;devzone.nordicsemi.com/.../ntfMgrPrintDelay.mov&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;in case you can&amp;#39;t see the video:&amp;nbsp;&lt;a href="https://imgur.com/a/FKmEPrp"&gt;https://imgur.com/a/FKmEPrp&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/339736?ContentTypeID=1</link><pubDate>Fri, 19 Nov 2021 06:18:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bb680d2-8ca5-4913-a903-70aa55824c09</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
[quote user="morpho"]my understanding is: TxByte() sends the first byte only and is never invoked after since the first-byte transmission should enable the TXDRDY event which the interrupt should handle from then on.[/quote]
&lt;p&gt;You call the TxByte() function inside the interrupt handler, as long as there is data in the FIFO. Wouldn&amp;#39;t this mean it&amp;#39;s called for every transmitted byte, except for the last?&lt;/p&gt;
[quote user="morpho"]why inside StartTx? What difference does clearing inside StartTx make than inside TxByte?[/quote]
&lt;p&gt;Then you ensure that the TXDRDY event is cleared before you start a new transaction, but leave it up to the interrupt handler to clear it for every transmitted byte.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Technically it should be enough just to clear it in the interrupt handler, so this might also work.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/339531?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 23:19:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d5f6996-5142-45da-ab25-b4fc2917616e</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Understood your point about DMA but like you also mentioned, it&amp;#39;s mostly used for stuff that requires high throughput like SPI.&lt;/p&gt;
&lt;p&gt;Understood about being offered limited support for custom stuff and it&amp;#39;s totally fair. It&amp;#39;s just if you could see any issues with the logic and if not, it&amp;#39;s fine and if so, great!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running/339453#339453"]I find the fact that you clear the TXDRDY event both in the interrupt handler and in the TxByte function a bit worrying.&amp;nbsp;[/quote]
&lt;p&gt;my understanding is: TxByte() sends the first byte only and is never invoked after since the first-byte transmission should enable the TXDRDY event which the interrupt should handle from then on.&lt;/p&gt;
[quote userid="2116" url="~/f/nordic-q-a/81718/uart-tx-in-particular-seems-to-have-a-race-condition-with-scheduler-running/339453#339453"]&lt;p&gt;Possibly it will work better if you only clear this in StartTx and in the interrupt.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;why inside StartTx? What difference does clearing inside StartTx make than inside TxByte?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/339453?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 13:47:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a8a14a0-34bf-456b-a8a3-0585c02d67b7</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
[quote user="morpho"]doesn&amp;#39;t UARTE use DMA additionally? why would that ensure no bytes are lost?[/quote]
&lt;p&gt;That&amp;#39;s one of the main&amp;nbsp;reasons to use DMA in the first place.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;DMA allows UART TX and RX data to be read from and written to RAM in parallel, without the CPU having to be involved. This means that if the CPU is busy handling a high priority interrupt the UART data can still flow in and out of RAM seamlessly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;All the CPU has to do is to prepare the TX and RX buffers in RAM, and let the UARTE peripheral know the address and size of these buffers, before starting a TX or RX transaction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Other advantages of DMA is less CPU usage and higher data throughput (more important for high speed peripherals like SPI).&amp;nbsp;&lt;/p&gt;
[quote user="morpho"]i am actually writing my own driver. do you see whether there&amp;#39;s a possibility of a race condition in my snippet?[/quote]
&lt;p&gt;You are free to do that if you want, but please be aware that we can only offer limited support for custom driver implementations. If you are planning to enter production I would strongly discourage it, as the responsibility falls on you rather than Nordic to ensure the driver works satisfactorily.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As for race conditions of the code, I find the fact that you clear the TXDRDY event both in the interrupt handler and in the TxByte function a bit worrying.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Possibly it will work better if you only clear this in StartTx and in the interrupt.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since UART transmission is controlled from the nRF52 side there shouldn&amp;#39;t be any risk of losing bytes here, even without DMA. It is more of an issue for RX data, since this can occur outside the control of the nRF.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/339326?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 04:32:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3ea2e92-2653-4948-85d3-f83757b82e2c</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Yes, this is nRF62840.&lt;/p&gt;
&lt;p&gt;doesn&amp;#39;t UARTE use DMA additionally? why would that ensure no bytes are lost?&lt;br /&gt;&lt;br /&gt;i am actually writing my own driver. do you see whether there&amp;#39;s a possibility of a race condition in my snippet?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART TX in particular seems to have a race condition with scheduler running</title><link>https://devzone.nordicsemi.com/thread/339188?ContentTypeID=1</link><pubDate>Tue, 16 Nov 2021 10:17:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df98ed76-89ef-4a61-97ae-17b55febf199</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Can you confirm that you are using the nRF52840 device?&lt;/p&gt;
&lt;p&gt;First off you should use the UARTE peripheral rather than the UART peripheral in order to ensure that no bytes are lost.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Secondly, you should use the nrfx_uarte driver rather than using the peripheral directly. These drivers have been developed by us over time to configure the peripherals optimally, and have been thoroughly tested to ensure they work well in different applications.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>