<?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: [rfc] proposed: new DMA interface</title>
		<link>http://forums.leaflabs.com/topic.php?id=1882</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:06: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=1882" rel="self" type="application/rss+xml" />

		<item>
			<title>rogerclark on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-105676</link>
			<pubDate>Sat, 14 Mar 2015 17:22:02 +0000</pubDate>
			<dc:creator>rogerclark</dc:creator>
			<guid isPermaLink="false">105676@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Does anyone have any examples of how to use the new Tube based dma to write to a peripheral ?&#60;/p&#62;
&#60;p&#62;Its unclear whether the older dma stuff still works, i.e the stuff listed as __deprecated
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11343</link>
			<pubDate>Thu, 21 Jun 2012 17:33:28 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11343@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;By the way, the USART example does work on STM32F2. These were the only changes required:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/e0a2e9a5ce60e348cbff88069c5063a2e34f79e6&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/e0a2e9a5ce60e348cbff88069c5063a2e34f79e6&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;With that patch, the same program works on F1 and F2 :).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11341</link>
			<pubDate>Thu, 21 Jun 2012 17:22:15 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11341@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666, ThomasB: Thanks for the feedback :). It does make me feel better to see that I'm not plunging ahead into the future without checking in with you all first.&#60;/p&#62;
&#60;p&#62;Since last post, I re-did things into a much simpler interface. You no longer have to specify the memory and peripheral addresses in a struct dma_tube_config. Just specify the source and destination addresses, and the library figures out which registers everything should live in. This also means you no longer need to think about MEM2MEM or FROM_MEM type flags; those get figured out for you.&#60;/p&#62;
&#60;p&#62;Here are some relevant commits, which have been pushed into the LeafLabs libmaple development branch. This is definitely not final yet, so any comments welcome.&#60;/p&#62;
&#60;p&#62;This introduces the new API:&#60;br /&#62;
&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/2026ef2c36b83521786da6ff711150fb8289d673&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/2026ef2c36b83521786da6ff711150fb8289d673&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Here's the working version of struct dma_tube_config and dma_tube_cfg():&#60;br /&#62;
&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/2026ef2c36b83521786da6ff711150fb8289d673/libmaple/include/libmaple/dma.h#L121&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/2026ef2c36b83521786da6ff711150fb8289d673/libmaple/include/libmaple/dma.h#L121&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Notice the additional error codes. There are a TON of gotchas when porting DMA code from STM32F1 to F2 and F4 targets (notably: only DMA2 does mem-to-mem, you must configure the new FIFO feature when PSIZE!=MSIZE). I tried to catch as many of them as I could, so you get a sensible error value instead of things just crashing.&#60;/p&#62;
&#60;p&#62;This commit ports the USART example to use the new API:&#60;br /&#62;
&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/8c718082124d7b7b95ffe4591a3b58f3f4601c85&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/8c718082124d7b7b95ffe4591a3b58f3f4601c85&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;This is the function used to set up the struct dma_tube_config:&#60;br /&#62;
&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/8c718082124d7b7b95ffe4591a3b58f3f4601c85/examples/test-usart-dma.cpp#L80&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/8c718082124d7b7b95ffe4591a3b58f3f4601c85/examples/test-usart-dma.cpp#L80&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;(It uses a &#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/13a0db8f74549ca1d3bda4a167e11ccff4e297af&#34;&#62;new HardwareSerial feature&#60;/a&#62; that gets the underlying &#60;code&#62;usart_dev&#60;/code&#62;).&#60;/p&#62;
&#60;p&#62;I think the result is a pretty nice interface. It could use a lot more testing, though, so if anyone wants to try it out, I'd be grateful.&#60;/p&#62;
&#60;p&#62;robodude666:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
*cough* Using a struct to hold config data? I think that was proposed before. *cough*&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes, I smiled and thought of you when I decided to go that route. Hopefully you'll agree that the latest incarnation of the configuration struct does manage to be a little nicer than the ST libraries' take on the situation.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Liking the changes I'm seeing so far. dma_tube_config makes it really easy to pass different configurations so you can repurpose a DMA controller between SPI/ADC/USART, etc. functions in your program.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Cool, glad it seems useful.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Asserts are always enabled, or is there a way to disable them? I don't remember entirely, but do asserts on Maple cause the LED to blink or do they output a msg to a debug usart... or both?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;See &#60;a href=&#34;http://leaflabs.com/docs/lang/api/assert.html&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/assert.html&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If you want to disable asserts globally, you can add -DDEBUG_LEVEL=DEBUG_NONE to your CFLAGS. Command-line only, of course. I've been thinking about a clean way to mix Make into the IDE for a while now (where by &#34;clean&#34;, I mean &#34;invisible unless you specifically look for it&#34;, so as not to confuse beginners), but haven't come up with anything convincing yet.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ThomasB on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11303</link>
			<pubDate>Sun, 17 Jun 2012 12:47:01 +0000</pubDate>
			<dc:creator>ThomasB</dc:creator>
			<guid isPermaLink="false">11303@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@mbolivar&#60;br /&#62;
Looks like good work :)&#60;br /&#62;
Can't say more at the moment, because I've no time to test/work with it.&#60;br /&#62;
So this post is only intended to say: You're not speaking with yourself  ;)&#60;br /&#62;
(and.. there are people out there who appreciate what you're doing)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11302</link>
			<pubDate>Sun, 17 Jun 2012 12:22:30 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">11302@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;*cough* Using a struct to hold config data? I think that was proposed before. *cough*&#60;/p&#62;
&#60;p&#62;Liking the changes I'm seeing so far. &#60;code&#62;dma_tube_config&#60;/code&#62; makes it really easy to pass different configurations so you can repurpose a DMA controller between SPI/ADC/USART, etc. functions in your program.&#60;/p&#62;
&#60;p&#62;Asserts are always enabled, or is there a way to disable them? I don't remember entirely, but do asserts on Maple cause the LED to blink or do they output a msg to a debug usart... or both?&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11213</link>
			<pubDate>Mon, 11 Jun 2012 14:02:19 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11213@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Another update to test-usart-dma.cpp (he said to himself):&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/mbolivar/libmaple/commit/6a719a860d69a8ee24c491a21232db10fcc42d8e&#34; rel=&#34;nofollow&#34;&#62;https://github.com/mbolivar/libmaple/commit/6a719a860d69a8ee24c491a21232db10fcc42d8e&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;This illustrates another improvement that &#60;code&#62;dma_tube_cfg()&#60;/code&#62; has over &#60;code&#62;dma_setup_xfer()&#60;/code&#62;: &#60;code&#62;dma_tube_cfg()&#60;/code&#62; detects when the configuration you specify is impossible to satisfy, and returns an error code (or just &#60;code&#62;DMA_TUBE_CFG_SUCCESS (=0)&#60;/code&#62; if everything worked).&#60;/p&#62;
&#60;p&#62;This lets you check that you did things correctly. There have been a few threads on this forum that went something like this:&#60;/p&#62;
&#60;p&#62;&#34;This DMA code doesn't work!&#34;&#60;br /&#62;
&#34;You didn't pick the right channel.&#34;&#60;br /&#62;
&#34;Oh, thanks.&#34;&#60;/p&#62;
&#60;p&#62;The new function tries harder to explain what went wrong. Existing error codes:&#60;/p&#62;
&#60;p&#62;- &#60;code&#62;DMA_TUBE_CFG_ECOMPAT&#60;/code&#62;: tube is incompatible with configuration (covers the &#34;wrong channel&#34; error)&#60;br /&#62;
- &#60;code&#62;DMA_TUBE_CFG_ENDATA&#60;/code&#62;: memory and peripheral sizes are incompatible with number of data to transfer (the new DMA controllers have stricter alignment requirements, so detecting this error is going to help you port from F1 in some cases)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11212</link>
			<pubDate>Mon, 11 Jun 2012 13:52:59 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11212@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;In hopes that working code will drive some feedback, I've pushed some updates/fixes to the aforementioned branch to get things working on Maple. I've also updated examples/test-usart-dma.cpp to use the new API. Here's the patch; as you can see, the changes are pretty straightforward:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/mbolivar/libmaple/commit/25863c25761690631bfe30ffc0b6cd65f69378ad&#34; rel=&#34;nofollow&#34;&#62;https://github.com/mbolivar/libmaple/commit/25863c25761690631bfe30ffc0b6cd65f69378ad&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I've left line comments for that commit on GitHub which explain the rationale behind the changes in detail; click the above link to read them.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11149</link>
			<pubDate>Thu, 07 Jun 2012 23:47:38 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11149@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Some more details (with edits):&#60;/p&#62;
&#60;p&#62;The idea for how you write code that works on F1 and F2/F4 is basically like this (with SPI RX chosen as the basis for an example, though this isn't working code):&#60;/p&#62;
&#60;p&#62;1. Pick a &#60;code&#62;dma_dev* dma&#60;/code&#62;, along with &#60;code&#62;dma_channel dma_ch&#60;/code&#62; to use on F1, and &#60;code&#62;dma_stream dma_st&#60;/code&#62; on F2/F4.&#60;br /&#62;
2. Pick the &#60;code&#62;dma_request_src&#60;/code&#62; that corresponds to the DMA request source you want (so e.g. &#60;code&#62;DMA_REQ_SRC_SPI1_RX&#60;/code&#62;). (Most of the portability magic is in the bit encodings used for &#60;code&#62;dma_request_src&#60;/code&#62; enumerator values).&#60;br /&#62;
3. Initialize a &#60;code&#62;struct dma_tube_config&#60;/code&#62; like so:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;dma_tube_config my_tube_cfg = {
    .tube_per_addr = &#38;amp;SPI1_BASE-&#38;gt;DR,
    .tube_per_size = DMA_SIZE_8BITS,
    .tube_mem_addr = address_of_your_buffer,
    .tube_mem_size = DMA_SIZE_8BITS,
    .tube_nr_xfers = sizeof(your_buffer),
    .tube_mode = DMA_MINC_MODE &#124; DMA_TRNS_ERR &#124; DMA_TRNS_CMPLT &#124; etc.,
    .tube_req_src = DMA_REQ_SRC_SPI1_RX,
    .series_data = 0,
};&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;4. Use conditional compilation, &#60;code&#62;extern&#60;/code&#62;, etc. so that &#60;code&#62;dma_tube tube&#60;/code&#62; is &#60;code&#62;dma_ch&#60;/code&#62; on F1 targets, and &#60;code&#62;dma_st&#60;/code&#62; on F2/F4 targets.&#60;/p&#62;
&#60;p&#62;5. Call &#60;code&#62;dma_tube_cfg(dma, tube, &#38;amp;my_tube_cfg)&#60;/code&#62;, perform any other desired configuration as usual, then call &#60;code&#62;dma_enable(dev, tube)&#60;/code&#62; to start things off. (You of course also have to configure &#60;code&#62;SPI1&#60;/code&#62; to enable DMA RX requests, etc.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "[rfc] proposed: new DMA interface"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1882#post-11148</link>
			<pubDate>Thu, 07 Jun 2012 23:30:34 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11148@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#60;strong&#62;Update June 21 2012: This initial interface revamp was later changed -- see &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1882#post-11341&#34;&#62;below&#60;/a&#62;&#60;/strong&#62;&#60;/p&#62;
&#60;p&#62;Hey all,&#60;/p&#62;
&#60;p&#62;The DMA peripherals on STM32F2/F4 are incompatible with STM32F1. I came up with a new API that should roughly work with both, and I'd love some feedback on it before I take it any further, as it's a fairly radical departure from the past (don't worry, the old functions are still there on F1, so old code will continue to work on existing boards).&#60;/p&#62;
&#60;p&#62;The patches are currently here, rebased on top of the current LeafLabs libmaple dev branch:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/mbolivar/libmaple/tree/series-of-tubes/&#34; rel=&#34;nofollow&#34;&#62;https://github.com/mbolivar/libmaple/tree/series-of-tubes/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The main commit which introduces the new API is here. What's new is (hopefully) thoroughly explained in the commit message and in comments that are part of the patch:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/mbolivar/libmaple/commit/fba31701d9b16a15f0e7dde01622ef487db31a55&#34; rel=&#34;nofollow&#34;&#62;https://github.com/mbolivar/libmaple/commit/fba31701d9b16a15f0e7dde01622ef487db31a55&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;There are still some things that just aren't portable between F1 and F2/F4, but they're carefully segregated into what a &#60;code&#62;dma_tube&#60;/code&#62; is, and the data structure (&#60;code&#62;struct dma_tube_config&#60;/code&#62;) that's passed to a new DMA transfer setup function, &#60;code&#62;dma_tube_cfg()&#60;/code&#62;. That way, you can keep parallel &#60;code&#62;dma_tube_config&#60;/code&#62;s around, one for each series you need to support, so the same code will work with both kinds of DMA controller. (If you're lucky or are doing something simple, a single &#60;code&#62;struct dma_tube_config&#60;/code&#62; will often suffice on both series.) &#60;code&#62;dma_tube_cfg()&#60;/code&#62; is intended to replace &#60;code&#62;dma_setup_xfer()&#60;/code&#62;.&#60;/p&#62;
&#60;p&#62;The portable, common interface is in libmaple/include/libmaple/dma.h (so it'll be included as &#60;code&#62;&#38;lt;libmaple/dma.h&#38;gt;&#60;/code&#62;; this is part of a larger change we're introducing -- again, don't worry, you can still &#60;code&#62;#include &#38;quot;dma.h&#38;quot;&#60;/code&#62; for now). It should feel very familiar to you; the only real difference is the configuration procedure described above. The nonportable bits live under libmaple/stm32f1 and libmaple/stm32f2. So F1 routines live in libmaple/stm32f1/dma.c, and the F1 series DMA header &#60;code&#62;&#38;lt;series/dma.h&#38;gt;&#60;/code&#62; lives in libmaple/stm32f1/include/series/dma.h (the series headers are included by &#60;code&#62;&#38;lt;libmaple/dma.h&#38;gt;&#60;/code&#62; to fill in the blanks on what the MCU series supports). Similarly for F2.&#60;/p&#62;
&#60;p&#62;Please let me know what you think about the new API. I'd really, especially love feedback if you've got experience with STM32 series outside of F1, F2, F4. I really want to get this one right, so we don't have to keep changing the interface every time we want to add a new family of MCUs.&#60;/p&#62;
&#60;p&#62;edit: fixed some typos in the commit message and force-pushed, updated link to relevant commit&#60;br /&#62;
edits 2/3: added some more information
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
