first 2016/02 SDFileSystemDMA inherited from Official SDFileSystem.
Dependents: SDFileSystemDMA-test DmdFullRGB_0_1
Fork of SDFileSystemDMA by
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/
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
Board | SRAM | SPI1 | SPI2 | SPI3 |
---|---|---|---|---|
NUCLEO-F030R8 | 8KB | (v) | ||
DISCO-F051R8 | 8KB | (w) | ||
4KB | (f) | |||
NUCLEO-F042K6 | 6KB | (r) | ||
NUCLEO-F070RB | 16KB | (w) | ||
NUCLEO-F072RB | 16KB | (w) | ||
NUCLEO-F091RC | 32KB | (c) |
Cortex-L0
Board | SRAM | SPI1 | SPI2 | SPI3 |
---|---|---|---|---|
DISCO-L053C8 | 8KB | (c) | ||
NUCLEO-L053R8 | 8KB | (c) | ||
NUCLEO-L073RZ | 20KB | (c) |
Cortex-M3
Board | SRAM | SPI1 | SPI2 | SPI3 |
---|---|---|---|---|
DISCO-F100RB | 8KB | (v) | (v) | - |
BLUEPILL-F103CB | 20KB | (w) | (w) | - |
NUCLEO-F103RB | 20KB | (v) | (v) | - |
NUCLEO-L152RE | 80KB | (v) | (w) | - |
MOTE-L152RC | 32KB | (w) | (w) | - |
Cortex-M4
F3
Board | SRAM | SPI1 | SPI2 | SPI3 |
---|---|---|---|---|
DISCO-F303VC | 40KB | - | (v) | (v) |
NUCLEO-F303RE | 64KB | (w) | (w) | (w) |
NUCLEO-F302R8 | 16KB | - | - | (c) |
NUCLEO-F303K8 | 12KB | (c) | - | - |
DISCO-F334C8 | 12KB | (c) | - | - |
NUCLEO-F334R8 | 12KB | (c) | - | - |
F4
Board | SPI1 | SPI2 | SPI3 |
---|---|---|---|
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 .
spi_dma/spi_dma_common.c@38:7077795dbf81, 2017-01-22 (annotated)
- Committer:
- mimi3
- Date:
- Sun Jan 22 23:13:11 2017 +0900
- Revision:
- 38:7077795dbf81
- Parent:
- 24:92bf692d61e2
change: table.md
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mimi3 | 2:0e871408d51b | 1 | #include "spi_dma.h" |
mimi3 | 21:41129109d6ab | 2 | #include "PeripheralPins.h" |
mimi3 | 2:0e871408d51b | 3 | |
mimi3 | 21:41129109d6ab | 4 | DMA_HandleTypeDef hdma_spi_tx; |
mimi3 | 21:41129109d6ab | 5 | DMA_HandleTypeDef hdma_spi_rx; |
mimi3 | 21:41129109d6ab | 6 | SPI_HandleTypeDef SpiHandle; |
mimi3 | 5:809e2eece945 | 7 | |
mimi3 | 2:0e871408d51b | 8 | static void spi_dma_error_handler(void) |
mimi3 | 2:0e871408d51b | 9 | { |
mimi3 | 2:0e871408d51b | 10 | while(1) |
mimi3 | 2:0e871408d51b | 11 | { |
mimi3 | 2:0e871408d51b | 12 | /* infinite loop */ |
mimi3 | 2:0e871408d51b | 13 | } |
mimi3 | 2:0e871408d51b | 14 | } |
mimi3 | 2:0e871408d51b | 15 | |
mimi3 | 2:0e871408d51b | 16 | static void spi_dma_start( SPI_TypeDef *spi, uint8_t *txbuff, uint8_t *rxbuff, uint16_t count) |
mimi3 | 2:0e871408d51b | 17 | { |
mimi3 | 21:41129109d6ab | 18 | (void)spi; |
mimi3 | 21:41129109d6ab | 19 | if( HAL_SPI_TransmitReceive_DMA( &SpiHandle, (uint8_t *)txbuff, (uint8_t *)rxbuff, count) != HAL_OK) { |
mimi3 | 2:0e871408d51b | 20 | spi_dma_error_handler(); |
mimi3 | 2:0e871408d51b | 21 | } |
mimi3 | 2:0e871408d51b | 22 | } |
mimi3 | 2:0e871408d51b | 23 | |
mimi3 | 2:0e871408d51b | 24 | static void spi_dma_wait_end( SPI_TypeDef *spi ) |
mimi3 | 2:0e871408d51b | 25 | { |
mimi3 | 21:41129109d6ab | 26 | (void)spi; |
mimi3 | 21:41129109d6ab | 27 | while (HAL_SPI_GetState( &SpiHandle ) != HAL_SPI_STATE_READY) { |
mimi3 | 2:0e871408d51b | 28 | /* just wait */ |
mimi3 | 2:0e871408d51b | 29 | } |
mimi3 | 2:0e871408d51b | 30 | } |
mimi3 | 2:0e871408d51b | 31 | |
mimi3 | 5:809e2eece945 | 32 | static void spi_dma_deinit( SPI_TypeDef *spi) |
mimi3 | 5:809e2eece945 | 33 | { |
mimi3 | 21:41129109d6ab | 34 | (void)spi; |
mimi3 | 21:41129109d6ab | 35 | HAL_DMA_DeInit( &hdma_spi_tx); |
mimi3 | 21:41129109d6ab | 36 | HAL_DMA_DeInit( &hdma_spi_rx); |
mimi3 | 2:0e871408d51b | 37 | } |
mimi3 | 18:1b1a0e68008a | 38 | |
mimi3 | 21:41129109d6ab | 39 | SPI_TypeDef *spi_get_id( PinName mosi, PinName miso, PinName sclk, PinName ssel) { |
mimi3 | 21:41129109d6ab | 40 | // Determine the SPI to use |
mimi3 | 21:41129109d6ab | 41 | SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI); |
mimi3 | 21:41129109d6ab | 42 | SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO); |
mimi3 | 21:41129109d6ab | 43 | SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK); |
mimi3 | 21:41129109d6ab | 44 | SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL); |
mimi3 | 18:1b1a0e68008a | 45 | |
mimi3 | 21:41129109d6ab | 46 | SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); |
mimi3 | 21:41129109d6ab | 47 | SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); |
mimi3 | 21:41129109d6ab | 48 | |
mimi3 | 21:41129109d6ab | 49 | return (SPI_TypeDef *) ( (SPIName)pinmap_merge(spi_data, spi_cntl) ); |
mimi3 | 21:41129109d6ab | 50 | } |
mimi3 | 21:41129109d6ab | 51 | |
mimi3 | 21:41129109d6ab | 52 | void spi_dma_init( SPI_TypeDef *spi ) { |
mimi3 | 21:41129109d6ab | 53 | spi_dma_irq_setup( spi ); |
mimi3 | 21:41129109d6ab | 54 | spi_dma_get_info( spi ); |
mimi3 | 21:41129109d6ab | 55 | } |
mimi3 | 2:0e871408d51b | 56 | |
mimi3 | 2:0e871408d51b | 57 | void __spi_dma_read_write( SPI_TypeDef *spi, uint8_t *txbuff, uint8_t *rxbuff, uint16_t count, uint8_t mode) |
mimi3 | 2:0e871408d51b | 58 | { |
mimi3 | 2:0e871408d51b | 59 | spi_dma_handle_setup( spi, mode ); |
mimi3 | 2:0e871408d51b | 60 | spi_dma_start( spi, txbuff, rxbuff, count ); |
mimi3 | 2:0e871408d51b | 61 | spi_dma_wait_end( spi ); |
mimi3 | 17:e6d3b7ed3799 | 62 | spi_dma_deinit(spi); |
mimi3 | 2:0e871408d51b | 63 | } |
mimi3 | 2:0e871408d51b | 64 |