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

		<item>
			<title>robodude666 on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25910</link>
			<pubDate>Sun, 12 May 2013 14:43:53 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">25910@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Last I remember, accessing onboard FLASH isn't that slow. If you mean external SPI flash, I don't have any working chips anymore. Burnt the last one I had.&#60;/p&#62;
&#60;p&#62;What do you mean by &#34;reading one 32 bit word into a core register&#34; ?&#60;/p&#62;
&#60;p&#62;FSMC supports up to 16-bit wide SRAM modules. So that would just be the time it takes to read two addresses (manually, since DMA won't give  you at benefits here), anding them together and writing a register.&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25909</link>
			<pubDate>Sun, 12 May 2013 14:18:45 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">25909@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Also timings of reading one 32 bit word into a core register
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25908</link>
			<pubDate>Sun, 12 May 2013 14:17:07 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">25908@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Where is FLASH to SRAM in that comparison?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25907</link>
			<pubDate>Sun, 12 May 2013 13:31:15 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">25907@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;More data!&#60;/p&#62;
&#60;p&#62;FSMC  to FSMC DMA  transfers are also possible (what a surprise?).&#60;/p&#62;
&#60;p&#62;Same 1920 x 16bit transfer took 640 uS with a manual 16x unrolled loop. That's a transfer rate of 3.0 MHz.&#60;br /&#62;
With a DMA  controller it comes to about 620 uS, or a transfer rate of 3.09 MHz.&#60;/p&#62;
&#60;p&#62;This is a setup of reading from one FSMC address and writing to another. This effectively exercises both reading and writing to FSMC-controlled external memory. Based on the analysis above, reading is clearly slower than writing which explains why this type of  a transfer is just slightly slower than FSMC to SRAM buffer read (which came  in at 3.95 MHz).&#60;/p&#62;
&#60;p&#62;I currently don't have any SPI devices I could use to try FSMC to SPI transfers.. &#60;/p&#62;
&#60;p&#62;So, to summarize so far, with a 16-bit wide payload:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;SRAM to SRAM = 11.63 MHz
SRAM to FSMC = 5.9 MHz
FSMC to SRAM = 3.95 MHz
FSMC to FSMC = 3.0 MHz

Keywords:
SRAM = onboard SRAM
FSMC = external SRAM&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;To  convert to Mbps, multiple transfer rate by payload width.&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25906</link>
			<pubDate>Sun, 12 May 2013 12:27:43 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">25906@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yup.&#60;/p&#62;
&#60;p&#62;I can confirm that you're able to use the FSMC address as your source/destination in a DMA transfer.&#60;/p&#62;
&#60;p&#62;I was able to transfer 1,920 16-bit wide values from FSMC into a buffer in 485 microseconds. That's a read rate of 3.95 MHz (per 16bit value).&#60;br /&#62;
Without the DMA transfer, reading the address manually into your buffer (loop not unrolled; just one at a time as worst case) takes 1070 microseconds, which is a read rate of 1.79 MHz. That's a 220% performance gain :).&#60;/p&#62;
&#60;p&#62;For speed reference.... Doing the same 1,920 16-bit value transfer between two SRAM (on the STM32) buffers takes 670 uS without DMA and 165 uS with DMA.&#60;/p&#62;
&#60;p&#62;FSMC memory access via the DMA controller certainly gains you some performance, but it's not nearly as fast as the onboard memory. The larger your transfer size is, the faster it'll get transfered but up to a point. A FSMC to SRAM DMA transfer of 240 16-bit values took 65 uS. 1920 is 8x the size and only took 485 instead of the expected 520. Doing 3072 transfers took 770 uS. With a buffer that's 1.6x larger we'd expect a transfer time of (485*1.6)=776... Not much of  a savings. So it's clearly not worth it to allocate a giant buffer on the STM32 as there's very little performance gain after some point. I'll stick to 1920 for my application, after I finish with these benchmarks :).&#60;/p&#62;
&#60;p&#62;I'm going  to look into write speeds next. Followed by FSMC to FSMC transfers. But first, coffee.&#60;/p&#62;
&#60;p&#62;EDIT:&#60;/p&#62;
&#60;p&#62;The results are in, and they're quite surprising. Manually writing 1920 16-bit values (not unrolled) to FSMC took 830 uS, or a write rate of 2.3 MHz. That's quite a bit slower than the 16x unrolled loop the FSMC test demo uses, however... Doing it with DMA took on 325 uS or a write rate of 5.9 MHz. That's just a little slower than the unrolled loop... However the unrolled loop demo just wrote garbage values that weren't very useful. If you also unroll your manually write loop it also goes down to 325 uS to manually write 16 values at a time in a loop.&#60;/p&#62;
&#60;p&#62;EDIT2:&#60;/p&#62;
&#60;p&#62;Interesting! I went back and edited the STM32 SRAM to FSMC benchmark program and unrolled the manual read loop to 16x. Performance is actually FASTER than DMA for my 1920 values. Comes out to  445 (unrolled) vs 485 (DMA) uS.&#60;/p&#62;
&#60;p&#62;But, there's something to keep in mind. While manually doing the transfers you're taking away CPU time from whatever your application is. DMA transfers happen behind the  scenes, and supposedly have only a 1% CPU usage. So, in that 480 microseconds  you're waiting for the DMA transfer to read/write to FSMC, you can be processing user input, filtering analog data, etc. Which still makes it worthwhile to implement if performance is a high priority.&#60;/p&#62;
&#60;p&#62;For my particular application, I will be using the external SRAM to buffer frames for my LCD and then use DMA transfers to get data from the external SRAM, to an internal buffer, and dump it to GPIO. I'm considering possibly going with FSMC -&#38;gt; SPI directly instead of getting a parallel LCD.&#60;/p&#62;
&#60;p&#62;Some other cool things you could do is maybe have FLASH/EEROM chip and use a DMA transfer to load data into SRAM on bootup :)! Or, if we ever get SDIO working buffer stuff off of an SD card.&#60;/p&#62;
&#60;p&#62;Next I'm going to look into transferring data between parts of external FSMC-controlled memory. And then publish everything on gist/github.&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25885</link>
			<pubDate>Sun, 12 May 2013 10:05:57 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">25885@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;p&#62;Excellent point! I forgot completely that FSMC-accessed RAM is designed to appear as a regular memory address. In which case, you should be able to do a regular memory-to-memory transfer and the STM32 will figure out everything needed to get that done.&#60;/p&#62;
&#60;p&#62;I'll try it out, and report back!&#60;/p&#62;
&#60;p&#62;EDIT: Oh brother! I forgot libmaple transitioned over to &#34;tubes&#34; while I was dealing with life. Time to read some source code comments! This might take longer than I thought.&#60;/p&#62;
&#60;p&#62;EDIT2:&#60;/p&#62;
&#60;p&#62;While trying to figure out how to use the new DMA tubes I ran across this in the libmaple source code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;enum dma_atype _dma_addr_type(__io void *addr) {
    switch (stm32_block_purpose((void*)addr)) {
    /* Notice we&#38;#39;re treating the code block as memory here.  That&#38;#39;s
     * correct for addresses in Flash and in [0x0, 0x7FFFFFF]
     * (provided that those addresses are aliased to Flash, SRAM, or
     * FSMC, depending on BOOT[01] and possibly SYSCFG_MEMRMP). It&#38;#39;s
     * not correct for other addresses in the code block, but those
     * will (hopefully) just fail-fast with transfer or bus errors. If
     * lots of people get confused, it might be worth being more
     * careful here. */
    case STM32_BLOCK_CODE:      /* Fall through */
    case STM32_BLOCK_SRAM:      /* ... */
    case STM32_BLOCK_FSMC_1_2:  /* ... */
    case STM32_BLOCK_FSMC_3_4:
        return DMA_ATYPE_MEM;
    case STM32_BLOCK_PERIPH:
        return DMA_ATYPE_PER;
    case STM32_BLOCK_FSMC_REG:        /* Fall through */
        /* Is this right? I can&#38;#39;t think of a reason to DMA into or out
         * of the FSMC registers. [mbolivar]  */
    case STM32_BLOCK_UNUSED:          /* ... */
    case STM32_BLOCK_CORTEX_INTERNAL: /* ... */
        return DMA_ATYPE_OTHER;
    default:
        ASSERT(0);              /* Can&#38;#39;t happen */
        return DMA_ATYPE_OTHER;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;SRAM and FSMC Banks 1 - 4 are all treated as a memory transfer. Looking good towards being able to do a simple memory-to-memory transfer so far.&#60;/p&#62;
&#60;p&#62;Thanks,&#60;br /&#62;
-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25864</link>
			<pubDate>Sun, 12 May 2013 07:10:29 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">25864@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666 - I don't have a Maple Native, so I have never tried accessing the FSMC with DMA.&#60;/p&#62;
&#60;p&#62;However, the memory on the STM32's FSMC is memory from the processors perspective. The FSMC's job is to make the external chips behave like memory from the processors perspective. That memory has an address and the FSMC has a 32-bit wide buffer to make read and write transactions look like normal memory accesses to the processor. So I would expect memory on the DSMC to look like memory to the DMA controller too.&#60;/p&#62;
&#60;p&#62;Looking at R0008 ...&#60;/p&#62;
&#60;p&#62;section 13.2 &#34;DMA main features&#34; describes the Direct memory access (DMA) features:&#60;br /&#62;
&#60;em&#62;● Memory-to-memory transfer&#60;br /&#62;
● Peripheral-to-memory and memory-to-peripheral, and peripheral-to-peripheral transfers&#60;br /&#62;
● Access to Flash, SRAM, APB1, APB2 and AHB peripherals as source and destination&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;The memory on the FSMC is accessed across the AHB&#60;/p&#62;
&#60;p&#62;Further, in section 21.3 &#34;AHB interface&#34; it describes the errors that the FSMC can raise, and it says:&#60;br /&#62;
&#60;em&#62;The effect of this AHB error depends on the AHB master which has attempted the R/W access:&#60;br /&#62;
● If it is the Cortex™-M3 CPU, a hard fault interrupt is generated&#60;br /&#62;
● If is a DMA, a DMA transfer error is generated and the corresponding DMA channel is automatically disabled.&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;I interpret that as saying the FSMC makes external memory behave the same for both the processor and DMA controllers. &#60;/p&#62;
&#60;p&#62;Hence, I think FSMC memory can be used in the same way as STM32's internal RAM. I think you could test this. Set up a DMA transfer between memory blocks or to/from a peripheral using internal RAM, then run the same transfer but to memory in the FSMC address range.&#60;/p&#62;
&#60;p&#62;FSMC-attached memory is only 8 or 16 bits wide. The FSMC peripheral manual does seem to suggest that access to the AHB bus might be blocked while a 32 bit transfer is assembled from multiple FSMC-external-memory transfers. You might want to avoid that by doing one or two byte transfers.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "FSMC + DMA?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=11533#post-25863</link>
			<pubDate>Sun, 12 May 2013 01:40:26 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">25863@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Howdy,&#60;/p&#62;
&#60;p&#62;Finally decided to try out the Maple Native's FSMC test example, and am pretty impressed by the performance... Write access is only at 6.49 MHz, but that's for writing 16-bit words which comes out to 12.37 MBps (512K x 16bit values in 80,758 microseconds); not too bad. Reading the entire 512K locations, one value at a time takes 255ms.... which is pretty slow.&#60;/p&#62;
&#60;p&#62;So, I was wondering can you take advantage of the DMA channels to read/write to/from the FSMC controller? I read through the RM0008 reference manual, and didn't see FSMC listed as a possible DMA option.&#60;/p&#62;
&#60;p&#62;Unrelated - kind of - is it possible to use a DMA channel to transfer data two different areas of a single FSMC bank without  first buffering the data on the STM32's SRAM. And, is it also possible to transfer data directly between FSMC and a parallel bus and FSMC and an SPI bus?&#60;/p&#62;
&#60;p&#62;Thanks!,&#60;br /&#62;
-robodude666
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
