edited driver, fixed crc handling
This commit is contained in:
parent
6e5d32350c
commit
a5ae7ec9a1
@ -240,16 +240,14 @@ void SDIO_wait_cmd_sent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffer) {
|
int SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffer) {
|
||||||
//Return with success because no data is needed
|
|
||||||
if (typeOfAns == NO_ANS) return 0;
|
|
||||||
|
|
||||||
//Wait for error or success
|
//Wait for error or success
|
||||||
while (1) {
|
while (1) {
|
||||||
if (SDIO->STA & SDIO_STA_CMDREND) break; //Correct Respone Received
|
if (SDIO->STA & SDIO_STA_CMDREND) break; //Correct Respone Received
|
||||||
|
if ((SDIO->STA & SDIO_STA_CMDSENT) && (typeOfAns == NO_ANS)) break; // No response required
|
||||||
|
|
||||||
//Exclude ACMD41 and CMD2 from valid CRC check
|
//Exclude ACMD41 and CMD2 from valid CRC check
|
||||||
if ((SDIO->STA & SDIO_STA_CCRCFAIL)) {
|
if ((SDIO->STA & SDIO_STA_CCRCFAIL)) {
|
||||||
if(expectedCMD == 0x3f) { // TODO: This seems odd..
|
if(expectedCMD == 0xff) { // TODO: This seems odd..
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
return CCRCFAIL;
|
return CCRCFAIL;
|
||||||
@ -260,7 +258,8 @@ int SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *response
|
|||||||
return CTIMEOUT;
|
return CTIMEOUT;
|
||||||
}
|
}
|
||||||
//Valid Respone Received
|
//Valid Respone Received
|
||||||
if ((SDIO->RESPCMD & SDIO_RESPCMD_RESPCMD) != expectedCMD) return -1; //Not the expected respose
|
if (((SDIO->RESPCMD & SDIO_RESPCMD_RESPCMD) != expectedCMD) && expectedCMD != 0xff)
|
||||||
|
return -1; //Not the expected respose
|
||||||
|
|
||||||
//If case of a correct Response
|
//If case of a correct Response
|
||||||
*(responseBuffer++) = SDIO->RESP1;
|
*(responseBuffer++) = SDIO->RESP1;
|
||||||
@ -302,7 +301,7 @@ ACMD41_RESP_t SDIO_send_ACMD41(uint8_t HCS){
|
|||||||
do {
|
do {
|
||||||
|
|
||||||
SDIO_send_cmd(41, (HCS ? (1<<30) : 0) | (1<<28), SHORT_ANS);
|
SDIO_send_cmd(41, (HCS ? (1<<30) : 0) | (1<<28), SHORT_ANS);
|
||||||
if (!SDIO_get_response(0x3F, SHORT_ANS, &response)) {
|
if (!SDIO_get_response(0xFF, SHORT_ANS, &response)) {
|
||||||
if (response & OCS_BUSY) { // Card is ready... Who knows why this bit is called busy...
|
if (response & OCS_BUSY) { // Card is ready... Who knows why this bit is called busy...
|
||||||
if (response & OCS_CCS) {
|
if (response & OCS_CCS) {
|
||||||
return ACMD41_RESP_SDXC;
|
return ACMD41_RESP_SDXC;
|
||||||
@ -326,7 +325,7 @@ int SDIO_send_CMD2() {
|
|||||||
int retry = 0x20;
|
int retry = 0x20;
|
||||||
do {
|
do {
|
||||||
SDIO_send_cmd(2, 0, LONG_ANS);
|
SDIO_send_cmd(2, 0, LONG_ANS);
|
||||||
if (!SDIO_get_response(0x3F, LONG_ANS, response)) return 0;
|
if (!SDIO_get_response(0xFF, LONG_ANS, response)) return 0;
|
||||||
}while(retry-- > 0);
|
}while(retry-- > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user