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: GloboMetereologico
Fork of SDFileSystem by
Diff: SDFileSystem.cpp
- Revision:
- 23:6bb3c1987511
- Parent:
- 22:3fa5eaf48e81
- Child:
- 24:a52e682a1ce4
--- a/SDFileSystem.cpp Wed Feb 24 17:46:31 2016 +0000
+++ b/SDFileSystem.cpp Wed Apr 13 16:51:25 2016 +0000
@@ -222,11 +222,20 @@
else
m_CardType = CARD_SD;
- //Increase the SPI frequency to full speed (up to 25MHz for SDCv2)
- if (m_FREQ > 25000000)
- m_Spi.frequency(25000000);
- else
+ //Increase the SPI frequency to full speed (up to 50MHz for SDCv2)
+ if (m_FREQ > 25000000) {
+ if (enableHighSpeedMode()) {
+ if (m_FREQ > 50000000) {
+ m_Spi.frequency(50000000);
+ } else {
+ m_Spi.frequency(m_FREQ);
+ }
+ } else {
+ m_Spi.frequency(25000000);
+ }
+ } else {
m_Spi.frequency(m_FREQ);
+ }
} else {
//Initialization failed
m_CardType = CARD_UNKNOWN;
@@ -883,3 +892,32 @@
deselect();
return false;
}
+
+bool SDFileSystem::enableHighSpeedMode()
+{
+ //Try to issue CMD6 up to 3 times
+ for (int f = 0; f < 3; f++) {
+ //Select the card, and wait for ready
+ if(!select())
+ break;
+
+ //Send CMD6(0x80FFFFF1) to change the access mode to high speed
+ if (writeCommand(CMD6, 0x80FFFFF1) == 0x00) {
+ //Read the 64B status data block
+ char status[64];
+ bool success = readData(status, 64);
+ deselect();
+ if (success) {
+ //Return whether or not the operation was successful
+ return ((status[16] & 0x0F) == 0x1);
+ }
+ } else {
+ //The command failed, get out
+ break;
+ }
+ }
+
+ //The operation failed 3 times
+ deselect();
+ return false;
+}
