Block access only to a SD Flash card conected via SPI. Based on SDFileSystem, but without any file system support.
SDFlashDisk.h
00001 /* 00002 * This file is derived from the standard MBED SDFileSystem.h file 00003 * The class defined here provides only low-level block access to the flash disk, with no filesystem. 00004 * 00005 * Modifications by John VanLaanen, June 2013 00006 */ 00007 00008 // Header from original file: 00009 00010 /* mbed Microcontroller Library 00011 * Copyright (c) 2006-2012 ARM Limited 00012 * 00013 * Permission is hereby granted, free of charge, to any person obtaining a copy 00014 * of this software and associated documentation files (the "Software"), to deal 00015 * in the Software without restriction, including without limitation the rights 00016 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00017 * copies of the Software, and to permit persons to whom the Software is 00018 * furnished to do so, subject to the following conditions: 00019 * 00020 * The above copyright notice and this permission notice shall be included in 00021 * all copies or substantial portions of the Software. 00022 * 00023 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00024 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00025 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00026 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00027 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00028 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00029 * SOFTWARE. 00030 */ 00031 00032 #ifndef MBED_SDFLASHDISK_H 00033 #define MBED_SDFLASHDISK_H 00034 00035 #include "mbed.h" 00036 #include <stdint.h> 00037 00038 /** Access to an SD Flash Card using SPI 00039 * 00040 * @code 00041 * #include "mbed.h" 00042 * #include "SDFlashDisk.h" 00043 * 00044 * SDFlashDisk sd(p5, p6, p7, p12); // mosi, miso, sclk, cs 00045 * 00046 * } 00047 */ 00048 class SDFlashDisk { 00049 public: 00050 00051 /** Create the object for accessing an SD Card using SPI 00052 * 00053 * @param mosi SPI mosi pin connected to SD Card 00054 * @param miso SPI miso pin conencted to SD Card 00055 * @param sclk SPI sclk pin connected to SD Card 00056 * @param cs DigitalOut pin used as SD Card chip select 00057 */ 00058 SDFlashDisk(PinName mosi, PinName miso, PinName sclk, PinName cs); 00059 virtual int disk_initialize(); 00060 virtual int disk_read(uint8_t * buffer, uint64_t block_number); 00061 virtual int disk_write(const uint8_t * buffer, uint64_t block_number); 00062 virtual uint64_t disk_sectors(); 00063 00064 protected: 00065 00066 int _cmd(int cmd, int arg); 00067 int _cmdx(int cmd, int arg); 00068 int _cmd8(); 00069 int _cmd58(); 00070 int initialise_card(); 00071 int initialise_card_v1(); 00072 int initialise_card_v2(); 00073 00074 int _read(uint8_t * buffer, uint32_t length); 00075 int _write(const uint8_t *buffer, uint32_t length); 00076 uint64_t _sd_sectors(); 00077 uint64_t _sectors; 00078 00079 SPI _spi; 00080 DigitalOut _cs; 00081 int cdv; 00082 }; 00083 00084 #endif // MBED_SDFLASHDISK_H 00085
Generated on Fri Aug 5 2022 11:52:17 by 1.7.2