first 2016/02 SDFileSystemDMA inherited from Official SDFileSystem.

Dependents:   SDFileSystemDMA-test DmdFullRGB_0_1

Fork of SDFileSystemDMA by mi mi

SDFileSystemDMA is enhanced SDFileSystem library for STM32 micros by using DMA functionality.
Max read transfer rate reaches over 2MByte/sec at 24MHz SPI clock if enough read buffer size is set.
Even though minimum read buffer size (512Byte) is set, read transfer rate will reach over 1MByte/sec at 24MHz SPI Clock.
( but depends on the ability of each SD card)

Test program is here.
https://developer.mbed.org/users/mimi3/code/SDFileSystemDMA-test/

/media/uploads/mimi3/sdfilesystemdma-speed-test3-read-buffer-512byte.png

/media/uploads/mimi3/sdfilesystemdma-speed-test-buffer-vs-spi-clock-nucleo-f411re-96mhz.png

Supported SPI port is shown below table.

(v): Verified. It works well.
(w): Probably it will work well. (not tested)
(c): Only compiled. (not tested)
(f): Over flash.
(r): Only read mode. (when _FS_READONLY==1)
(u) Under construction
(z): Dose not work.

Caution

If your board has SRAM less than or equal to 8KB, the buffer size must be set to 512 Bytes.

Supported Boards:
Cortex-M0

BoardSRAMSPI1SPI2SPI3
NUCLEO-F030R88KB(v)
DISCO-F051R88KB(w)
NUCLEO-F031K64KB(f)
NUCLEO-F042K66KB(r)
NUCLEO-F070RB16KB(w)
NUCLEO-F072RB16KB(w)
NUCLEO-F091RC32KB(c)

Cortex-L0

BoardSRAMSPI1SPI2SPI3
DISCO-L053C88KB(c)
NUCLEO-L053R88KB(c)
NUCLEO-L073RZ20KB(c)

Cortex-M3

BoardSRAMSPI1SPI2SPI3
DISCO-F100RB8KB(v)(v)-
BLUEPILL-F103CB20KB(w)(w)-
NUCLEO-F103RB20KB(v)(v)-
NUCLEO-L152RE80KB(v)(w)-
MOTE-L152RC32KB(w)(w)-

Cortex-M4
F3

BoardSRAMSPI1SPI2SPI3
DISCO-F303VC40KB-(v)(v)
NUCLEO-F303RE64KB(w)(w)(w)
NUCLEO-F302R816KB--(c)
NUCLEO-F303K812KB(c)--
DISCO-F334C812KB(c)--
NUCLEO-F334R812KB(c)--

F4

BoardSPI1SPI2SPI3
ELMO-F411RE(w)-(w)
MTS-MDOT-F411RE(u)-(u)
MTS-DRAGONFLY-F411RE(w)-(w)
NUCLEO-F411RE(v)-(v)
NUCLEO-F401RE(w)-(w)
MTS-MDOT-F405RG(u)-(u)
NUCLEO-F410RB(c)-(c)
NUCLEO-F446RE(c)-(c)
NUCLEO-F429ZI(c)-(c)
B96B-F446VE(c)-(c)
NUCLEO-F446ZE(c)-(c)
DISCO-F429ZI(u)-(u)
DISCO-F469NI(c)-(c)

Information

This library is set to use "short file name" in SDFileSystemDMA/FATFileSystem/ChaN/ffconf.h . ( _USE_LFN=0)
You can change this option to _USE_LFN=1 .

Committer:
mimi3
Date:
Mon Feb 15 22:40:26 2016 +0900
Revision:
18:1b1a0e68008a
Parent:
2:0e871408d51b
Child:
20:c6a6e019922e
Refactoring: part1: F0,F3,F4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mimi3 2:0e871408d51b 1 #if defined(TARGET_STM32F4)
mimi3 2:0e871408d51b 2 /*
mimi3 2:0e871408d51b 3
mimi3 2:0e871408d51b 4 This file is licensed under Apache 2.0 license.
mimi3 2:0e871408d51b 5 (C) 2016 dinau
mimi3 2:0e871408d51b 6
mimi3 2:0e871408d51b 7 */
mimi3 2:0e871408d51b 8 #include "spi_dma.h"
mimi3 2:0e871408d51b 9
mimi3 2:0e871408d51b 10 #define DMAx_CLK_ENABLE() __DMA2_CLK_ENABLE()
mimi3 2:0e871408d51b 11 #define SPIx_TX_DMA_STREAM DMA2_Stream3
mimi3 2:0e871408d51b 12 #define SPIx_RX_DMA_STREAM DMA2_Stream2
mimi3 2:0e871408d51b 13 #define SPIx_TX_DMA_CHANNEL DMA_CHANNEL_3
mimi3 2:0e871408d51b 14 #define SPIx_RX_DMA_CHANNEL DMA_CHANNEL_3
mimi3 18:1b1a0e68008a 15 #define SPIx_DMA_TX_IRQn DMA2_Stream3_IRQn
mimi3 18:1b1a0e68008a 16 #define SPIx_DMA_RX_IRQn DMA2_Stream2_IRQn
mimi3 18:1b1a0e68008a 17 #define DMAx_TX_IRQHandler DMA2_Stream3_IRQHandler
mimi3 18:1b1a0e68008a 18 #define DMAx_RX_IRQHandler DMA2_Stream2_IRQHandler
mimi3 2:0e871408d51b 19
mimi3 2:0e871408d51b 20 #define readReg( reg, mask) ( (reg) & (mask) )
mimi3 2:0e871408d51b 21
mimi3 2:0e871408d51b 22
mimi3 2:0e871408d51b 23 void spi_dma_get_info( SPI_TypeDef *spi )
mimi3 2:0e871408d51b 24 {
mimi3 2:0e871408d51b 25 SPI_HandleTypeDef *hspi;
mimi3 2:0e871408d51b 26 if( spi == SPI1 ){
mimi3 2:0e871408d51b 27 hspi = &Spi1Handle;
mimi3 2:0e871408d51b 28 }
mimi3 2:0e871408d51b 29 #if 0
mimi3 2:0e871408d51b 30 else {
mimi3 2:0e871408d51b 31 hspi = &Spi2Handle;
mimi3 2:0e871408d51b 32 }
mimi3 2:0e871408d51b 33 #endif
mimi3 2:0e871408d51b 34 hspi->Instance = spi;
mimi3 2:0e871408d51b 35 hspi->Init.Mode = readReg(spi->CR1, SPI_MODE_MASTER);
mimi3 2:0e871408d51b 36 hspi->Init.BaudRatePrescaler = readReg(spi->CR1, SPI_CR1_BR);
mimi3 2:0e871408d51b 37 hspi->Init.Direction = readReg(spi->CR1, SPI_CR1_BIDIMODE);
mimi3 2:0e871408d51b 38 hspi->Init.CLKPhase = readReg(spi->CR1, SPI_CR1_CPHA);
mimi3 2:0e871408d51b 39 hspi->Init.CLKPolarity = readReg(spi->CR1, SPI_CR1_CPOL);
mimi3 2:0e871408d51b 40 hspi->Init.CRCCalculation = readReg(spi->CR1, SPI_CR1_CRCEN);
mimi3 2:0e871408d51b 41 hspi->Init.CRCPolynomial = spi->CRCPR & 0xFFFF;
mimi3 2:0e871408d51b 42 hspi->Init.DataSize = readReg(spi->CR1, SPI_CR1_DFF);
mimi3 2:0e871408d51b 43 hspi->Init.FirstBit = SPI_FIRSTBIT_MSB;
mimi3 2:0e871408d51b 44 hspi->Init.NSS = readReg(spi->CR1, SPI_CR1_SSM);
mimi3 2:0e871408d51b 45 hspi->Init.TIMode = SPI_TIMODE_DISABLED;
mimi3 2:0e871408d51b 46 hspi->State = HAL_SPI_STATE_READY;
mimi3 2:0e871408d51b 47 }
mimi3 2:0e871408d51b 48
mimi3 18:1b1a0e68008a 49 void spi_dma_handle_setup( SPI_TypeDef *spi, uint8_t mode )
mimi3 18:1b1a0e68008a 50 {
mimi3 18:1b1a0e68008a 51 static uint8_t dma_handle_inited = 0;
mimi3 2:0e871408d51b 52 /* Peripheral DMA init*/
mimi3 2:0e871408d51b 53 if( spi == SPI1 ){
mimi3 2:0e871408d51b 54 /* TX: */
mimi3 18:1b1a0e68008a 55 if( !dma_handle_inited ){
mimi3 18:1b1a0e68008a 56 hdma_spi1_tx.Instance = SPIx_TX_DMA_STREAM;
mimi3 18:1b1a0e68008a 57 hdma_spi1_tx.Init.Channel = SPIx_TX_DMA_CHANNEL;
mimi3 18:1b1a0e68008a 58 hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
mimi3 18:1b1a0e68008a 59 hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
mimi3 18:1b1a0e68008a 60 hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
mimi3 18:1b1a0e68008a 61 hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
mimi3 18:1b1a0e68008a 62 hdma_spi1_tx.Init.Mode = DMA_NORMAL;
mimi3 18:1b1a0e68008a 63 hdma_spi1_tx.Init.Priority = DMA_PRIORITY_HIGH;
mimi3 18:1b1a0e68008a 64 /**/
mimi3 18:1b1a0e68008a 65 hdma_spi1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
mimi3 18:1b1a0e68008a 66 hdma_spi1_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
mimi3 18:1b1a0e68008a 67 hdma_spi1_tx.Init.MemBurst = DMA_MBURST_SINGLE;
mimi3 18:1b1a0e68008a 68 hdma_spi1_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
mimi3 18:1b1a0e68008a 69 /**/
mimi3 18:1b1a0e68008a 70 }
mimi3 18:1b1a0e68008a 71 hdma_spi1_tx.Init.MemInc = ( mode == DMA_SPI_READ) ? DMA_MINC_DISABLE : DMA_MINC_ENABLE;
mimi3 2:0e871408d51b 72 HAL_DMA_Init(&hdma_spi1_tx);
mimi3 2:0e871408d51b 73 __HAL_LINKDMA( &Spi1Handle,hdmatx,hdma_spi1_tx);
mimi3 2:0e871408d51b 74
mimi3 2:0e871408d51b 75 /* RX: */
mimi3 18:1b1a0e68008a 76 if( !dma_handle_inited ){
mimi3 18:1b1a0e68008a 77 hdma_spi1_rx.Instance = SPIx_RX_DMA_STREAM;
mimi3 18:1b1a0e68008a 78 hdma_spi1_rx.Init.Channel = SPIx_RX_DMA_CHANNEL;
mimi3 18:1b1a0e68008a 79 hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
mimi3 18:1b1a0e68008a 80 hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
mimi3 18:1b1a0e68008a 81 hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
mimi3 18:1b1a0e68008a 82 hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
mimi3 18:1b1a0e68008a 83 hdma_spi1_rx.Init.Mode = DMA_NORMAL;
mimi3 18:1b1a0e68008a 84 hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW;
mimi3 18:1b1a0e68008a 85 /**/
mimi3 18:1b1a0e68008a 86 hdma_spi1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
mimi3 18:1b1a0e68008a 87 hdma_spi1_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
mimi3 18:1b1a0e68008a 88 hdma_spi1_rx.Init.MemBurst = DMA_MBURST_SINGLE;
mimi3 18:1b1a0e68008a 89 hdma_spi1_rx.Init.PeriphBurst = DMA_PBURST_SINGLE;
mimi3 18:1b1a0e68008a 90 /**/
mimi3 18:1b1a0e68008a 91 }
mimi3 18:1b1a0e68008a 92 hdma_spi1_rx.Init.MemInc = (mode == DMA_SPI_READ) ? DMA_MINC_ENABLE : DMA_MINC_DISABLE;
mimi3 2:0e871408d51b 93 HAL_DMA_Init(&hdma_spi1_rx);
mimi3 2:0e871408d51b 94 __HAL_LINKDMA( &Spi1Handle,hdmarx,hdma_spi1_rx);
mimi3 2:0e871408d51b 95 }
mimi3 2:0e871408d51b 96 #if 0
mimi3 2:0e871408d51b 97 else if( spi == SPI2 ) {
mimi3 2:0e871408d51b 98
mimi3 2:0e871408d51b 99 }
mimi3 2:0e871408d51b 100 #endif
mimi3 18:1b1a0e68008a 101 dma_handle_inited = 1;
mimi3 2:0e871408d51b 102 }
mimi3 2:0e871408d51b 103
mimi3 2:0e871408d51b 104 void spi_dma_irq_setup( SPI_TypeDef *spi)
mimi3 2:0e871408d51b 105 {
mimi3 2:0e871408d51b 106 if( spi == SPI1 ) {
mimi3 2:0e871408d51b 107 /* DMA controller clock enable */
mimi3 2:0e871408d51b 108 DMAx_CLK_ENABLE();
mimi3 2:0e871408d51b 109
mimi3 2:0e871408d51b 110 /* DMA interrupt init */
mimi3 18:1b1a0e68008a 111 HAL_NVIC_SetPriority(SPIx_DMA_TX_IRQn, 0, 1);
mimi3 18:1b1a0e68008a 112 HAL_NVIC_EnableIRQ( SPIx_DMA_TX_IRQn);
mimi3 18:1b1a0e68008a 113 HAL_NVIC_SetPriority(SPIx_DMA_RX_IRQn, 0, 0);
mimi3 18:1b1a0e68008a 114 HAL_NVIC_EnableIRQ( SPIx_DMA_RX_IRQn);
mimi3 2:0e871408d51b 115 }
mimi3 2:0e871408d51b 116 #if 0
mimi3 2:0e871408d51b 117 else if ( spi == SPI2 ){
mimi3 2:0e871408d51b 118
mimi3 2:0e871408d51b 119 }
mimi3 2:0e871408d51b 120 #endif
mimi3 2:0e871408d51b 121 }
mimi3 2:0e871408d51b 122
mimi3 18:1b1a0e68008a 123 void DMAx_TX_IRQHandler(void)
mimi3 18:1b1a0e68008a 124 {
mimi3 18:1b1a0e68008a 125 HAL_DMA_IRQHandler(&hdma_spi1_tx);
mimi3 18:1b1a0e68008a 126 }
mimi3 2:0e871408d51b 127
mimi3 18:1b1a0e68008a 128 void DMAx_RX_IRQHandler(void)
mimi3 2:0e871408d51b 129 {
mimi3 2:0e871408d51b 130 HAL_DMA_IRQHandler(&hdma_spi1_rx);
mimi3 2:0e871408d51b 131 }
mimi3 2:0e871408d51b 132
mimi3 2:0e871408d51b 133 #endif /* TARGET_STM32F4 */
mimi3 2:0e871408d51b 134