Merge pull request #167 from oliviermartin/om/sd-change-default-clock-settings

libraries/sd: Allow changing the default clock settings for the initialization and transfer states.
pull/173/head
Emilio Monti 2014-02-18 10:45:22 +00:00
commit 7d21ccaf0d
2 changed files with 16 additions and 5 deletions

View File

@ -122,6 +122,10 @@
SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) : SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) :
FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs) { FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs) {
_cs = 1; _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) #define R1_IDLE_STATE (1 << 0)
@ -143,8 +147,8 @@ SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs,
#define SDCARD_V2HC 3 #define SDCARD_V2HC 3
int SDFileSystem::initialise_card() { int SDFileSystem::initialise_card() {
// Set to 100kHz for initialisation, and clock card with cs = 1 // Set to SCK for initialisation, and clock card with cs = 1
_spi.frequency(100000); _spi.frequency(_init_sck);
_cs = 1; _cs = 1;
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
_spi.write(0xFF); _spi.write(0xFF);
@ -209,8 +213,9 @@ int SDFileSystem::disk_initialize() {
debug("Set 512-byte block timed out\n"); debug("Set 512-byte block timed out\n");
return 1; return 1;
} }
_spi.frequency(1000000); // Set to 1MHz for data transfer // Set SCK for data transfer
_spi.frequency(_transfer_sck);
return 0; return 0;
} }

View File

@ -73,7 +73,13 @@ protected:
int _write(const uint8_t *buffer, uint32_t length); int _write(const uint8_t *buffer, uint32_t length);
uint64_t _sd_sectors(); uint64_t _sd_sectors();
uint64_t _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; SPI _spi;
DigitalOut _cs; DigitalOut _cs;
int cdv; int cdv;