<?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>Kinetis MicrocontrollersのトピックRe: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362215#M18472</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Hi Mark,&lt;/SPAN&gt;&lt;/P&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;&amp;nbsp; When the DMA is transfer&amp;nbsp; ,It must not&amp;nbsp; run your above code ,&amp;nbsp; because the RM Write it clearly (as to my above reply (1));&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Now , you do not want pause DMA, I think you only can pause UART for changer BCR. &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Best Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Alice&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 25 Nov 2014 12:56:25 GMT</pubDate>
    <dc:creator>Alice_Yang</dc:creator>
    <dc:date>2014-11-25T12:56:25Z</dc:date>
    <item>
      <title>Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362211#M18468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wrote a KL26 UART driver using circular tx/rx buffers and DMA.&amp;nbsp; It works fine, except once in a while it seems to skip a byte on transmit.&amp;nbsp; I suspect the problem might have something to do with the way I update BCR (the counter in the DSR_BCR register) when adding data to the transmit buffer.&amp;nbsp; The code looks like this (data to send is pointed to by "data" and length "len"):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14166138870718951" jivemacro_uid="_14166138870718951" modifiedtitle="true"&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Disable the UART Tx DMA request while we work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[n].DCR &amp;amp;= ~(DMA_DCR_ERQ_MASK);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t old_bcr = DMA0-&amp;gt;DMA[n].DSR_BCR &amp;amp; DMA_DSR_BCR_BCR_MASK;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (old_bcr + len &amp;lt; circular_buffer_size)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Add new data to tx buffer and update "put" pointer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t bytesToEnd = (1 &amp;lt;&amp;lt; UART_TX_BUF_SIZE_ORDER) - txPutPtr;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (len &amp;lt;= bytesToEnd)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;txBuf[txPutPtr], data, len);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;txBuf[txPutPtr], &amp;amp;data[0],&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bytesToEnd);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;txBuf[0],&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;data[bytesToEnd], len-bytesToEnd);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txPutPtr = (txPutPtr + len) &amp;amp; (circular_buffer_size - 1);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Update the DMA channel BCR counter to account for the new data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[n].DSR_BCR = DMA_DSR_BCR_DONE_MASK;&amp;nbsp; // must clear DONE first, then write BCR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[n].DSR_BCR = DMA_DSR_BCR_BCR(old_bcr + len);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Resume the Tx DMA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[n].DCR |= DMA_DCR_ERQ_MASK;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is, is it safe to modify BCR in this manner?&amp;nbsp; Or is there a better way to ensure DMA is paused while I modify it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Nov 2014 00:01:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362211#M18468</guid>
      <dc:creator>mark03</dc:creator>
      <dc:date>2014-11-22T00:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362212#M18469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think your code have no problem , while&amp;nbsp; I have some suggestion for you .&lt;/P&gt;&lt;P&gt;1 )&amp;nbsp; The KL26&amp;nbsp; RM says "&lt;/P&gt;&lt;P&gt;During a channel's execution, writes to programming model&lt;/P&gt;&lt;P&gt;registers can corrupt the data transfer. The DMA module itself&lt;/P&gt;&lt;P&gt;does not have a mechanism to prevent writes to registers during&lt;/P&gt;&lt;P&gt;a channel's execution."&lt;/P&gt;&lt;P&gt;so , I&amp;nbsp; suggest you do this on the DMA complete ISR;&lt;/P&gt;&lt;P&gt;2) The&amp;nbsp; L&amp;nbsp; series processor UART have not receive/send FIFO, so it easily occur byte lost when reconfigure the DMA, so if can , reduce the UART baud rate.&lt;/P&gt;&lt;P&gt;In Kinetis K&amp;nbsp; series , the UART have receive/send FIFO&amp;nbsp; , it is convenient for reconfigure DMA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps !&lt;/P&gt;&lt;P&gt;Alice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Nov 2014 04:10:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362212#M18469</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2014-11-22T04:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362213#M18470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alice,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The KL26 RM is somewhat ambiguous on what is ok and what is not ok here.&amp;nbsp; I am still hoping someone with firsthand experience, or knowledge of the internal DMA peripheral structure, will respond with suggestions.&amp;nbsp; I'd prefer not to have to use the DMA-complete interrupt, but that's my backup plan if I can't figure this out.&amp;nbsp; (As designed, a DMA-complete interrupt will never occur unless the circular buffer runs out of space.&amp;nbsp; I like this design, but...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My working hypothesis as to what may be happening goes something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Transmit DMA is active when the code above is called.&amp;nbsp; So the code might intersect the running DMA at any point---during the read phase, the write phase, or whenever.&lt;/P&gt;&lt;P&gt;2) Suppose that when ERQ is cleared, a DMA transaction was half-complete: the read from txBuf had occurred, but the write to UART_D had not yet occurred.&lt;/P&gt;&lt;P&gt;3) When ERQ is set (after the BCR change), a new DMA transaction starts, and the old byte which had not yet been written to UART_D is lost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is just a guess.&amp;nbsp; The manuals don't specify the internal workings of the DMA engine in enough detail to confirm or deny.&amp;nbsp; What do you think?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 17:57:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362213#M18470</guid>
      <dc:creator>mark03</dc:creator>
      <dc:date>2014-11-24T17:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362214#M18471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think customer code exists the risk. &lt;/P&gt;&lt;P&gt;During DMA transfer data to UART data register, calling above code will pause the DMA transfer.&lt;/P&gt;&lt;P&gt;The data could not be transferred to UART data register successfully.&lt;/P&gt;&lt;P&gt;Then the current UART transmit request will be omitted (no data transmit at UART port).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Customer can consider to use DMA cycle-steal mode to transfer data to UART data register.&lt;/P&gt;&lt;P&gt;When customer want to modify DMA BCR counter value, customer can write 0 to UARTx_C2[TE] register to disable the UART transmit.&lt;/P&gt;&lt;P&gt;The current transmit activity in progress will be completed. &lt;/P&gt;&lt;P&gt;The code can polling the UARTx_S1[TDRE] status flag is set to indicate current transmit data buffer empty.&lt;/P&gt;&lt;P&gt;Then customer could call related DMA BCR modification code to change the DMA BCR counter value. &lt;/P&gt;&lt;P&gt;After that, customer can re-enable UART transmit via set UARTx_C2[TE] register.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Wish it helps.&lt;BR /&gt;best regards &lt;BR /&gt;Ma Hui&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 08:38:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362214#M18471</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2014-11-25T08:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362215#M18472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Hi Mark,&lt;/SPAN&gt;&lt;/P&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;&amp;nbsp; When the DMA is transfer&amp;nbsp; ,It must not&amp;nbsp; run your above code ,&amp;nbsp; because the RM Write it clearly (as to my above reply (1));&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Now , you do not want pause DMA, I think you only can pause UART for changer BCR. &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Best Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14.0pt;"&gt;Alice&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 12:56:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362215#M18472</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2014-11-25T12:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362216#M18473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I will try this and report back.&amp;nbsp; So I will clear UARTx_C2[TE], then poll for UARTx_S1[TDRE].&amp;nbsp; But when TDRE is set, won't that initiate another DMA cycle?&amp;nbsp; Because the UART TDMAE bit is still enabled.&amp;nbsp; Or is the UART TX DMA request output gated by TE?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 16:29:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362216#M18473</guid>
      <dc:creator>mark03</dc:creator>
      <dc:date>2014-11-25T16:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Safe/correct way to pause DMA, modify BCR count, and resume?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362217#M18474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My above suggestion also exists the risk. So, I suggest you can use below way:&lt;/P&gt;&lt;P&gt;1&amp;gt; At first, disable the DMA request;&lt;/P&gt;&lt;P&gt;2&amp;gt; The code add some delay, it need consider DMA response time and DMA transfer time, I would recommend to use 40 cycles core clock for worst case.&lt;/P&gt;&lt;P&gt;3&amp;gt; There no need to disable UART transmit, it just need polling UARTx_S1[TC] flag to make sure the UART transmit complete.&lt;/P&gt;&lt;P&gt;4&amp;gt; Then customer can start to modify DMA BCR value.&lt;/P&gt;&lt;P&gt;That will make sure no data will be omitted during DMA transfer, while it add some delay time for current UART transmit finished.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Wish it helps.&lt;BR /&gt;best regards &lt;BR /&gt;Ma Hui&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Nov 2014 06:58:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Safe-correct-way-to-pause-DMA-modify-BCR-count-and-resume/m-p/362217#M18474</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2014-11-26T06:58:41Z</dc:date>
    </item>
  </channel>
</rss>

