@@ -697,7 +697,12 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
697
697
for (int i = 0 ; i < 3 ; i++) {
698
698
// Send CMD55 for APP command first
699
699
if (isAcmd) {
700
- _cmd_spi (CMD55_APP_CMD, 0x0 );
700
+ response = _cmd_spi (CMD55_APP_CMD, 0x0 );
701
+ }
702
+
703
+ // Wait for card to be ready after CMD55
704
+ if (false == _wait_ready (SD_COMMAND_TIMEOUT)) {
705
+ debug_if (SD_DBG, " Card not ready yet \n " );
701
706
}
702
707
703
708
// Send command over SPI interface
@@ -717,20 +722,20 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
717
722
// Process the response R1 : Exit on CRC/Illegal command error/No response
718
723
if (R1_NO_RESPONSE == response) {
719
724
_deselect ();
720
- debug_if (SD_DBG, " No response CMD:%d \n " , cmd);
725
+ debug_if (SD_DBG, " No response CMD:%d response: 0x%x \n " ,cmd, response );
721
726
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE; // No device
722
727
}
723
728
if (response & R1_COM_CRC_ERROR) {
724
729
_deselect ();
725
- debug_if (SD_DBG, " CRC error CMD:%d \n " , cmd);
730
+ debug_if (SD_DBG, " CRC error CMD:%d response 0x%x \n " ,cmd, response );
726
731
return SD_BLOCK_DEVICE_ERROR_CRC; // CRC error
727
732
}
728
733
if (response & R1_ILLEGAL_COMMAND) {
729
- debug_if (SD_DBG, " Illegal command CMD:%d\n " , cmd);
734
+ _deselect ();
735
+ debug_if (SD_DBG, " Illegal command CMD:%d response 0x%x\n " ,cmd, response);
730
736
if (CMD8_SEND_IF_COND == cmd) { // Illegal command is for Ver1 or not SD Card
731
737
_card_type = CARD_UNKNOWN;
732
738
}
733
- _deselect ();
734
739
return SD_BLOCK_DEVICE_ERROR_UNSUPPORTED; // Command not supported
735
740
}
736
741
@@ -1031,4 +1036,5 @@ void SDBlockDevice::_deselect() {
1031
1036
_cs = 1 ;
1032
1037
_spi.unlock ();
1033
1038
}
1039
+
1034
1040
#endif /* DEVICE_SPI */
0 commit comments