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 .
SDFileSystemDMA.h@0:853a612ffb16, 2016-02-12 (annotated)
- Committer:
- mimi3
- Date:
- Fri Feb 12 13:43:31 2016 +0000
- Revision:
- 0:853a612ffb16
- Child:
- 2:0e871408d51b
added: FATFileSystem(Official version(latest))
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mimi3 | 0:853a612ffb16 | 1 | /* mbed Microcontroller Library |
mimi3 | 0:853a612ffb16 | 2 | * Copyright (c) 2006-2012 ARM Limited |
mimi3 | 0:853a612ffb16 | 3 | * |
mimi3 | 0:853a612ffb16 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
mimi3 | 0:853a612ffb16 | 5 | * of this software and associated documentation files (the "Software"), to deal |
mimi3 | 0:853a612ffb16 | 6 | * in the Software without restriction, including without limitation the rights |
mimi3 | 0:853a612ffb16 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
mimi3 | 0:853a612ffb16 | 8 | * copies of the Software, and to permit persons to whom the Software is |
mimi3 | 0:853a612ffb16 | 9 | * furnished to do so, subject to the following conditions: |
mimi3 | 0:853a612ffb16 | 10 | * |
mimi3 | 0:853a612ffb16 | 11 | * The above copyright notice and this permission notice shall be included in |
mimi3 | 0:853a612ffb16 | 12 | * all copies or substantial portions of the Software. |
mimi3 | 0:853a612ffb16 | 13 | * |
mimi3 | 0:853a612ffb16 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
mimi3 | 0:853a612ffb16 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
mimi3 | 0:853a612ffb16 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
mimi3 | 0:853a612ffb16 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
mimi3 | 0:853a612ffb16 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mimi3 | 0:853a612ffb16 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
mimi3 | 0:853a612ffb16 | 20 | * SOFTWARE. |
mimi3 | 0:853a612ffb16 | 21 | */ |
mimi3 | 0:853a612ffb16 | 22 | #ifndef MBED_SDFILESYSTEM_H |
mimi3 | 0:853a612ffb16 | 23 | #define MBED_SDFILESYSTEM_H |
mimi3 | 0:853a612ffb16 | 24 | |
mimi3 | 0:853a612ffb16 | 25 | #include "mbed.h" |
mimi3 | 0:853a612ffb16 | 26 | #include "FATFileSystem.h" |
mimi3 | 0:853a612ffb16 | 27 | #include <stdint.h> |
mimi3 | 0:853a612ffb16 | 28 | |
mimi3 | 0:853a612ffb16 | 29 | /** Access the filesystem on an SD Card using SPI |
mimi3 | 0:853a612ffb16 | 30 | * |
mimi3 | 0:853a612ffb16 | 31 | * @code |
mimi3 | 0:853a612ffb16 | 32 | * #include "mbed.h" |
mimi3 | 0:853a612ffb16 | 33 | * #include "SDFileSystem.h" |
mimi3 | 0:853a612ffb16 | 34 | * |
mimi3 | 0:853a612ffb16 | 35 | * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs |
mimi3 | 0:853a612ffb16 | 36 | * |
mimi3 | 0:853a612ffb16 | 37 | * int main() { |
mimi3 | 0:853a612ffb16 | 38 | * FILE *fp = fopen("/sd/myfile.txt", "w"); |
mimi3 | 0:853a612ffb16 | 39 | * fprintf(fp, "Hello World!\n"); |
mimi3 | 0:853a612ffb16 | 40 | * fclose(fp); |
mimi3 | 0:853a612ffb16 | 41 | * } |
mimi3 | 0:853a612ffb16 | 42 | */ |
mimi3 | 0:853a612ffb16 | 43 | class SDFileSystem : public FATFileSystem { |
mimi3 | 0:853a612ffb16 | 44 | public: |
mimi3 | 0:853a612ffb16 | 45 | |
mimi3 | 0:853a612ffb16 | 46 | /** Create the File System for accessing an SD Card using SPI |
mimi3 | 0:853a612ffb16 | 47 | * |
mimi3 | 0:853a612ffb16 | 48 | * @param mosi SPI mosi pin connected to SD Card |
mimi3 | 0:853a612ffb16 | 49 | * @param miso SPI miso pin conencted to SD Card |
mimi3 | 0:853a612ffb16 | 50 | * @param sclk SPI sclk pin connected to SD Card |
mimi3 | 0:853a612ffb16 | 51 | * @param cs DigitalOut pin used as SD Card chip select |
mimi3 | 0:853a612ffb16 | 52 | * @param name The name used to access the virtual filesystem |
mimi3 | 0:853a612ffb16 | 53 | */ |
mimi3 | 0:853a612ffb16 | 54 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
mimi3 | 0:853a612ffb16 | 55 | virtual int disk_initialize(); |
mimi3 | 0:853a612ffb16 | 56 | virtual int disk_status(); |
mimi3 | 0:853a612ffb16 | 57 | virtual int disk_read(uint8_t* buffer, uint32_t block_number, uint32_t count); |
mimi3 | 0:853a612ffb16 | 58 | virtual int disk_write(const uint8_t* buffer, uint32_t block_number, uint32_t count); |
mimi3 | 0:853a612ffb16 | 59 | virtual int disk_sync(); |
mimi3 | 0:853a612ffb16 | 60 | virtual uint32_t disk_sectors(); |
mimi3 | 0:853a612ffb16 | 61 | |
mimi3 | 0:853a612ffb16 | 62 | protected: |
mimi3 | 0:853a612ffb16 | 63 | |
mimi3 | 0:853a612ffb16 | 64 | int _cmd(int cmd, int arg); |
mimi3 | 0:853a612ffb16 | 65 | int _cmdx(int cmd, int arg); |
mimi3 | 0:853a612ffb16 | 66 | int _cmd8(); |
mimi3 | 0:853a612ffb16 | 67 | int _cmd58(); |
mimi3 | 0:853a612ffb16 | 68 | int initialise_card(); |
mimi3 | 0:853a612ffb16 | 69 | int initialise_card_v1(); |
mimi3 | 0:853a612ffb16 | 70 | int initialise_card_v2(); |
mimi3 | 0:853a612ffb16 | 71 | |
mimi3 | 0:853a612ffb16 | 72 | int _read(uint8_t * buffer, uint32_t length); |
mimi3 | 0:853a612ffb16 | 73 | int _write(const uint8_t *buffer, uint32_t length); |
mimi3 | 0:853a612ffb16 | 74 | uint32_t _sd_sectors(); |
mimi3 | 0:853a612ffb16 | 75 | uint32_t _sectors; |
mimi3 | 0:853a612ffb16 | 76 | |
mimi3 | 0:853a612ffb16 | 77 | void set_init_sck(uint32_t sck) { _init_sck = sck; } |
mimi3 | 0:853a612ffb16 | 78 | // Note: The highest SPI clock rate is 20 MHz for MMC and 25 MHz for SD |
mimi3 | 0:853a612ffb16 | 79 | void set_transfer_sck(uint32_t sck) { _transfer_sck = sck; } |
mimi3 | 0:853a612ffb16 | 80 | uint32_t _init_sck; |
mimi3 | 0:853a612ffb16 | 81 | uint32_t _transfer_sck; |
mimi3 | 0:853a612ffb16 | 82 | |
mimi3 | 0:853a612ffb16 | 83 | SPI _spi; |
mimi3 | 0:853a612ffb16 | 84 | DigitalOut _cs; |
mimi3 | 0:853a612ffb16 | 85 | int cdv; |
mimi3 | 0:853a612ffb16 | 86 | int _is_initialized; |
mimi3 | 0:853a612ffb16 | 87 | }; |
mimi3 | 0:853a612ffb16 | 88 | |
mimi3 | 0:853a612ffb16 | 89 | #endif |