Fixed SDFileSystem when no card present (pull request).
Dependents: ILI9341_Clock_Nucleo
Fork of SDFileSystem by
Revision 5:96428c0b7119, committed 2014-02-15
- Comitter:
- Olivier
- Date:
- Sat Feb 15 11:38:55 2014 +0000
- Parent:
- 4:e3161f629541
- Commit message:
- Allow changing the default clock settings for the initialization and transfer states.
Changed in this revision
SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
SDFileSystem.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r e3161f629541 -r 96428c0b7119 SDFileSystem.cpp --- a/SDFileSystem.cpp Sat Feb 15 02:21:21 2014 +0000 +++ b/SDFileSystem.cpp Sat Feb 15 11:38:55 2014 +0000 @@ -122,6 +122,10 @@ SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) : FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0) { _cs = 1; + + // Set default to 100kHz for initialisation and 1MHz for data transfer + _init_sck = 100000; + _transfer_sck = 1000000; } #define R1_IDLE_STATE (1 << 0) @@ -143,8 +147,8 @@ #define SDCARD_V2HC 3 int SDFileSystem::initialise_card() { - // Set to 100kHz for initialisation, and clock card with cs = 1 - _spi.frequency(100000); + // Set to SCK for initialisation, and clock card with cs = 1 + _spi.frequency(_init_sck); _cs = 1; for (int i = 0; i < 16; i++) { _spi.write(0xFF); @@ -213,8 +217,9 @@ debug("Set 512-byte block timed out\n"); return 1; } - - _spi.frequency(1000000); // Set to 1MHz for data transfer + + // Set SCK for data transfer + _spi.frequency(_transfer_sck); return 0; }
diff -r e3161f629541 -r 96428c0b7119 SDFileSystem.h --- a/SDFileSystem.h Sat Feb 15 02:21:21 2014 +0000 +++ b/SDFileSystem.h Sat Feb 15 11:38:55 2014 +0000 @@ -73,7 +73,13 @@ int _write(const uint8_t *buffer, uint32_t length); uint64_t _sd_sectors(); uint64_t _sectors; - + + void set_init_sck(uint32_t sck) { _init_sck = sck; } + // Note: The highest SPI clock rate is 20 MHz for MMC and 25 MHz for SD + void set_transfer_sck(uint32_t sck) { _transfer_sck = sck; } + uint32_t _init_sck; + uint32_t _transfer_sck; + SPI _spi; DigitalOut _cs; int cdv;