Mark Schwarzer / SDFileSystem_A8
Committer:
markschwarzer
Date:
Tue Nov 17 20:28:59 2020 +0000
Revision:
0:a9d72fcb5d03
logs gps data to SD card

Who changed what in which revision?

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