<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Serial DMA</title>
		<link>http://forums.leaflabs.com/topic.php?id=9752</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:26:11 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=9752" rel="self" type="application/rss+xml" />

		<item>
			<title>jpopadic on "Serial DMA"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9752#post-21429</link>
			<pubDate>Mon, 03 Dec 2012 11:56:07 +0000</pubDate>
			<dc:creator>jpopadic</dc:creator>
			<guid isPermaLink="false">21429@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;In my case, it's channel 3 (I'm interested in Rx on USART3), so I was OK from the start (the IRQ was coming through fine, just borked data).  USART_DMA_DEV and USART_RX_DMA_CHANNEL are defined at the top of my file to be DMA1 and DMA_CH3, respectively, so no real change there.&#60;/p&#62;
&#60;p&#62;Swapping DMA_SIZE_8BITS for DMA_SIZE_32BITS on the source side did the trick.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Serial DMA"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9752#post-21427</link>
			<pubDate>Mon, 03 Dec 2012 10:42:04 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">21427@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;jpopadic - Rapid detective work, and thank you for posting a solution.&#60;/p&#62;
&#60;p&#62;However, my reading of that thread, and especially this, the final post: &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1719#post-10670&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1719#post-10670&#60;/a&#62;&#60;br /&#62;
is that the transfer can be 8bits, but the important parameter was the DMA channel, which needed to be &#34;DMA1, DMA_CH4&#34;&#60;/p&#62;
&#60;p&#62;I notice that the DMA channel in your posted code has changed from &#34;DMA1, DMA_CH3&#34;, which, if I've understood that other thread would not work, to &#34;USART_DMA_DEV, USART_RX_DMA_CHANNEL&#34;. What are the values for these?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jpopadic on "Serial DMA"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9752#post-21425</link>
			<pubDate>Mon, 03 Dec 2012 09:25:58 +0000</pubDate>
			<dc:creator>jpopadic</dc:creator>
			<guid isPermaLink="false">21425@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Solved my problem myself.  Here's the solution for anyone who cares :-)&#60;/p&#62;
&#60;p&#62;It looks like the USART needs to be accessed as 16- or 32- bits (&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1719#post-10654&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1719#post-10654&#60;/a&#62;)&#60;/p&#62;
&#60;p&#62;Changing the DMA setup to the following makes everything work:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;dma_setup_transfer(
    USART_DMA_DEV,
    USART_RX_DMA_CHANNEL,
    &#38;amp;USART_DEV-&#38;gt;regs-&#38;gt;DR, DMA_SIZE_32BITS,
    rx_buf,               DMA_SIZE_8BITS,
    (DMA_MINC_MODE &#124; DMA_CIRC_MODE &#124; DMA_TRNS_CMPLT));&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>jpopadic on "Serial DMA"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9752#post-21422</link>
			<pubDate>Mon, 03 Dec 2012 07:37:29 +0000</pubDate>
			<dc:creator>jpopadic</dc:creator>
			<guid isPermaLink="false">21422@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Replying to myself...&#60;/p&#62;
&#60;p&#62;It looks like the current revision of the example (&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/examples/test-usart-dma.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/examples/test-usart-dma.cpp&#60;/a&#62;) has been updated to use a new API, that isn't in the latest IDE installer.&#60;/p&#62;
&#60;p&#62;A peek at an earlier revision (&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/b8f61070b0be0dcd539b6563c5820719d841412f/examples/test-usart-dma.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/b8f61070b0be0dcd539b6563c5820719d841412f/examples/test-usart-dma.cpp&#60;/a&#62;) is a lot more illuminating.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jpopadic on "Serial DMA"</title>
			<link>http://forums.leaflabs.com/topic.php?id=9752#post-21419</link>
			<pubDate>Mon, 03 Dec 2012 06:26:29 +0000</pubDate>
			<dc:creator>jpopadic</dc:creator>
			<guid isPermaLink="false">21419@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm trying to use DMA with USART3 to grab some incoming serial data and am having some problems.  The interrupt is firing too quickly (chars sent way below TRANSFER_SIZE) and the data isn't written to the right spot (seeing a stack of zeros).&#60;/p&#62;
&#60;p&#62;The libmaple example here (&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/examples/test-usart-dma.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/examples/test-usart-dma.cpp&#60;/a&#62;) is woefully out of date.  Does anyone have a better example?&#60;/p&#62;
&#60;p&#62;My (truncated) code (v0.0.12):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;dma.h&#38;gt;

#define TRANSFER_SIZE 16

char bytesReceived[TRANSFER_SIZE];
volatile bool dataReady = false;

void DMAEvent(){
  dma_irq_cause event = dma_get_irq_cause(DMA1, DMA_CH3);
  switch(event) {
    case DMA_TRANSFER_COMPLETE:
      dma_disable(DMA1, DMA_CH3);
      SerialUSB.println(&#38;quot;done.&#38;quot;);
      dataReady = true;
      break;
  }
}

void setup() {
  dataReady = false;

  Serial3.begin(9600);

  USART3-&#38;gt;regs-&#38;gt;CR3 = USART_CR3_DMAR;   // set DMA request on Rx bit
  dma_init(DMA1);
  dma_setup_transfer(
    DMA1,
    DMA_CH3,
    &#38;amp;USART3-&#38;gt;regs-&#38;gt;DR,
    DMA_SIZE_8BITS,
    bytesReceived,
    DMA_SIZE_8BITS,
    (DMA_MINC_MODE &#124; DMA_CIRC_MODE &#124; DMA_FROM_MEM &#124; DMA_TRNS_CMPLT));
  dma_attach_interrupt(DMA1, DMA_CH3, DMAEvent);
  dma_set_priority(DMA1, DMA_CH3, DMA_PRIORITY_VERY_HIGH);
  dma_set_num_transfers(DMA1, DMA_CH3, TRANSFER_SIZE);
  dma_enable(DMA1, DMA_CH3);
}

void loop() {
  if(dataReady)
  {
    SerialUSB.println(&#38;quot;read it back...&#38;quot;);
    dataReady = false;
    for(int i = 0; i &#38;lt; TRANSFER_SIZE; ++i)
    {
      SerialUSB.print(bytesReceived[i]);
    }
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;John
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
