Browse Source

Fix detection of old SD cards on Teensy 3.5 & 3.6

main
PaulStoffregen 8 years ago
parent
commit
36ea5fac57
1 changed files with 21 additions and 7 deletions
  1. +21
    -7
      utility/KinetisSDHC.c

+ 21
- 7
utility/KinetisSDHC.c View File

#if defined(__MK64FX512__) || defined(__MK66FX1M0__) #if defined(__MK64FX512__) || defined(__MK66FX1M0__)


#include "kinetis.h" #include "kinetis.h"
#include "core_pins.h" // testing only
//#include "core_pins.h" // testing only
//#include "HardwareSerial.h" // testing only


// Missing in Teensyduino 1.30 // Missing in Teensyduino 1.30
#ifndef MPU_CESR_VLD_MASK #ifndef MPU_CESR_VLD_MASK
SDHC_RESULT_NO_RESPONSE /* 5: No Response */ // from old diskio.h SDHC_RESULT_NO_RESPONSE /* 5: No Response */ // from old diskio.h
}; };


/*void print_result(int n)
{
switch (n) {
case SDHC_RESULT_OK: serial_print("OK\n"); break;
case SDHC_RESULT_ERROR: serial_print("R/W Error\n"); break;
case SDHC_RESULT_WRPRT: serial_print("Write Protect\n"); break;
case SDHC_RESULT_NOT_READY: serial_print("Not Ready\n"); break;
case SDHC_RESULT_PARERR: serial_print("Invalid Param\n"); break;
case SDHC_RESULT_NO_RESPONSE: serial_print("No Response\n"); break;
default: serial_print("Unknown result\n");
}
}*/

#define SDHC_STATUS_NOINIT 0x01 /* Drive not initialized */ #define SDHC_STATUS_NOINIT 0x01 /* Drive not initialized */
#define SDHC_STATUS_NODISK 0x02 /* No medium in the drive */ #define SDHC_STATUS_NODISK 0x02 /* No medium in the drive */
#define SDHC_STATUS_PROTECT 0x04 /* Write protected */ #define SDHC_STATUS_PROTECT 0x04 /* Write protected */
} }


resR = SDHC_CMD8_SetInterface(0x000001AA); // 3.3V and AA check pattern resR = SDHC_CMD8_SetInterface(0x000001AA); // 3.3V and AA check pattern
if (resR > 0) {
sdCardDesc.status = SDHC_STATUS_NOINIT;
return SDHC_STATUS_NOINIT;
}

if (resR == 0) {
if (resR == SDHC_RESULT_OK) {
if (SDHC_CMDRSP0 != 0x000001AA) { if (SDHC_CMDRSP0 != 0x000001AA) {
sdCardDesc.status = SDHC_STATUS_NOINIT; sdCardDesc.status = SDHC_STATUS_NOINIT;
return SDHC_STATUS_NOINIT; return SDHC_STATUS_NOINIT;
} }
sdCardDesc.highCapacity = 1; sdCardDesc.highCapacity = 1;
} else if (resR == SDHC_RESULT_NO_RESPONSE) {
// version 1 cards do not respond to CMD8
} else {
sdCardDesc.status = SDHC_STATUS_NOINIT;
return SDHC_STATUS_NOINIT;
} }


if (SDHC_ACMD41_SendOperationCond(0)) { if (SDHC_ACMD41_SendOperationCond(0)) {

Loading…
Cancel
Save