Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Lab8_USB-MSD_RAM_HelloWorld_mbed
Fork of USBMSD_SD by
USBMSD_SD.h@4:a4423c624fed, 2014-03-26 (annotated)
- Committer:
- jakowisp
- Date:
- Wed Mar 26 07:01:02 2014 +0000
- Revision:
- 4:a4423c624fed
- Parent:
- 3:dbd7383533e6
USBMSD_SRAM;
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| samux | 0:de50a209c5a9 | 1 | /* mbed USBMSD_SD Library, for providing file access to SD cards | 
| samux | 0:de50a209c5a9 | 2 | * Copyright (c) 2008-2010, sford | 
| samux | 0:de50a209c5a9 | 3 | * | 
| samux | 0:de50a209c5a9 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 
| samux | 0:de50a209c5a9 | 5 | * of this software and associated documentation files (the "Software"), to deal | 
| samux | 0:de50a209c5a9 | 6 | * in the Software without restriction, including without limitation the rights | 
| samux | 0:de50a209c5a9 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
| samux | 0:de50a209c5a9 | 8 | * copies of the Software, and to permit persons to whom the Software is | 
| samux | 0:de50a209c5a9 | 9 | * furnished to do so, subject to the following conditions: | 
| samux | 0:de50a209c5a9 | 10 | * | 
| samux | 0:de50a209c5a9 | 11 | * The above copyright notice and this permission notice shall be included in | 
| samux | 0:de50a209c5a9 | 12 | * all copies or substantial portions of the Software. | 
| samux | 0:de50a209c5a9 | 13 | * | 
| samux | 0:de50a209c5a9 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| samux | 0:de50a209c5a9 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| samux | 0:de50a209c5a9 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
| samux | 0:de50a209c5a9 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
| samux | 0:de50a209c5a9 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| samux | 0:de50a209c5a9 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
| samux | 0:de50a209c5a9 | 20 | * THE SOFTWARE. | 
| samux | 0:de50a209c5a9 | 21 | */ | 
| samux | 0:de50a209c5a9 | 22 | |
| samux | 0:de50a209c5a9 | 23 | #ifndef USBMSD_SD_H | 
| samux | 0:de50a209c5a9 | 24 | #define USBMSD_SD_H | 
| samux | 0:de50a209c5a9 | 25 | |
| samux | 0:de50a209c5a9 | 26 | #include "mbed.h" | 
| samux | 0:de50a209c5a9 | 27 | #include "USBMSD.h" | 
| samux | 0:de50a209c5a9 | 28 | |
| samux | 0:de50a209c5a9 | 29 | /** Use the SDcard as mass storage device using the USBMSD class | 
| samux | 0:de50a209c5a9 | 30 | * | 
| samux | 0:de50a209c5a9 | 31 | * @code | 
| samux | 0:de50a209c5a9 | 32 | * #include "mbed.h" | 
| samux | 0:de50a209c5a9 | 33 | * #include "USBMSD_SD.h" | 
| samux | 0:de50a209c5a9 | 34 | * | 
| samux | 0:de50a209c5a9 | 35 | * USBMSD_SD sd(p5, p6, p7, p8); | 
| samux | 0:de50a209c5a9 | 36 | * | 
| samux | 0:de50a209c5a9 | 37 | * int main() { | 
| samux | 0:de50a209c5a9 | 38 | * while(1); | 
| samux | 0:de50a209c5a9 | 39 | * } | 
| samux | 0:de50a209c5a9 | 40 | * | 
| samux | 0:de50a209c5a9 | 41 | * @endcode | 
| samux | 0:de50a209c5a9 | 42 | */ | 
| samux | 0:de50a209c5a9 | 43 | class USBMSD_SD : public USBMSD { | 
| samux | 0:de50a209c5a9 | 44 | public: | 
| samux | 0:de50a209c5a9 | 45 | |
| samux | 0:de50a209c5a9 | 46 | /** Create the File System for accessing an SD Card using SPI | 
| samux | 0:de50a209c5a9 | 47 | * | 
| samux | 0:de50a209c5a9 | 48 | * @param mosi SPI mosi pin connected to SD Card | 
| samux | 0:de50a209c5a9 | 49 | * @param miso SPI miso pin conencted to SD Card | 
| samux | 0:de50a209c5a9 | 50 | * @param sclk SPI sclk pin connected to SD Card | 
| samux | 0:de50a209c5a9 | 51 | * @param cs DigitalOut pin used as SD Card chip select | 
| samux | 0:de50a209c5a9 | 52 | * @param name The name used to access the virtual filesystem | 
| samux | 0:de50a209c5a9 | 53 | */ | 
| samux | 0:de50a209c5a9 | 54 | USBMSD_SD(PinName mosi, PinName miso, PinName sclk, PinName cs); | 
| samux | 0:de50a209c5a9 | 55 | virtual int disk_initialize(); | 
| samux | 0:de50a209c5a9 | 56 | virtual int disk_status(); | 
| samux | 2:055119ccf5a7 | 57 | virtual int disk_read(uint8_t * buffer, uint64_t block_number); | 
| samux | 2:055119ccf5a7 | 58 | virtual int disk_write(const uint8_t * buffer, uint64_t block_number); | 
| samux | 0:de50a209c5a9 | 59 | virtual int disk_sync(); | 
| samux | 2:055119ccf5a7 | 60 | virtual uint64_t disk_sectors(); | 
| samux | 2:055119ccf5a7 | 61 | |
| avnisha | 3:dbd7383533e6 | 62 | //virtual uint64_t disk_size(){return _sectors*512;}; | 
| avnisha | 3:dbd7383533e6 | 63 | virtual uint64_t disk_size(); | 
| samux | 0:de50a209c5a9 | 64 | |
| samux | 0:de50a209c5a9 | 65 | protected: | 
| samux | 0:de50a209c5a9 | 66 | |
| samux | 0:de50a209c5a9 | 67 | int _cmd(int cmd, int arg); | 
| samux | 0:de50a209c5a9 | 68 | int _cmdx(int cmd, int arg); | 
| samux | 0:de50a209c5a9 | 69 | int _cmd8(); | 
| samux | 0:de50a209c5a9 | 70 | int _cmd58(); | 
| samux | 0:de50a209c5a9 | 71 | int initialise_card(); | 
| samux | 0:de50a209c5a9 | 72 | int initialise_card_v1(); | 
| samux | 0:de50a209c5a9 | 73 | int initialise_card_v2(); | 
| samux | 0:de50a209c5a9 | 74 | |
| samux | 2:055119ccf5a7 | 75 | int _read(uint8_t * buffer, uint32_t length); | 
| samux | 2:055119ccf5a7 | 76 | int _write(const uint8_t *buffer, uint32_t length); | 
| samux | 2:055119ccf5a7 | 77 | uint64_t _sd_sectors(); | 
| samux | 2:055119ccf5a7 | 78 | uint64_t _sectors; | 
| samux | 0:de50a209c5a9 | 79 | |
| samux | 2:055119ccf5a7 | 80 | uint8_t _status; | 
| samux | 0:de50a209c5a9 | 81 | |
| samux | 0:de50a209c5a9 | 82 | SPI _spi; | 
| samux | 0:de50a209c5a9 | 83 | DigitalOut _cs; | 
| samux | 2:055119ccf5a7 | 84 | int cdv; | 
| samux | 0:de50a209c5a9 | 85 | }; | 
| samux | 0:de50a209c5a9 | 86 | |
| samux | 0:de50a209c5a9 | 87 | #endif | 
