<?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>MCUXpresso SDK中的主题 Re: Bug in LPSPI_MasterTransferBlocking()?</title>
    <link>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011034#M2076</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I don't think that rxRemainingByteCount is being initialized properly in all cases. In SDK 2.7 fsl_lpspi.c, it is set as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t rxFifoMaxBytes = 4U * fifoSize;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps I am missing something, but shouldn't it take bytesPerFrame into consideration? Something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t rxFifoMaxBytes = ((bytesPerFrame &amp;lt;= 4U) ? bytesPerFrame : 4U) * fifoSize;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ran into the lockup issue again in LPSPI_MasterTransferBlocking() (SDK 2.7) using a bitsPerFrame setting of 8 before modifying it as above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Apr 2020 14:36:06 GMT</pubDate>
    <dc:creator>kevin_haake</dc:creator>
    <dc:date>2020-04-28T14:36:06Z</dc:date>
    <item>
      <title>Bug in LPSPI_MasterTransferBlocking()?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011031#M2073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe there is a potential issue in LPSPI_MasterTransferBlocking() (as found in fsl_lpspi.c / SDK 2.6, MKE14F512VLL16). What I have observed is that if this&amp;nbsp;function&amp;nbsp;is preempted/interrupted for a substantial length of time at the wrong time, an overrun can occur in&amp;nbsp;the Rx FIFO which causes the function to get stuck in an endless loop and&amp;nbsp;never return.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;issue appears to reside&amp;nbsp;in the Tx loop, and is exposed in the following circumstance:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Precondition: The Tx FIFO is full, and&amp;nbsp;the Rx FIFO is still empty (i.e. we are waiting for&amp;nbsp;data to be&amp;nbsp;clocked out)&lt;/P&gt;&lt;P&gt;1. The code waits for room to open up in the&amp;nbsp;Tx FIFO.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Once room is available (note that the Rx FIFO will not be empty at this point), another word is written to the Tx FIFO.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;3. The code then checks the Rx FIFO, and reads any data that is available.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF the driver is interrupted for a substantial amount of time between steps (2) and (3) above, it is possible that FIFOSIZE + 1 words will be clocked out before we read anything. If this happens, an Rx FIFO overrun will occur and a word will be dropped.&amp;nbsp;This&amp;nbsp;drop will cause the Rx loop at the end of the function (not shown) to never complete, because rxRemainingByteCount will never reach zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think that switching the order of steps (2) and (3) above would address&amp;nbsp;this issue, as shown in the below snippet. Notice that the write step was moved from before the read step to after the read step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/95308iD8E48CAF3BA54EA0/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Feb 2020 14:09:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011031#M2073</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-02-25T14:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Bug in LPSPI_MasterTransferBlocking()?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011032#M2074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/kevin.haake@licor.com" rel="nofollow noopener noreferrer" target="_blank"&gt;kevin.haake@licor.com&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your comments, as you mention this looks like a bug but I think this being checked in the new SDK revision:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;while&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txRemainingByteCount &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0U&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txRemainingByteCount &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; bytesEachWrite&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
            bytesEachWrite &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;uint8_t&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;txRemainingByteCount&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

        &lt;SPAN class="comment token"&gt;/*Wait until TX FIFO is not full*/&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;while&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;LPSPI_GetTxFifoCount&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;base&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; fifoSize&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

        &lt;SPAN class="comment token"&gt;/* To prevent rxfifo overflow, ensure transmitting and receiving are executed in parallel */&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;NULL &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; rxData&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;||&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rxRemainingByteCount &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; txRemainingByteCount&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; rxFifoMaxBytes&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
            &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txData &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; NULL&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
            &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
                wordToSend &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;LPSPI_CombineWriteData&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;txData&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; bytesEachWrite&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; isByteSwap&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
                txData &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; bytesEachWrite&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
            &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

            &lt;SPAN class="token function"&gt;LPSPI_WriteData&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;base&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; wordToSend&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
            txRemainingByteCount &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; bytesEachWrite&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

        &lt;SPAN class="comment token"&gt;/*Check whether there is RX data in RX FIFO . Read out the RX data so that the RX FIFO would not overrun.*/&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rxData &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; NULL&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
            &lt;SPAN class="keyword token"&gt;while&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;LPSPI_GetRxFifoCount&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;base&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0U&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
            &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
                readData &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;LPSPI_ReadData&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;base&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
                &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rxRemainingByteCount &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; bytesEachRead&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
                &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
                    bytesEachRead &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;uint8_t&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;rxRemainingByteCount&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
                &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

                &lt;SPAN class="token function"&gt;LPSPI_SeparateReadData&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rxData&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; readData&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; bytesEachRead&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; isByteSwap&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
                rxData &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; bytesEachRead&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

                rxRemainingByteCount &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; bytesEachRead&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
            &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
        &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
    &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/S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;&lt;/P&gt;&lt;P&gt;In the previous code, the driver checks the number of bytes in the RX and TX to send before sending another word so I think the overrun will be avoided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Alexis Andalon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Feb 2020 23:06:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011032#M2074</guid>
      <dc:creator>Alexis_A</dc:creator>
      <dc:date>2020-02-26T23:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Bug in LPSPI_MasterTransferBlocking()?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011033#M2075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Alexis. Yes, it appears that should work. Serves me right for not updating to SDK 2.7.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Feb 2020 23:20:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011033#M2075</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-02-26T23:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Bug in LPSPI_MasterTransferBlocking()?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011034#M2076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I don't think that rxRemainingByteCount is being initialized properly in all cases. In SDK 2.7 fsl_lpspi.c, it is set as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t rxFifoMaxBytes = 4U * fifoSize;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps I am missing something, but shouldn't it take bytesPerFrame into consideration? Something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint32_t rxFifoMaxBytes = ((bytesPerFrame &amp;lt;= 4U) ? bytesPerFrame : 4U) * fifoSize;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I ran into the lockup issue again in LPSPI_MasterTransferBlocking() (SDK 2.7) using a bitsPerFrame setting of 8 before modifying it as above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2020 14:36:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Bug-in-LPSPI-MasterTransferBlocking/m-p/1011034#M2076</guid>
      <dc:creator>kevin_haake</dc:creator>
      <dc:date>2020-04-28T14:36:06Z</dc:date>
    </item>
  </channel>
</rss>

