<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: RT685 USART Driver in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1955243#M228466</link>
    <description>&lt;P&gt;Does anyone know if writing to the FIFOINTENCLR register twice, very close in time together, would cause the second write to not take? That appears to be what's happening.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Sep 2024 14:24:53 GMT</pubDate>
    <dc:creator>jwprice100</dc:creator>
    <dc:date>2024-09-16T14:24:53Z</dc:date>
    <item>
      <title>RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1953654#M228388</link>
      <description>&lt;P&gt;I'm using a RT685 with the FreeRTOS USART driver provided in the SDK. The driver seems to work most of the time. However I end up somehow getting into a weird state after an indeterminate period of time.&amp;nbsp; It seems the base USART driver's IRQ Handler is called repeatedly over and over again. Digging into the reason it seems the tx level FIFO interrupt is firing. However there is no data to send.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Digging into the code I find:&lt;/P&gt;&lt;LI-CODE lang="c"&gt; /* Send data */
        if (sendEnabled &amp;amp;&amp;amp; ((base-&amp;gt;FIFOSTAT &amp;amp; USART_FIFOSTAT_TXNOTFULL_MASK) != 0U))
        {
            base-&amp;gt;FIFOWR = *handle-&amp;gt;txData;
            handle-&amp;gt;txDataSize--;
            handle-&amp;gt;txData++;
            sendEnabled = handle-&amp;gt;txDataSize != 0U;
            if (!sendEnabled)
            {
                base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_TXLVL_MASK;

                base-&amp;gt;INTENSET = USART_INTENSET_TXIDLEEN_MASK;
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;When tx data runs out it clearly disabled that interrupt. Yet I find from a breakpoint that txDataSize is zero! So it's like it ran out of data without executing the code path that would disable tx lvl interrupts.&lt;BR /&gt;&lt;BR /&gt;To confirm I added the following code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    if (!sendEnabled &amp;amp;&amp;amp; (base-&amp;gt;FIFOINTENSET &amp;amp; USART_FIFOINTENCLR_TXLVL_MASK) )
    {
        base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_TXLVL_MASK;
        base-&amp;gt;INTENSET = USART_INTENSET_TXIDLEEN_MASK;
    }&lt;/LI-CODE&gt;&lt;P&gt;This code does indeed fire. This seems impossible! Can anyone shed any light?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2024 17:51:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1953654#M228388</guid>
      <dc:creator>jwprice100</dc:creator>
      <dc:date>2024-09-12T17:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1955243#M228466</link>
      <description>&lt;P&gt;Does anyone know if writing to the FIFOINTENCLR register twice, very close in time together, would cause the second write to not take? That appears to be what's happening.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 14:24:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1955243#M228466</guid>
      <dc:creator>jwprice100</dc:creator>
      <dc:date>2024-09-16T14:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1955597#M228488</link>
      <description>&lt;P&gt;The issue does appear to be that when two writes to the FIFOINTENCLR register that are spaced closely in time, the second write may not work. I've confirmed via debugging that the register was written but did not clear. My solution is as follows:&lt;BR /&gt;&lt;BR /&gt;In the&amp;nbsp;USART_TransferHandleIRQ function replace:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_RXLVL_MASK | USART_FIFOINTENSET_RXERR_MASK;&lt;/LI-CODE&gt;&lt;P&gt;with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;while((base-&amp;gt;FIFOINTENSET &amp;amp; USART_FIFOINTENCLR_TXLVL_MASK) || (base-&amp;gt;FIFOINTENSET &amp;amp; USART_FIFOINTENCLR_TXLVL_MASK))
{
  base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_RXLVL_MASK | USART_FIFOINTENSET_RXERR_MASK;
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and replace&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_TXLVL_MASK;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//This is necesary in case the previous loop iteration just wrote it or the receive logic just wrote it.
while(base-&amp;gt;FIFOINTENSET &amp;amp; USART_FIFOINTENCLR_TXLVL_MASK)
{
  base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_TXLVL_MASK;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this helps anyone else encountering this issue.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 12:00:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1955597#M228488</guid>
      <dc:creator>jwprice100</dc:creator>
      <dc:date>2024-09-17T12:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1956788#M228594</link>
      <description>&lt;P&gt;This wasn't the source of the problem afterall. I just got really lucky and ran for many hours without getting stuck in the ISR. I think I know the real problem/solution, I'll report that if I am right.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 16:09:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1956788#M228594</guid>
      <dc:creator>jwprice100</dc:creator>
      <dc:date>2024-09-18T16:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1959970#M228779</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/217453"&gt;@jwprice100&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Did you find the root cause of this problem or are you still requiring support on this matter?&lt;/P&gt;
&lt;P&gt;If you did find the root cause, we would appreciate it if you would please share it so that it may benefit other community members.&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR /&gt;Gustavo&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 14:30:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1959970#M228779</guid>
      <dc:creator>gusarambula</dc:creator>
      <dc:date>2024-09-23T14:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1979567#M230008</link>
      <description>&lt;P&gt;I am also interested to hear how&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/217453"&gt;@jwprice100&lt;/a&gt;&amp;nbsp;made out.&amp;nbsp; Thanks in advance for sharing your results!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 22:29:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1979567#M230008</guid>
      <dc:creator>gregburlingame</dc:creator>
      <dc:date>2024-10-22T22:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1980399#M230057</link>
      <description>&lt;P&gt;I believe I identified the root cause of this matter. It's a fairly significant bug in the UART driver but it would only manifest if transmitting and receiving at the same time. I suspect most applications are not doing this which is why it may have remained hidden.&lt;/P&gt;&lt;P&gt;To understand the issue, the interrupt handler for the fsl_uart code has a snippet as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;        if (sendEnabled &amp;amp;&amp;amp; ((base-&amp;gt;FIFOSTAT &amp;amp; USART_FIFOSTAT_TXNOTFULL_MASK) != 0U))
        {
            base-&amp;gt;FIFOWR = *handle-&amp;gt;txData;
            handle-&amp;gt;txDataSize--;
            handle-&amp;gt;txData++;
            sendEnabled = handle-&amp;gt;txDataSize != 0U;
            if (!sendEnabled)
            {
                base-&amp;gt;FIFOINTENCLR = USART_FIFOINTENCLR_TXLVL_MASK;

                base-&amp;gt;INTENSET = USART_INTENSET_TXIDLEEN_MASK;
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The important thing to note is that it disables the tx interrupt sources in the interrupt handler itself.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the&amp;nbsp;USART_TransferSendNonBlocking function there are two lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;uint32_t interruptMask = USART_GetEnabledInterrupts(base);
USART_DisableInterrupts(base, interruptMask);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Followed later by:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;USART_EnableInterrupts(base, interruptMask | (uint32_t)kUSART_TxLevelInterruptEnable);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the interrupt happens to fire in between those first tw0o lines, and happened to clear the Tx interrupts in that call, the tx interrupts would then be re-enabled.&lt;/P&gt;&lt;P&gt;As one of those tx interrupt sources are the Tx FIFO level threshold the interrupt fires immediately. There's no code path to disable the tx interrupts in this case (they are only cleared if there was something to send and then all the bytes were drained), so the interrupt exists and fires again immediately. This hangs the processor.&lt;/P&gt;&lt;P&gt;Hopefully that all made sense, let me know if there are any questions about it. It's a very nasty bug so it should &lt;SPAN&gt;definitely&lt;/SPAN&gt; get fixed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 17:39:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1980399#M230057</guid>
      <dc:creator>jwprice100</dc:creator>
      <dc:date>2024-10-23T17:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: RT685 USART Driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1980429#M230058</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/217453"&gt;@jwprice100&lt;/a&gt;&amp;nbsp;for sharing your findings!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 18:22:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/RT685-USART-Driver/m-p/1980429#M230058</guid>
      <dc:creator>gregburlingame</dc:creator>
      <dc:date>2024-10-23T18:22:15Z</dc:date>
    </item>
  </channel>
</rss>

