<?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: K20 UART RX DMA - with a circular buffer in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430481#M24865</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ma Hui&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the SSIZE set to 001(16-bits), how could I control the data receive between big-endian and little-endian? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;&lt;P&gt;Jin Xin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Jun 2015 13:29:37 GMT</pubDate>
    <dc:creator>jinxin_cn</dc:creator>
    <dc:date>2015-06-17T13:29:37Z</dc:date>
    <item>
      <title>K20 UART RX DMA - with a circular buffer</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430479#M24863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm building an application where I want to have a large RX buffer off UART1 on a K20D7.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've created a DMA transfer from UART1 using the configuration code below. The problem I see is determining whether there has been a buffer overflow. I'm also unclear on the exact operation of DMA_TCD0_DADDR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm thinking of DMA_TCD0_DADDR as a head pointer on a circular buffer. Does the DMA actually update the DADDR in a way that I can read from to determine where the next byte will be stored?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My approach is that I'll have a tail pointer to pull data off the buffer. If the tail and DADDR are the same, then nothing is in the buffer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only problem is when DADDR laps the tail pointer. As far as I can tell, there's no way for me to detect this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suggestions? This must be a relatively common style of serial port.. perhaps there's a better implementation approach?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;Rudy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#define baud 9600&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#define F_CPU 48000000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#define BAUD2DIV(baud)&amp;nbsp; (((F_CPU * 2) + ((baud) &amp;gt;&amp;gt; 1)) / (baud))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5em; font-size: 13.3333330154419px; font-family: 'courier new', courier;"&gt;#define RX_BUFFER_SIZE 1024&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;static volatile uint8_t rx_buffer[RX_BUFFER_SIZE] __attribute__((aligned(1024)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;int divisor = BAUD2DIV(baud);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;SIM_SCGC4 |= SIM_SCGC4_UART1_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;PORTC_PCR3 = PORT_PCR_PE_MASK | PORT_PCR_PS_MASK | PORT_PCR_PFE_MASK | PORT_PCR_MUX(3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;PORTC_PCR4 = PORT_PCR_DSE_MASK | PORT_PCR_SRE_MASK | PORT_PCR_MUX(3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; UART1_BDH = (divisor &amp;gt;&amp;gt; 13) &amp;amp; 0x1F;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; UART1_BDL = (divisor &amp;gt;&amp;gt; 5) &amp;amp; 0xFF;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; UART1_C4 = divisor &amp;amp; 0x1F;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; UART1_C1 = 0; // configures 8-bit, no parity&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; UART1_PFIFO = 0; // no fifo since we're setting up DMA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; // UART DMA RECEIVE CONFIGURATION&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; //enable DMA clocks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SIM_SCGC6 |= SIM_SCGC6_DMAMUX_MASK; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SIM_SCGC7 |= SIM_SCGC7_DMA_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMAMUX_CHCFG0 = 0; // disable the channel first&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; // config the dma channel&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_DSR_BCR0 |= DMA_DSR_BCR_DONE_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_CSR = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_CR = 0; // default control register&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_DCHPRI0 = 0; // DMA channel 0 priority default to 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_EEI = 0; // all error interrupts are cleared. might be needed if we're debugging..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; // now set up TCD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_SADDR = (uint32_t) &amp;amp;UART1_D; // reading from UART1 data register&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_SOFF = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_ATTR = DMA_ATTR_SMOD(0) | DMA_ATTR_SSIZE(0)&amp;nbsp;&amp;nbsp;&amp;nbsp; // source does not iterate - no modulo, source is a byte in size, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; | DMA_ATTR_DMOD(0) | DMA_ATTR_DSIZE(10); // destination is a byte, 1 kB of buffer space, address must align with a 1k boundary&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_NBYTES_MLNO = 1; // one byte is transferred each time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_SLAST = 0; // the source address never changes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_DADDR = (uint32_t) &amp;amp;rx_buffer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_DOFF = 1; // incoming byte increment by 1 through the rx_buffer, wrapping around at the 1k boundary&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_CITER_ELINKNO = 1; // single major loop. CITER and BITER must be initialized to the same value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_BITER_ELINKNO = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_TCD0_DLASTSGA = 0; // no adjustment to destination address... assuming that destination address has not been changed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; // enable the dma channel&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMA_ERQ |= DMA_ERQ_ERQ0_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; DMAMUX_CHCFG0 = DMAMUX_CHCFG_ENBL_MASK | 0x04; // sets channel 0 source to UART1 receive&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; UART1_C5 = UART_C5_RDMAS_MASK; // Now, when an character is received, as long as the receive interrupt is enabled, a DMA request will be sent.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; UART1_C2 = C2_ENABLE; // enable the UART&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; // setup the interrupts - now used for TX only...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; NVIC_SET_PRIORITY(IRQ_UART1_STATUS, IRQ_PRIORITY);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; NVIC_ENABLE_IRQ(IRQ_UART1_STATUS);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Apr 2015 23:52:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430479#M24863</guid>
      <dc:creator>rudymoore</dc:creator>
      <dc:date>2015-04-21T23:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: K20 UART RX DMA - with a circular buffer</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430480#M24864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Justin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I check your eDMA setting only use one major loop for one minor loop.&lt;/P&gt;&lt;P&gt;I would recommend you to use below eDMA setting, one major loop with more minor loop.&lt;/P&gt;&lt;P&gt;Each minor loop could transfer one byte from UART1 data to RX buffer.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DMA.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/49924i069AC9472CEECAF2/image-size/large?v=v2&amp;amp;px=999" role="button" title="DMA.png" alt="DMA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It could set one major loop with N(buffer byte size) minor loop, each UART receive will transfer one byte data to RX buffer.&lt;/P&gt;&lt;P&gt;Customer could read DMA_TCDn_BITER_ELINKNO [BITER] bits value to check how many bytes could be load into the RX buffer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW: I check below code with problem:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;DMA_TCD0_ATTR = DMA_ATTR_SMOD(0) | DMA_ATTR_SSIZE(0)&amp;nbsp;&amp;nbsp;&amp;nbsp; // source does not iterate - no modulo, source is a byte in size, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; | DMA_ATTR_DMOD(0) | &lt;/SPAN&gt;&lt;SPAN style="color: #ff0000;"&gt;DMA_ATTR_DSIZE(10)&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;; // destination is a byte, 1 kB of buffer space, address must align with a 1k boundary&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;The &lt;SPAN style="font-family: 'courier new', courier;"&gt;DMA_ATTR_DSIZE value also should be 0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Wish it helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&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>Thu, 30 Apr 2015 01:37:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430480#M24864</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2015-04-30T01:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: K20 UART RX DMA - with a circular buffer</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430481#M24865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ma Hui&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the SSIZE set to 001(16-bits), how could I control the data receive between big-endian and little-endian? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;&lt;P&gt;Jin Xin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 13:29:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430481#M24865</guid>
      <dc:creator>jinxin_cn</dc:creator>
      <dc:date>2015-06-17T13:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: K20 UART RX DMA - with a circular buffer</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430482#M24866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jin Xin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kinetis product only supports the little endian, although ARM Cortex M4 core support both big and little endian.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&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>Thu, 18 Jun 2015 03:13:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K20-UART-RX-DMA-with-a-circular-buffer/m-p/430482#M24866</guid>
      <dc:creator>Hui_Ma</dc:creator>
      <dc:date>2015-06-18T03:13:15Z</dc:date>
    </item>
  </channel>
</rss>

