@@ -690,7 +690,12 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
690
690
for (int i = 0 ; i < 3 ; i++) {
691
691
// Send CMD55 for APP command first
692
692
if (isAcmd) {
693
- _cmd_spi (CMD55_APP_CMD, 0x0 );
693
+ response = _cmd_spi (CMD55_APP_CMD, 0x0 );
694
+ }
695
+
696
+ // Wait for card to be ready after CMD55
697
+ if (false == _wait_ready (SD_COMMAND_TIMEOUT)) {
698
+ debug_if (SD_DBG, " Card not ready yet \n " );
694
699
}
695
700
696
701
// Send command over SPI interface
@@ -710,20 +715,20 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
710
715
// Process the response R1 : Exit on CRC/Illegal command error/No response
711
716
if (R1_NO_RESPONSE == response) {
712
717
_deselect ();
713
- debug_if (SD_DBG, " No response CMD:%d \n " , cmd);
718
+ debug_if (SD_DBG, " No response CMD:%d response: 0x%x \n " ,cmd, response );
714
719
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE; // No device
715
720
}
716
721
if (response & R1_COM_CRC_ERROR) {
717
722
_deselect ();
718
- debug_if (SD_DBG, " CRC error CMD:%d \n " , cmd);
723
+ debug_if (SD_DBG, " CRC error CMD:%d response 0x%x \n " ,cmd, response );
719
724
return SD_BLOCK_DEVICE_ERROR_CRC; // CRC error
720
725
}
721
726
if (response & R1_ILLEGAL_COMMAND) {
722
- debug_if (SD_DBG, " Illegal command CMD:%d\n " , cmd);
727
+ _deselect ();
728
+ debug_if (SD_DBG, " Illegal command CMD:%d response 0x%x\n " ,cmd, response);
723
729
if (CMD8_SEND_IF_COND == cmd) { // Illegal command is for Ver1 or not SD Card
724
730
_card_type = CARD_UNKNOWN;
725
731
}
726
- _deselect ();
727
732
return SD_BLOCK_DEVICE_ERROR_UNSUPPORTED; // Command not supported
728
733
}
729
734
@@ -1024,4 +1029,5 @@ void SDBlockDevice::_deselect() {
1024
1029
_cs = 1 ;
1025
1030
_spi.unlock ();
1026
1031
}
1032
+
1027
1033
#endif /* DEVICE_SPI */
0 commit comments