<?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: LPUART driver bug in MCUXpresso SDK</title>
    <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1184590#M2882</link>
    <description>&lt;P&gt;I haven't had time to put together an example project that reproduces the problem, but I can confirm it still exists. The 'fix' I suggested above seems to work in my use case: LEVEL_1 interrupts should be disabled in LPUART_EnableInterrupts() and LPUART_DisableInterrupts() before modifying base-&amp;gt;CTRL, and then the LEVEL_1 interrupts can be reenabled before these functions return. (via&amp;nbsp;DisableIRQ() and EnableIRQ()).&lt;BR /&gt;&lt;BR /&gt;One thing that I didn't outline above is that the FreeRTOS driver functions LPUART_RTOS_Send() and LPUART_RTOS_Receive() should also be modified so that the send and receive non-blocking calls occur in a critical section, like the following:&lt;BR /&gt;&lt;BR /&gt;taskENTER_CRITICAL();&lt;BR /&gt;LPUART_TransferSendNonBlocking(handle-&amp;gt;base, handle-&amp;gt;t_state, &amp;amp;handle-&amp;gt;txTransfer);&lt;BR /&gt;taskEXIT_CRITICAL();&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;taskENTER_CRITICAL();&lt;BR /&gt;LPUART_TransferReceiveNonBlocking(handle-&amp;gt;base, handle-&amp;gt;t_state, &amp;amp;handle-&amp;gt;rxTransfer, &amp;amp;n);&lt;BR /&gt;taskEXIT_CRITICAL();&lt;/P&gt;&lt;P&gt;This prevents the LEVEL_1 interrupts being disabled for a potentially long time due to a low priority task doing the disabling and then getting preempted by a higher priority task before reenabling.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason the LEVEL_1 interrupts need to be disabled before modifying base-&amp;gt;CTRL is that LPUART_TransferHandleIRQ() also modifies base-&amp;gt;CTRL, and this modification is not an atomic operation. This can cause an interrupt flag to get stuck on (ex: LPUART_CTRL_TIE).&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2020 15:18:58 GMT</pubDate>
    <dc:creator>kevin_haake</dc:creator>
    <dc:date>2020-11-17T15:18:58Z</dc:date>
    <item>
      <title>LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1080690#M2614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is a UART driver issue that is present in SDK_2.7.0. While I have not tested it, I believe it is still present in&amp;nbsp;SDK_2.8. I am using a MKE14F512VLL16.&amp;nbsp;In my case I am also using FreeRTOS and have one task handling sending data out the UART and another task reading data from the UART, concurrently.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Things usually appear to work fine. However, we have witnessed a small number of&amp;nbsp;mysterious device lockups and so I was tasked with looking into it. What I found was that in this bad state, the device would repeatedly receive a Tx interrupt. Inside of LPUART_TransferHandleIRQ() ,&amp;nbsp;the kLPUART_TxDataRegEmptyFlag would be set in STAT, and the kLPUART_TxDataRegEmptyInterruptEnable flag would be set in CTRL. However, the handle-&amp;gt;txDataSize field would unexpectedly be zero. This caused an endless interrupt loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe the root cause of this problem is&amp;nbsp;a small window of opportunity where a new Rx request would be made by the application (via LPUART_TransferReceiveNonBlocking()). Among other things, this&amp;nbsp;request calls LPUART_DisableInterrupts() and LPUART_EnableInterrupts() to clear/set various interrupt flags. Normally this is fine. However, there is a problem in the following scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. IF within LPUART_EnableInterrupts (for example), the following line starts to be executed:&lt;BR /&gt;base-&amp;gt;CTRL |= mask;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. A&amp;nbsp;Tx interrupt immediately occurs causing the last byte of a transfer to be written out. Note that in this case, the&amp;nbsp;LPUART_TransferHandleIRQ()&amp;nbsp;will do the following:&lt;BR /&gt;base-&amp;gt;CTRL = (base-&amp;gt;CTRL &amp;amp; ~LPUART_CTRL_TIE_MASK);&lt;BR /&gt;which (correctly) clears&amp;nbsp;the Tx interrupt flag.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, because the operation in #1 is not atomic (*), if the interrupt occurred after the read instruction of the read/modify/write instruction sequence in #1, but before the write instruction, when the ISR returns and the application call continues within LPUART_EnableInterrupts(), it will write stale data back to CTRL, with&amp;nbsp;the Tx interrupt flag still set. This causes the lockup.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be a more elegant way to fix this, but one fix for this case is to disable the UART IRQs&amp;nbsp;at&amp;nbsp;the beginning of LPUART_DisableInterrupts() and LPUART_EnableInterrupts() and then reenable them before the&amp;nbsp;function returns. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #7f0055;"&gt;&lt;STRONG&gt;void&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;STRONG&gt;LPUART_EnableInterrupts&lt;/STRONG&gt;(&lt;SPAN style="color: #005032;"&gt;LPUART_Type&lt;/SPAN&gt; *base, &lt;SPAN style="color: #005032;"&gt;uint32_t&lt;/SPAN&gt; mask)&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;{&lt;/P&gt;&lt;P style="color: #3f7f5f; margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #000000;"&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; // First NEW CODE&amp;nbsp;block start&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #005032;"&gt;uint32_t&lt;/SPAN&gt; instance = LPUART_GetInstance(base);&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #7f0055;"&gt;&lt;STRONG&gt;#if&lt;/STRONG&gt;&lt;/SPAN&gt; defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) &amp;amp;&amp;amp; FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;DisableIRQ(s_lpuartTxIRQ[instance]);&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;DisableIRQ(s_lpuartRxIRQ[instance]);&lt;/P&gt;&lt;P style="color: #7f0055; margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG&gt;#else&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;DisableIRQ(s_lpuartIRQ[instance]);&lt;/P&gt;&lt;P style="color: #7f0055; margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG&gt;#endif&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&amp;nbsp; &amp;nbsp;// First NEW CODE&amp;nbsp;block end&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;base-&amp;gt;&lt;SPAN style="color: #0000c0;"&gt;BAUD&lt;/SPAN&gt; |= ((mask &amp;lt;&amp;lt; 8U) &amp;amp; (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK));&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #7f0055;"&gt;&lt;STRONG&gt;#if&lt;/STRONG&gt;&lt;/SPAN&gt; defined(FSL_FEATURE_LPUART_HAS_FIFO) &amp;amp;&amp;amp; FSL_FEATURE_LPUART_HAS_FIFO&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;base-&amp;gt;&lt;SPAN style="color: #0000c0;"&gt;FIFO&lt;/SPAN&gt; = (base-&amp;gt;&lt;SPAN style="color: #0000c0;"&gt;FIFO&lt;/SPAN&gt; &amp;amp; ~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK)) |&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;((mask &amp;lt;&amp;lt; 8U) &amp;amp; (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK));&lt;/P&gt;&lt;P style="color: #7f0055; margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG&gt;#endif&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;mask &amp;amp;= 0xFFFFFF00U;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;base-&amp;gt;&lt;SPAN style="color: #0000c0;"&gt;CTRL&lt;/SPAN&gt; |= mask;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;BR /&gt;// Second NEW CODE block start&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #7f0055;"&gt;&lt;STRONG&gt;#if&lt;/STRONG&gt;&lt;/SPAN&gt; defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) &amp;amp;&amp;amp; FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;EnableIRQ(s_lpuartRxIRQ[instance]);&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;EnableIRQ(s_lpuartTxIRQ[instance]);&lt;/P&gt;&lt;P style="color: #7f0055; margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG&gt;#else&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;EnableIRQ(s_lpuartIRQ[instance]);&lt;/P&gt;&lt;P style="color: #7f0055; margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;STRONG&gt;#endif&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&amp;nbsp; &amp;nbsp;// Second NEW CODE block end&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;(*) The disassembly of&amp;nbsp;&lt;SPAN&gt;base-&amp;gt;CTRL |= mask shows the following (non-atomic):&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt; background-color: yellow;"&gt;00066a58:&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ldr&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;r3, [r7, #4]&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt; background-color: yellow;"&gt;00066a5a:&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ldr&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;r2, [r3, #24]&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// copies base-&amp;gt;CTRL into temporary register&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt; background-color: yellow;"&gt;00066a5c:&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ldr&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;r3, [r7, #0]&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WINDOW OF OPPORTUNITY exists here if interrupt&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt; background-color: yellow;"&gt;00066a5e:&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;orrs&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;r2, r3&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;// &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;occurs and ISR modifies CTRL flag. If it does,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt; background-color: yellow;"&gt;00066a60:&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;ldr&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;r3, [r7, #4]&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;our CTRL copy will now be stale!&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt; background-color: yellow;"&gt;00066a62:&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;str&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;r2, [r3, #24]&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// writes potentially stale result of OR back to base-&amp;gt;CTRL&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in; font-size: medium; color: #000000; text-indent: 0px; text-decoration: none;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: yellow;"&gt;666&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;// potentially losing ISR change&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2020 17:14:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1080690#M2614</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-08-10T17:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1134381#M2732</link>
      <description>&lt;P&gt;Hi Cavin:&lt;/P&gt;
&lt;P&gt;Thank you very much for your sharing.&amp;nbsp; I will try to reproduce your issue on my side.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 15:19:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1134381#M2732</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2020-09-02T15:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1150475#M2752</link>
      <description>&lt;P&gt;Thank you, Daniel. For what it is worth, I was able to able to reproduce the issue somewhat reliably by simply increasing the frequency of the reads and writes to multiple transfers a second. Even so, this would produce a lockup only once every 3 to 4 hours or so on average.&lt;/P&gt;&lt;P&gt;In my case, the transmit transfers were generally short (generally less than 100 bytes each), and the read transfers were only a single byte at a time. (Many more read transfers than write transfers).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 15:54:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1150475#M2752</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-09-08T15:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1150932#M2754</link>
      <description>&lt;P&gt;could&amp;nbsp; you please send me your simple project for me to reproduce?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 07:51:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1150932#M2754</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2020-09-09T07:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1151611#M2758</link>
      <description>&lt;P&gt;My current project is too complex to split up easily, but I'll try to put something together for you that exhibits the issue and post it.&lt;BR /&gt;&lt;BR /&gt;I could be wrong, but I think as long as you have two freeRTOS tasks, one reading a byte at a time from a UART (that has data being written to it) and the other writing to the same UART, repeatedly, the problem will eventually show up.&lt;/P&gt;&lt;P&gt;In my case, one of my tasks is repeatedly calling&amp;nbsp;LPUART_RTOS_Receive() and the other is repeatedly calling&amp;nbsp;LPUART_RTOS_Send().&lt;/P&gt;&lt;P&gt;Note that LPUART_RTOS_Receive() eventually calls&amp;nbsp;LPUART_TransferReceiveNonBlocking() and waits for the transfer to finish. The latter calls both&amp;nbsp;LPUART_DisableInterrupts and&amp;nbsp;LPUART_EnableInterrupts while it is setting up the transfer. (I am using a 32 byte ring buffer).&lt;BR /&gt;&lt;BR /&gt;LPUART_RTOS_Send() eventually calls&amp;nbsp;LPUART_TransferSendNonBlocking() and waits for the transfer to finish.&lt;/P&gt;&lt;P&gt;The trick is that the start of a Rx transfer needs to be initiated immediately before a previously started Tx transfer finishes. The latter has to interrupt the Rx task and finish the transfer (i.e. modify base-&amp;gt;CTRL) just as the former is in the middle of setting base-&amp;gt;CTRL inside of LPUART_DisableInterrupts() or LPUART_EnableInterrupts(). This window is small, but it exists.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 13:28:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1151611#M2758</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-09-14T13:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1184579#M2881</link>
      <description>&lt;P&gt;Any updates on this? We've hit the same bug on SDK 2.8.0.&lt;/P&gt;
&lt;P&gt;We're communicating with our ble chip via lpuart, sending data from one task and receiving from another.&lt;/P&gt;
&lt;P&gt;Randomly we hit the exact lockup described in this topic.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 14:57:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1184579#M2881</guid>
      <dc:creator>alexmarin</dc:creator>
      <dc:date>2020-11-17T14:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1184590#M2882</link>
      <description>&lt;P&gt;I haven't had time to put together an example project that reproduces the problem, but I can confirm it still exists. The 'fix' I suggested above seems to work in my use case: LEVEL_1 interrupts should be disabled in LPUART_EnableInterrupts() and LPUART_DisableInterrupts() before modifying base-&amp;gt;CTRL, and then the LEVEL_1 interrupts can be reenabled before these functions return. (via&amp;nbsp;DisableIRQ() and EnableIRQ()).&lt;BR /&gt;&lt;BR /&gt;One thing that I didn't outline above is that the FreeRTOS driver functions LPUART_RTOS_Send() and LPUART_RTOS_Receive() should also be modified so that the send and receive non-blocking calls occur in a critical section, like the following:&lt;BR /&gt;&lt;BR /&gt;taskENTER_CRITICAL();&lt;BR /&gt;LPUART_TransferSendNonBlocking(handle-&amp;gt;base, handle-&amp;gt;t_state, &amp;amp;handle-&amp;gt;txTransfer);&lt;BR /&gt;taskEXIT_CRITICAL();&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;taskENTER_CRITICAL();&lt;BR /&gt;LPUART_TransferReceiveNonBlocking(handle-&amp;gt;base, handle-&amp;gt;t_state, &amp;amp;handle-&amp;gt;rxTransfer, &amp;amp;n);&lt;BR /&gt;taskEXIT_CRITICAL();&lt;/P&gt;&lt;P&gt;This prevents the LEVEL_1 interrupts being disabled for a potentially long time due to a low priority task doing the disabling and then getting preempted by a higher priority task before reenabling.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason the LEVEL_1 interrupts need to be disabled before modifying base-&amp;gt;CTRL is that LPUART_TransferHandleIRQ() also modifies base-&amp;gt;CTRL, and this modification is not an atomic operation. This can cause an interrupt flag to get stuck on (ex: LPUART_CTRL_TIE).&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 15:18:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1184590#M2882</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-11-17T15:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1227057#M3055</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was fixed by the SDK team, it should be released in SDK 2.10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 10:06:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1227057#M3055</guid>
      <dc:creator>alexmarin</dc:creator>
      <dc:date>2021-02-05T10:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: LPUART driver bug</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1227196#M3056</link>
      <description>&lt;P&gt;Super - thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 14:46:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/LPUART-driver-bug/m-p/1227196#M3056</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2021-02-05T14:46:49Z</dc:date>
    </item>
  </channel>
</rss>

