USBMSD SD card Hello World for Mbed platforms
Dependencies: mbed USBMSD_SD USBDevice
USBDevice/USBMSD/USB_SDcard.h@6:126c4d980196, 2011-11-14 (annotated)
- Committer:
- samux
- Date:
- Mon Nov 14 10:00:07 2011 +0000
- Revision:
- 6:126c4d980196
- Parent:
- 4:980e6470dcce
now we have a connect inside USBMSD to get all capacities from storage chip
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
4:980e6470dcce | 1 | /* mbed USB_SDcard Library, for accessing SD cards |
samux |
4:980e6470dcce | 2 | * Copyright (c) 2008-2010, sford |
samux |
4:980e6470dcce | 3 | * |
samux |
4:980e6470dcce | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
samux |
4:980e6470dcce | 5 | * of this software and associated documentation files (the "Software"), to deal |
samux |
4:980e6470dcce | 6 | * in the Software without restriction, including without limitation the rights |
samux |
4:980e6470dcce | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
samux |
4:980e6470dcce | 8 | * copies of the Software, and to permit persons to whom the Software is |
samux |
4:980e6470dcce | 9 | * furnished to do so, subject to the following conditions: |
samux |
4:980e6470dcce | 10 | * |
samux |
4:980e6470dcce | 11 | * The above copyright notice and this permission notice shall be included in |
samux |
4:980e6470dcce | 12 | * all copies or substantial portions of the Software. |
samux |
4:980e6470dcce | 13 | * |
samux |
4:980e6470dcce | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
samux |
4:980e6470dcce | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
samux |
4:980e6470dcce | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
samux |
4:980e6470dcce | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
samux |
4:980e6470dcce | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
samux |
4:980e6470dcce | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
samux |
4:980e6470dcce | 20 | * THE SOFTWARE. |
samux |
4:980e6470dcce | 21 | */ |
samux |
4:980e6470dcce | 22 | |
samux |
4:980e6470dcce | 23 | #ifndef USB_SDCARD_H |
samux |
4:980e6470dcce | 24 | #define USB_SDCARD_H |
samux |
4:980e6470dcce | 25 | |
samux |
4:980e6470dcce | 26 | #include "mbed.h" |
samux |
4:980e6470dcce | 27 | #include "USBMSD.h" |
samux |
4:980e6470dcce | 28 | |
samux |
4:980e6470dcce | 29 | class USB_SDcard : public USBMSD { |
samux |
4:980e6470dcce | 30 | public: |
samux |
4:980e6470dcce | 31 | |
samux |
4:980e6470dcce | 32 | /** Create the File System for accessing an SD Card using SPI |
samux |
4:980e6470dcce | 33 | * |
samux |
4:980e6470dcce | 34 | * @param mosi SPI mosi pin connected to SD Card |
samux |
4:980e6470dcce | 35 | * @param miso SPI miso pin conencted to SD Card |
samux |
4:980e6470dcce | 36 | * @param sclk SPI sclk pin connected to SD Card |
samux |
4:980e6470dcce | 37 | * @param cs DigitalOut pin used as SD Card chip select |
samux |
4:980e6470dcce | 38 | */ |
samux |
4:980e6470dcce | 39 | USB_SDcard(PinName mosi = p5, PinName miso = p6, PinName sclk = p7, PinName cs = p8); |
samux |
4:980e6470dcce | 40 | |
samux |
4:980e6470dcce | 41 | /* |
samux |
4:980e6470dcce | 42 | * read a block on a storage chip |
samux |
4:980e6470dcce | 43 | * |
samux |
4:980e6470dcce | 44 | * @param data pointer where will be stored read data |
samux |
4:980e6470dcce | 45 | * @param block block number |
samux |
4:980e6470dcce | 46 | * @returns 0 if successful |
samux |
4:980e6470dcce | 47 | */ |
samux |
4:980e6470dcce | 48 | virtual int blockRead(uint8_t * data, uint16_t block); |
samux |
4:980e6470dcce | 49 | |
samux |
4:980e6470dcce | 50 | /* |
samux |
4:980e6470dcce | 51 | * write a block on a storage chip |
samux |
4:980e6470dcce | 52 | * |
samux |
4:980e6470dcce | 53 | * @param data data to write |
samux |
4:980e6470dcce | 54 | * @param block block number |
samux |
4:980e6470dcce | 55 | * @returns 0 if successful |
samux |
4:980e6470dcce | 56 | */ |
samux |
4:980e6470dcce | 57 | virtual int blockWrite(uint8_t * data, uint16_t block); |
samux |
6:126c4d980196 | 58 | |
samux |
6:126c4d980196 | 59 | virtual int diskInit(); |
samux |
6:126c4d980196 | 60 | virtual uint16_t blockSize(); |
samux |
6:126c4d980196 | 61 | virtual uint32_t memorySize(); |
samux |
4:980e6470dcce | 62 | |
samux |
4:980e6470dcce | 63 | protected: |
samux |
4:980e6470dcce | 64 | |
samux |
4:980e6470dcce | 65 | int disk_status(); |
samux |
4:980e6470dcce | 66 | int disk_sync(); |
samux |
4:980e6470dcce | 67 | int disk_sectors(); |
samux |
4:980e6470dcce | 68 | int _cmd(int cmd, int arg); |
samux |
4:980e6470dcce | 69 | int _cmdx(int cmd, int arg); |
samux |
4:980e6470dcce | 70 | int _cmd8(); |
samux |
4:980e6470dcce | 71 | int _cmd58(); |
samux |
4:980e6470dcce | 72 | int initialise_card(); |
samux |
4:980e6470dcce | 73 | int initialise_card_v1(); |
samux |
4:980e6470dcce | 74 | int initialise_card_v2(); |
samux |
4:980e6470dcce | 75 | |
samux |
4:980e6470dcce | 76 | int _read(char *buffer, int length); |
samux |
4:980e6470dcce | 77 | int _write(const char *buffer, int length); |
samux |
4:980e6470dcce | 78 | int _sd_sectors(); |
samux |
4:980e6470dcce | 79 | int _sectors; |
samux |
6:126c4d980196 | 80 | int capacity; |
samux |
6:126c4d980196 | 81 | int block_len; |
samux |
4:980e6470dcce | 82 | |
samux |
4:980e6470dcce | 83 | SPI _spi; |
samux |
4:980e6470dcce | 84 | DigitalOut _cs; |
samux |
4:980e6470dcce | 85 | }; |
samux |
4:980e6470dcce | 86 | |
samux |
4:980e6470dcce | 87 | #endif |