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:
Sun Jan 22 23:13:11 2017 +0900
Revision:
38:7077795dbf81
Parent:
34:b065d97cb70f
change: table.md

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mimi3 10:b48d3ace55db 1 /* mbed Microcontroller Library
mimi3 10:b48d3ace55db 2 * Copyright (c) 2006-2012 ARM Limited
mimi3 10:b48d3ace55db 3 *
mimi3 10:b48d3ace55db 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mimi3 10:b48d3ace55db 5 * of this software and associated documentation files (the "Software"), to deal
mimi3 10:b48d3ace55db 6 * in the Software without restriction, including without limitation the rights
mimi3 10:b48d3ace55db 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mimi3 10:b48d3ace55db 8 * copies of the Software, and to permit persons to whom the Software is
mimi3 10:b48d3ace55db 9 * furnished to do so, subject to the following conditions:
mimi3 10:b48d3ace55db 10 *
mimi3 10:b48d3ace55db 11 * The above copyright notice and this permission notice shall be included in
mimi3 10:b48d3ace55db 12 * all copies or substantial portions of the Software.
mimi3 10:b48d3ace55db 13 *
mimi3 10:b48d3ace55db 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mimi3 10:b48d3ace55db 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mimi3 10:b48d3ace55db 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mimi3 10:b48d3ace55db 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mimi3 10:b48d3ace55db 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mimi3 10:b48d3ace55db 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mimi3 10:b48d3ace55db 20 * SOFTWARE.
mimi3 10:b48d3ace55db 21 */
mimi3 10:b48d3ace55db 22 #include "mbed.h"
mimi3 10:b48d3ace55db 23
mimi3 10:b48d3ace55db 24 #include "ffconf.h"
mimi3 10:b48d3ace55db 25 #include "mbed_debug.h"
mimi3 10:b48d3ace55db 26
mimi3 10:b48d3ace55db 27 #include "FATFileSystem.h"
mimi3 10:b48d3ace55db 28 #include "FATFileHandle.h"
mimi3 10:b48d3ace55db 29 #include "FATDirHandle.h"
mimi3 10:b48d3ace55db 30
mimi3 10:b48d3ace55db 31 DWORD get_fattime(void) {
mimi3 10:b48d3ace55db 32 time_t rawtime;
mimi3 10:b48d3ace55db 33 time(&rawtime);
mimi3 10:b48d3ace55db 34 struct tm *ptm = localtime(&rawtime);
mimi3 10:b48d3ace55db 35 return (DWORD)(ptm->tm_year - 80) << 25
mimi3 10:b48d3ace55db 36 | (DWORD)(ptm->tm_mon + 1 ) << 21
mimi3 10:b48d3ace55db 37 | (DWORD)(ptm->tm_mday ) << 16
mimi3 10:b48d3ace55db 38 | (DWORD)(ptm->tm_hour ) << 11
mimi3 10:b48d3ace55db 39 | (DWORD)(ptm->tm_min ) << 5
mimi3 10:b48d3ace55db 40 | (DWORD)(ptm->tm_sec/2 );
mimi3 10:b48d3ace55db 41 }
mimi3 10:b48d3ace55db 42
mimi3 10:b48d3ace55db 43 FATFileSystem *FATFileSystem::_ffs[_VOLUMES] = {0};
mimi3 10:b48d3ace55db 44
mimi3 10:b48d3ace55db 45 FATFileSystem::FATFileSystem(const char* n) : FileSystemLike(n) {
mimi3 10:b48d3ace55db 46 debug_if(FFS_DBG, "FATFileSystem(%s)\n", n);
mimi3 10:b48d3ace55db 47 for(int i=0; i<_VOLUMES; i++) {
mimi3 10:b48d3ace55db 48 if(_ffs[i] == 0) {
mimi3 10:b48d3ace55db 49 _ffs[i] = this;
mimi3 10:b48d3ace55db 50 _fsid[0] = '0' + i;
mimi3 10:b48d3ace55db 51 _fsid[1] = '\0';
dinau 31:cfad42bb789a 52 debug_if(FFS_DBG, "Mounting [%s] on ffs drive [%s]\n", getName(), _fsid);
mimi3 10:b48d3ace55db 53 f_mount(&_fs, _fsid, 0);
mimi3 10:b48d3ace55db 54 return;
mimi3 10:b48d3ace55db 55 }
mimi3 10:b48d3ace55db 56 }
mimi3 10:b48d3ace55db 57 error("Couldn't create %s in FATFileSystem::FATFileSystem\n", n);
mimi3 10:b48d3ace55db 58 }
mimi3 10:b48d3ace55db 59
mimi3 10:b48d3ace55db 60 FATFileSystem::~FATFileSystem() {
mimi3 10:b48d3ace55db 61 for (int i=0; i<_VOLUMES; i++) {
mimi3 10:b48d3ace55db 62 if (_ffs[i] == this) {
mimi3 10:b48d3ace55db 63 _ffs[i] = 0;
mimi3 10:b48d3ace55db 64 f_mount(NULL, _fsid, 0);
mimi3 10:b48d3ace55db 65 }
mimi3 10:b48d3ace55db 66 }
mimi3 10:b48d3ace55db 67 }
mimi3 10:b48d3ace55db 68
mimi3 10:b48d3ace55db 69 FileHandle *FATFileSystem::open(const char* name, int flags) {
dinau 31:cfad42bb789a 70 debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%s]\n", name, getName(), _fsid);
mimi3 10:b48d3ace55db 71 char n[64];
mimi3 10:b48d3ace55db 72 sprintf(n, "%s:/%s", _fsid, name);
mimi3 10:b48d3ace55db 73
mimi3 10:b48d3ace55db 74 /* POSIX flags -> FatFS open mode */
mimi3 10:b48d3ace55db 75 BYTE openmode;
dinau 34:b065d97cb70f 76 #if _FS_READONLY==1
dinau 34:b065d97cb70f 77 openmode = FA_READ;
dinau 34:b065d97cb70f 78 #else
mimi3 10:b48d3ace55db 79 if (flags & O_RDWR) {
mimi3 10:b48d3ace55db 80 openmode = FA_READ|FA_WRITE;
mimi3 10:b48d3ace55db 81 } else if(flags & O_WRONLY) {
mimi3 10:b48d3ace55db 82 openmode = FA_WRITE;
mimi3 10:b48d3ace55db 83 } else {
mimi3 10:b48d3ace55db 84 openmode = FA_READ;
mimi3 10:b48d3ace55db 85 }
mimi3 10:b48d3ace55db 86 if(flags & O_CREAT) {
mimi3 10:b48d3ace55db 87 if(flags & O_TRUNC) {
mimi3 10:b48d3ace55db 88 openmode |= FA_CREATE_ALWAYS;
mimi3 10:b48d3ace55db 89 } else {
mimi3 10:b48d3ace55db 90 openmode |= FA_OPEN_ALWAYS;
mimi3 10:b48d3ace55db 91 }
mimi3 10:b48d3ace55db 92 }
dinau 34:b065d97cb70f 93 #endif
mimi3 10:b48d3ace55db 94
mimi3 10:b48d3ace55db 95 FIL fh;
mimi3 10:b48d3ace55db 96 FRESULT res = f_open(&fh, n, openmode);
mimi3 10:b48d3ace55db 97 if (res) {
mimi3 10:b48d3ace55db 98 debug_if(FFS_DBG, "f_open('w') failed: %d\n", res);
mimi3 10:b48d3ace55db 99 return NULL;
mimi3 10:b48d3ace55db 100 }
dinau 34:b065d97cb70f 101 #if !_FS_READONLY
mimi3 10:b48d3ace55db 102 if (flags & O_APPEND) {
mimi3 10:b48d3ace55db 103 f_lseek(&fh, fh.fsize);
mimi3 10:b48d3ace55db 104 }
dinau 34:b065d97cb70f 105 #endif
mimi3 10:b48d3ace55db 106 return new FATFileHandle(fh);
mimi3 10:b48d3ace55db 107 }
mimi3 10:b48d3ace55db 108
mimi3 10:b48d3ace55db 109 int FATFileSystem::remove(const char *filename) {
dinau 34:b065d97cb70f 110 #if !_FS_READONLY
mimi3 10:b48d3ace55db 111 FRESULT res = f_unlink(filename);
mimi3 10:b48d3ace55db 112 if (res) {
mimi3 10:b48d3ace55db 113 debug_if(FFS_DBG, "f_unlink() failed: %d\n", res);
mimi3 10:b48d3ace55db 114 return -1;
mimi3 10:b48d3ace55db 115 }
mimi3 10:b48d3ace55db 116 return 0;
dinau 34:b065d97cb70f 117 #else
dinau 34:b065d97cb70f 118 return -1;
dinau 34:b065d97cb70f 119 #endif
mimi3 10:b48d3ace55db 120 }
mimi3 10:b48d3ace55db 121
mimi3 10:b48d3ace55db 122 int FATFileSystem::rename(const char *oldname, const char *newname) {
dinau 34:b065d97cb70f 123 #if !_FS_READONLY
mimi3 10:b48d3ace55db 124 FRESULT res = f_rename(oldname, newname);
mimi3 10:b48d3ace55db 125 if (res) {
mimi3 10:b48d3ace55db 126 debug_if(FFS_DBG, "f_rename() failed: %d\n", res);
mimi3 10:b48d3ace55db 127 return -1;
mimi3 10:b48d3ace55db 128 }
mimi3 10:b48d3ace55db 129 return 0;
dinau 34:b065d97cb70f 130 #else
dinau 34:b065d97cb70f 131 return -1;
dinau 34:b065d97cb70f 132 #endif
mimi3 10:b48d3ace55db 133 }
mimi3 10:b48d3ace55db 134
mimi3 10:b48d3ace55db 135 int FATFileSystem::format() {
dinau 34:b065d97cb70f 136 #if !_FS_READONLY
mimi3 10:b48d3ace55db 137 FRESULT res = f_mkfs(_fsid, 0, 512); // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
mimi3 10:b48d3ace55db 138 if (res) {
mimi3 10:b48d3ace55db 139 debug_if(FFS_DBG, "f_mkfs() failed: %d\n", res);
mimi3 10:b48d3ace55db 140 return -1;
mimi3 10:b48d3ace55db 141 }
mimi3 10:b48d3ace55db 142 return 0;
dinau 34:b065d97cb70f 143 #else
dinau 34:b065d97cb70f 144 return -1;
dinau 34:b065d97cb70f 145 #endif
mimi3 10:b48d3ace55db 146 }
mimi3 10:b48d3ace55db 147
mimi3 10:b48d3ace55db 148 DirHandle *FATFileSystem::opendir(const char *name) {
mimi3 10:b48d3ace55db 149 FATFS_DIR dir;
mimi3 10:b48d3ace55db 150 FRESULT res = f_opendir(&dir, name);
mimi3 10:b48d3ace55db 151 if (res != 0) {
mimi3 10:b48d3ace55db 152 return NULL;
mimi3 10:b48d3ace55db 153 }
mimi3 10:b48d3ace55db 154 return new FATDirHandle(dir);
mimi3 10:b48d3ace55db 155 }
mimi3 10:b48d3ace55db 156
mimi3 10:b48d3ace55db 157 int FATFileSystem::mkdir(const char *name, mode_t mode) {
dinau 34:b065d97cb70f 158 #if !_FS_READONLY
mimi3 10:b48d3ace55db 159 FRESULT res = f_mkdir(name);
mimi3 10:b48d3ace55db 160 return res == 0 ? 0 : -1;
dinau 34:b065d97cb70f 161 #else
dinau 34:b065d97cb70f 162 return -1;
dinau 34:b065d97cb70f 163 #endif
mimi3 10:b48d3ace55db 164 }
mimi3 10:b48d3ace55db 165
mimi3 10:b48d3ace55db 166 int FATFileSystem::mount() {
mimi3 10:b48d3ace55db 167 FRESULT res = f_mount(&_fs, _fsid, 1);
mimi3 10:b48d3ace55db 168 return res == 0 ? 0 : -1;
mimi3 10:b48d3ace55db 169 }
mimi3 10:b48d3ace55db 170
mimi3 10:b48d3ace55db 171 int FATFileSystem::unmount() {
mimi3 10:b48d3ace55db 172 if (disk_sync())
mimi3 10:b48d3ace55db 173 return -1;
mimi3 10:b48d3ace55db 174 FRESULT res = f_mount(NULL, _fsid, 0);
mimi3 10:b48d3ace55db 175 return res == 0 ? 0 : -1;
mimi3 10:b48d3ace55db 176 }