SDFileSystem-Smartes

Dependents:   Demo_NucleoF4xx_SD_Card soundthing

Committer:
FelipeVR
Date:
Tue Jun 12 18:15:57 2018 +0000
Revision:
0:70ff1cadb69a
SD Smartest;

Who changed what in which revision?

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