<?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: DMA with SPI to read SD Card?</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279271#M10163</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I should have spelled that out in my question, rather than just tagging it.&amp;nbsp; I had a suspicion you may be referring to other hardware.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simple is good, but working would be better. :smileysad:&amp;nbsp; I'm really stumped on this, having tried just about everything.&amp;nbsp; I'll dig more into the DMAMUX stuff and see if the answer is hidden therein.&amp;nbsp; There are sections of the ref. man. that refer specifically to SPI via DMA, so I'm not just imagining it should work....I think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Oct 2013 21:19:10 GMT</pubDate>
    <dc:creator>ids</dc:creator>
    <dc:date>2013-10-15T21:19:10Z</dc:date>
    <item>
      <title>DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279267#M10159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am struggling with getting DMA to read data from an SPI channel, in particular, for an SD card.&lt;/P&gt;&lt;P&gt;Do I need to link two channels to get the SPI write before the SPI read?&lt;/P&gt;&lt;P&gt;Any code or suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 00:56:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279267#M10159</guid>
      <dc:creator>ids</dc:creator>
      <dc:date>2013-10-15T00:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279268#M10160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't have any particular experience using SPI for an SD card, but I will make two particular comments:&lt;/P&gt;&lt;P&gt;All SPI transactions are simultaneously a 'read' and a 'write'.&amp;nbsp; The only difference is what you 'keep'.&amp;nbsp; I think you will find that the DMA to 'empty' the RX-FIFO will 'naturally' come after the requests to fill the TX-FIFO since you can't have an RX-request until a TX-send has completed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Freescale DSPI 'DMA' is a 'little bit inconvenient'.&amp;nbsp; The loading of SPIx_PUSHR FIFO registers requires 32-bit writes, the top-half of which are SPI-controls.&amp;nbsp; Thus, if you want to DMA-out a 'block', you have to intersperse your data as the 'bottom byte or word' in these 32-bit words, meaning your data-block is 'non contiguous'.&amp;nbsp; This puts an 'extra step' in your data-block handling to interleave data &amp;amp; controls that MAY preclude any advantage you were hoping to gain from DMA, especially since I assume you would run SPI to SD at 'full hardware rate' (1/2 busclk), meaning each byte-out takes 16 bus-clocks, or probably only 32 CPU cycles.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I presently use SPI DMA to continually refresh a monochrome bitmap display.&amp;nbsp; It is write-only, so I ignore RX requests (and overruns therefrom).&amp;nbsp; And since the internal memory buffer is in a fixed location (specifically addressed at the top of RAM so I can use bit-banding access for individual pixels!), it is 'very little trouble' to work with using only the least-byte of the 32-bit words, with the rest pre-set for the proper SPI controls for each write.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Memory structure:&lt;/P&gt;&lt;P&gt;typedef union{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Byte/DWord duality, big-endian&lt;/P&gt;&lt;P&gt;&amp;nbsp; struct{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t lo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t mlo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t mhi;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t hi;&lt;/P&gt;&lt;P&gt;&amp;nbsp; } u8;&lt;/P&gt;&lt;P&gt;&amp;nbsp; struct {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t lo;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t hi;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }u16;&lt;/P&gt;&lt;P&gt;&amp;nbsp; uint32_t u32;&lt;/P&gt;&lt;P&gt;}u32_8_t;&lt;/P&gt;&lt;P&gt;#define Y_PITCH 132&lt;/P&gt;&lt;P&gt;typedef struct {&lt;/P&gt;&lt;P&gt;&amp;nbsp; u32_8_t&amp;nbsp;&amp;nbsp; OLED_CMDS[32];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Precede the actual dispaly RAM with room for commands to prefix the data&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp; In a contiguous block-write operation&lt;/P&gt;&lt;P&gt;&amp;nbsp; u32_8_t&amp;nbsp;&amp;nbsp; Display_RAM[Y_PITCH*8]; //Chip RAM is 132*8, only 128*8 is displayed&lt;/P&gt;&lt;P&gt;} OLED_RAM_Obj;&lt;/P&gt;&lt;P&gt;//OLED.Display_RAM[ ].u8.lo are the bytes for screen data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with this pre-set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t foo;&lt;/P&gt;&lt;P&gt; //Preset SPI-port-required upper bits of Command/Display RAM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(foo=32;foo&amp;gt;0;foo--)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Commands assert two CS, one of which is D/!C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OLED.OLED_CMDS[foo-1].u32 = SPI_PUSHR_PCS(3) | SPI_PUSHR_CTAS(0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(foo=Y_PITCH*8;foo&amp;gt;0;foo--)&amp;nbsp;&amp;nbsp;&amp;nbsp; //Data asserts just CS0, leaving D/!C high&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OLED.Display_RAM[foo-1].u32 = SPI_PUSHR_PCS(1) | SPI_PUSHR_CTAS(0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#pragma location=0x2000EF00&lt;/P&gt;&lt;P&gt;__no_init OLED_RAM_Obj OLED;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Pre-allocated fixed-space for Display RAM&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Necessary, in SRAM-U, to use bit-banding!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TX channel initialization:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void DMA_Init_Tx(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; // use dma to blast-out display contents!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM_SCGC6 |= SIM_SCGC6_DMAMUX_MASK;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM_SCGC7 |= SIM_SCGC7_DMA_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_ERQ = DMA_ERQ_ERQ2_MASK; //channel 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMAMUX_CHCFG2 = DMAMUX_CHCFG_ENBL_MASK | DMAMUX_CHCFG_SOURCE(DMA_SPI0_XMIT_CHAN) ; //Source 17 for SPI transmit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_SADDR = (uint32_t)&amp;amp;OLED.OLED_CMDS[32-OLED_cmd_cnt].u32; /* Set the Source Address */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Destination address */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_DADDR = (uint32_t)&amp;amp;SPI0_PUSHR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Source offset Dwords */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_SOFF = 0x04;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Source and Destination Modulo off, source and destination size 2 = 32 bits */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_ATTR = DMA_ATTR_SSIZE(2) | DMA_ATTR_DSIZE(2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Transfer 4 bytes (one aligned Dword) per transaction */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_NBYTES_MLNO = 0x04;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Adjust back to start needed */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_SLAST = -(4*(Y_PITCH*8 + OLED_cmd_cnt));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Destination offset disabled */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_DOFF = 0x00;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* No link channel to channel, 1 transaction */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_CITER_ELINKNO = DMA_CITER_ELINKNO_CITER(((Y_PITCH*8 + OLED_cmd_cnt)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* No adjustment to destination address */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_DLASTSGA = 0x00;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_BITER_ELINKNO = DMA_BITER_ELINKNO_BITER(((Y_PITCH*8 + OLED_cmd_cnt)));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then this is called regularly to start the DMA-block to refresh:&lt;/P&gt;&lt;P&gt;void OLED_Refresh(void)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //See that RAM contents get sent to the OLED display device&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt; //&amp;nbsp;&amp;nbsp; SPI0_MCR |= SPI_MCR_CLR_RXF_MASK;&amp;nbsp; //Make sure RX Fifo is empty for us!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //^^leave it full of garbage, there is just more to come (which we don't even offload)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI0_RSER = SPI_RSER_TFFF_RE_MASK | SPI_RSER_TFFF_DIRS_MASK; //Set SPI TX to make DMA requests&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_ERQ = DMA_ERQ_ERQ2_MASK; //channel 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA_TCD2_CSR = DMA_CSR_DREQ_MASK | DMA_CSR_START_MASK;&amp;nbsp; //One transfer at a time.&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 15:48:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279268#M10160</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2013-10-15T15:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279269#M10161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the detailed response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am confused about the PUSHR comment you make.&amp;nbsp; According to the "KL25 Sub-Family Reference Manual", rev 3, Sep 2012, sec'n 37.3, "the SPI has 8-bit registers" and then in 37.3.5 there is the definition of the SPI Data Register - is this not an 8-bit field to write your output to, and then later read the input back from?&lt;/P&gt;&lt;P&gt;The SPI impl in mbed has, for example, the following struct, which is all 8-bit as well:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/** SPI - Register Layout Typedef */&lt;/P&gt;&lt;P&gt;typedef struct {&lt;/P&gt;&lt;P&gt;&amp;nbsp; __IO uint8_t C1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&amp;lt; SPI control register 1, offset: 0x0 */&lt;/P&gt;&lt;P&gt;&amp;nbsp; __IO uint8_t C2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&amp;lt; SPI control register 2, offset: 0x1 */&lt;/P&gt;&lt;P&gt;&amp;nbsp; __IO uint8_t BR;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&amp;lt; SPI baud rate register, offset: 0x2 */&lt;/P&gt;&lt;P&gt;&amp;nbsp; __I&amp;nbsp; uint8_t S;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&amp;lt; SPI status register, offset: 0x3 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t RESERVED_0[1];&lt;/P&gt;&lt;P&gt;&amp;nbsp; __IO uint8_t D;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&amp;lt; SPI data register, offset: 0x5 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t RESERVED_1[1];&lt;/P&gt;&lt;P&gt;&amp;nbsp; __IO uint8_t M;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /**&amp;lt; SPI match register, offset: 0x7 */&lt;/P&gt;&lt;P&gt;} SPI_Type;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Their implementation for a write/read cycle is also all 8-bit:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int spi_master_write(spi_t *obj, int value) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wait tx buffer empty&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(!spi_writeable(obj));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; obj-&amp;gt;spi-&amp;gt;D = (value &amp;amp; 0xff);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wait rx buffer full&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!spi_readable(obj));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return obj-&amp;gt;spi-&amp;gt;D &amp;amp; 0xff;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have therefore setup the DMA to do 8-bit reads/writes.&amp;nbsp; My primary purpose is to read from the SPI and fill a buffer.&amp;nbsp; I prefix any DMA activity with appropriate commands to the SD card to prepare it for a read of a 512-byte block.&amp;nbsp; DMA wise I have tried a lot of things.&amp;nbsp; For example, a single DMA channel set to read, with Cycle Steal = 0, filled my buffer (512 bytes) very quickly but with all the same value.&amp;nbsp; I do have the SPI set up properly (as far as I can tell) - RXDMAE on, etc.&amp;nbsp; I tried linking two DMA channels, the other set to do writes to the SPI data register, Cycle Steal = 1 (single read/write at a time), ERQ enabled, etc, hoping writes would trigger reads and they would ping-pong back and forth with the SPRF/SPTEF flags signalling the appropriate DMA operation.&amp;nbsp; I've tried just about all permutations and combinations but cannot get it to work.&amp;nbsp; I've also tried adding the extra SPI write, as per ref.man 37.4.4.1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd post code, but have done it in so many ways, no snippet could reflect this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fwiw, using default mbed read/write functions is working, so I have a solid baseline from which to work.&amp;nbsp; Swapping the 512-byte block read to DMA is not working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see DMAMUX in your code snippet - maybe setting up the DMAMUX is what I am missing?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 19:06:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279269#M10161</guid>
      <dc:creator>ids</dc:creator>
      <dc:date>2013-10-15T19:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279270#M10162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My bad -- I didn't notice the 'L series' tag.&amp;nbsp; My stuff is all for the 'bigger parts', in particular this is K20 Rev 2 silicon, with the FIFO-enabled DSPI peripheral.&amp;nbsp; Sounds like the KL peripheral is 'much simpler', which isn't all bad!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 20:21:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279270#M10162</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2013-10-15T20:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279271#M10163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I should have spelled that out in my question, rather than just tagging it.&amp;nbsp; I had a suspicion you may be referring to other hardware.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simple is good, but working would be better. :smileysad:&amp;nbsp; I'm really stumped on this, having tried just about everything.&amp;nbsp; I'll dig more into the DMAMUX stuff and see if the answer is hidden therein.&amp;nbsp; There are sections of the ref. man. that refer specifically to SPI via DMA, so I'm not just imagining it should work....I think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 21:19:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279271#M10163</guid>
      <dc:creator>ids</dc:creator>
      <dc:date>2013-10-15T21:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279272#M10164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry I can't be of 'more direct' help.&amp;nbsp; Only thing I will mention -- as SPI master, you certainly only 'receive' as a result of a 'transmit', so you will certainly need something filling your 512 TXs, so presumably two DMA channels are indeed required, but I expect your SPI peripheral has individual RX and TX 'requests for service' so they should pace themselves once enabled!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 02:38:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279272#M10164</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2013-10-16T02:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279273#M10165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I actually had a long winded response ready to go, and as I was finishing up a detailed pseudo-code ver'n of what I've done, I read a bit more in the ref. manual that got me wondering about my impl, so I'll delay until I try a few more things.&amp;nbsp; I do understand the bit about an SPI Master having to write in order to read.&amp;nbsp; I'm just not sure how much of this a DMA transfer might automate.&amp;nbsp; It's probably safest not to assume too much, and run two channels, one to write (essentially garbage), the other to read.&amp;nbsp; I have tried a few things with the DMAMUX, scanned mbed source to see if I may conflict with any internals, etc.&amp;nbsp; Still no luck, however. :smileysad:&amp;nbsp; I much prefer a world in which someone else has done the hard part, and where I can just re-use the code.&amp;nbsp; Guess I'm stuck doing the legwork on this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2013 18:08:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279273#M10165</guid>
      <dc:creator>ids</dc:creator>
      <dc:date>2013-10-17T18:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279274#M10166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After much too much time on this, I have finally succeeded.&amp;nbsp; If anyone wants code, just ask.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Oct 2013 02:18:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279274#M10166</guid>
      <dc:creator>ids</dc:creator>
      <dc:date>2013-10-19T02:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279275#M10167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Steve,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be interested to see the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How is the performance of DMA SPI?&amp;nbsp; Did you consider, or try, interrupt-driven SPI first?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm curious if it is a significant improvement.&amp;nbsp; I understand there is an errata on the Kinetis SPI that means you can't run it at full speed, if I recall correctly, but I imagine that DMA reduces CPU consumption quite a bit over interrupt-driven SPI, at least for medium and large block sizes.&amp;nbsp; (For small transfers of 1 to 20 bytes or so, perhaps the overhead of the DMA setup would actually reduce performance over interrupt-driven mode, but it seems fairly low-overhead to me.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Oct 2013 22:39:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279275#M10167</guid>
      <dc:creator>colin</dc:creator>
      <dc:date>2013-10-19T22:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Re: DMA with SPI to read SD Card?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279276#M10168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Code below.&amp;nbsp; It should be noted that while I do have DMA and SPI working together, I have not been able to apply this to an SD card.&amp;nbsp; It's a great mystery to me at this point, and I'm throwing in the towel.&amp;nbsp; I have no sense of performance difference at this time, sorry.&amp;nbsp; I would assume that it would be faster than a busy loop checking the SPI Read Buffer Full and Transmit Buffer Empty flags and acting appropriately.&amp;nbsp; And it should reduce the CPU burden as well, allowing your code to carry on while this happens in the background.&amp;nbsp; My intent was to target the 512 byte block transfers from the SD card, filling a buffer with audio samples, in which case my code really has no need to wait for, or be notified of, completion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt; font-family: terminal, monaco;"&gt;SPI_Type* spi_peripherals[] = SPI_BASES;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;/**&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* Run a DMA Test using SPI.&amp;nbsp; Attempts to read and write a fixed number of bytes, to/from provided buffers.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;*&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* @param dmaReadCh The DMA channel to configure for the SPI READ operation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* @param dmaWriteCh The DMA channel to configure for the SPI WRITE operation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* @param srcBuffer Data buffer of values to write out to SPI&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* @param destBuffer Data buffer in which to store values read from the SPI&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* @param length The length of both buffers&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;* @param spiCh The SPI channel to use, 0 or 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;void dma_test(const int dmaReadCh, const int dmaWriteCh, uint8_t *srcBuffer, uint8_t *destBuffer, int length, int spiCh) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI_Type* SPIn = spi_peripherals[spiCh];&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIn-&amp;gt;C1 &amp;amp;= ~SPI_C1_SPE_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Enable DMA clocking&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM-&amp;gt;SCGC6 |= SIM_SCGC6_DMAMUX_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enable clock to DMA mux&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM-&amp;gt;SCGC7 |= SIM_SCGC7_DMA_MASK;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enable clock to DMA&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __disable_irq();&amp;nbsp;&amp;nbsp;&amp;nbsp; // Disable Interrupts - this needs to be an atomic operation&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // reset DMAMUX0&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMAMUX0-&amp;gt;CHCFG[dmaReadCh] = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMAMUX0-&amp;gt;CHCFG[dmaWriteCh] = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaReadCh].DSR_BCR = DMA_DSR_BCR_DONE_MASK; // clear/reset DMA status&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaWriteCh].DSR_BCR = DMA_DSR_BCR_DONE_MASK; // clear/reset DMA status&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Configure DMAMUX&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMAMUX0-&amp;gt;CHCFG[dmaReadCh] = DMAMUX_CHCFG_ENBL_MASK | /*DMAMUX_CHCFG_TRIG_MASK | */(spiCh ? DMA_MUX_SRC_SPI1_Receive : DMA_MUX_SRC_SPI0_Receive);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMAMUX0-&amp;gt;CHCFG[dmaWriteCh] = DMAMUX_CHCFG_ENBL_MASK | /*DMAMUX_CHCFG_TRIG_MASK | */(spiCh ? DMA_MUX_SRC_SPI1_Transmit : DMA_MUX_SRC_SPI0_Transmit);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set up DMA channel to read from SPI&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaReadCh].SAR = (uint32_t)&amp;amp;(SPIn-&amp;gt;D);// set source address: SPI Data register&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaReadCh].DAR = (unsigned int)destBuffer; // set dest address: memory buffer&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaReadCh].DSR_BCR |= DMA_DSR_BCR_BCR_MASK &amp;amp; length; // length of transfer&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaReadCh].DCR = DMA_DCR_ERQ_MASK | DMA_DCR_CS_MASK | DMA_DCR_SSIZE(0x01) | DMA_DCR_DINC_MASK | DMA_DCR_DSIZE(0x01) | DMA_DCR_D_REQ_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set up another DMA channel to write to the SPI, in order to force Reads&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaWriteCh].SAR = (unsigned int)srcBuffer;// set source address&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaWriteCh].DAR = (uint32_t)&amp;amp;(SPIn-&amp;gt;D); // set dest address: SPI Data register&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaWriteCh].DSR_BCR |= DMA_DSR_BCR_BCR_MASK &amp;amp; length; // length of transfer&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DMA0-&amp;gt;DMA[dmaWriteCh].DCR = DMA_DCR_ERQ_MASK | DMA_DCR_CS_MASK | DMA_DCR_SINC_MASK | DMA_DCR_SSIZE(0x01) | DMA_DCR_DSIZE(0x01) | DMA_DCR_D_REQ_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __enable_irq();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enable SPI and the DMA features within&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: terminal, monaco; font-size: 8pt; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIn-&amp;gt;C1 |= SPI_C1_SPE_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt; font-family: terminal, monaco;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIn-&amp;gt;C2 |= SPI_C2_TXDMAE_MASK | SPI_C2_RXDMAE_MASK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I followed this up with a loop to check various status registers and so forth.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 18:01:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/DMA-with-SPI-to-read-SD-Card/m-p/279276#M10168</guid>
      <dc:creator>ids</dc:creator>
      <dc:date>2013-10-21T18:01:40Z</dc:date>
    </item>
  </channel>
</rss>

