A File System interface that incorporates both SD and USB support. It was difficult to find a ready-to-go library, but the right set of pieces from others, and a few modifications, created this.

Dependencies:   FatFileSystemCpp USBHostLite

Dependents:   m3PI_TP_POPS_II2015v0 m3PI_TP_POPS_II2015v0 ourproject m3PI_TP_SETI ... more

Committer:
bouaziz
Date:
Sun Nov 10 21:01:29 2013 +0000
Revision:
2:5bc5d2b70622
Parent:
1:19a776ced714
Just simple modification to maje this lib usable by our students Polytech Paris Sud Undergraduate School  in university of Paris Sud Orsay;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 1:19a776ced714 1 /* mbed SDFileSystem Library, for providing file access to SD cards
WiredHome 1:19a776ced714 2 * Copyright (c) 2008-2010, sford
WiredHome 1:19a776ced714 3 *
WiredHome 1:19a776ced714 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
WiredHome 1:19a776ced714 5 * of this software and associated documentation files (the "Software"), to deal
WiredHome 1:19a776ced714 6 * in the Software without restriction, including without limitation the rights
WiredHome 1:19a776ced714 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
WiredHome 1:19a776ced714 8 * copies of the Software, and to permit persons to whom the Software is
WiredHome 1:19a776ced714 9 * furnished to do so, subject to the following conditions:
WiredHome 1:19a776ced714 10 *
WiredHome 1:19a776ced714 11 * The above copyright notice and this permission notice shall be included in
WiredHome 1:19a776ced714 12 * all copies or substantial portions of the Software.
WiredHome 1:19a776ced714 13 *
WiredHome 1:19a776ced714 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
WiredHome 1:19a776ced714 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
WiredHome 1:19a776ced714 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
WiredHome 1:19a776ced714 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
WiredHome 1:19a776ced714 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
WiredHome 1:19a776ced714 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
WiredHome 1:19a776ced714 20 * THE SOFTWARE.
WiredHome 1:19a776ced714 21 */
WiredHome 1:19a776ced714 22
WiredHome 1:19a776ced714 23 #ifndef MBED_SDFILESYSTEM_H
WiredHome 1:19a776ced714 24 #define MBED_SDFILESYSTEM_H
WiredHome 1:19a776ced714 25
WiredHome 1:19a776ced714 26 #include "mbed.h"
WiredHome 1:19a776ced714 27 #include "FATFileSystem.h"
WiredHome 1:19a776ced714 28
WiredHome 1:19a776ced714 29 /** Access the filesystem on an SD Card using SPI
WiredHome 1:19a776ced714 30 *
WiredHome 1:19a776ced714 31 * @code
WiredHome 1:19a776ced714 32 * #include "mbed.h"
WiredHome 1:19a776ced714 33 * #include "SDFileSystem.h"
WiredHome 1:19a776ced714 34 *
WiredHome 1:19a776ced714 35 * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
WiredHome 1:19a776ced714 36 *
WiredHome 1:19a776ced714 37 * int main() {
WiredHome 1:19a776ced714 38 * FILE *fp = fopen("/sd/myfile.txt", "w");
WiredHome 1:19a776ced714 39 * fprintf(fp, "Hello World!\n");
WiredHome 1:19a776ced714 40 * fclose(fp);
WiredHome 1:19a776ced714 41 * }
WiredHome 1:19a776ced714 42 */
WiredHome 1:19a776ced714 43 class SDFileSystem : public FATFileSystem {
WiredHome 1:19a776ced714 44 public:
WiredHome 1:19a776ced714 45
WiredHome 1:19a776ced714 46 /** Create the File System for accessing an SD Card using SPI
WiredHome 1:19a776ced714 47 *
WiredHome 1:19a776ced714 48 * @param mosi SPI mosi pin connected to SD Card
WiredHome 1:19a776ced714 49 * @param miso SPI miso pin conencted to SD Card
WiredHome 1:19a776ced714 50 * @param sclk SPI sclk pin connected to SD Card
WiredHome 1:19a776ced714 51 * @param cs DigitalOut pin used as SD Card chip select
WiredHome 1:19a776ced714 52 * @param name The name used to access the virtual filesystem
WiredHome 1:19a776ced714 53 */
WiredHome 1:19a776ced714 54 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
WiredHome 1:19a776ced714 55 virtual int disk_initialize();
WiredHome 1:19a776ced714 56 virtual int disk_write(const char *buffer, int block_number);
WiredHome 1:19a776ced714 57 virtual int disk_read(char *buffer, int block_number);
WiredHome 1:19a776ced714 58 virtual int disk_status();
WiredHome 1:19a776ced714 59 virtual int disk_sync();
WiredHome 1:19a776ced714 60 virtual int disk_sectors();
WiredHome 1:19a776ced714 61
WiredHome 1:19a776ced714 62 protected:
WiredHome 1:19a776ced714 63
WiredHome 1:19a776ced714 64 int _cmd(int cmd, int arg);
WiredHome 1:19a776ced714 65 int _cmdx(int cmd, int arg);
WiredHome 1:19a776ced714 66 int _cmd8();
WiredHome 1:19a776ced714 67 int _cmd58();
WiredHome 1:19a776ced714 68 int initialise_card();
WiredHome 1:19a776ced714 69 int initialise_card_v1();
WiredHome 1:19a776ced714 70 int initialise_card_v2();
WiredHome 1:19a776ced714 71
WiredHome 1:19a776ced714 72 int _read(char *buffer, int length);
WiredHome 1:19a776ced714 73 int _write(const char *buffer, int length);
WiredHome 1:19a776ced714 74 int _sd_sectors();
WiredHome 1:19a776ced714 75 int _sectors;
WiredHome 1:19a776ced714 76
WiredHome 1:19a776ced714 77 SPI _spi;
WiredHome 1:19a776ced714 78 DigitalOut _cs;
WiredHome 1:19a776ced714 79 };
WiredHome 1:19a776ced714 80
WiredHome 1:19a776ced714 81 #endif