edited sdio driver, todo: check crc response handling

This commit is contained in:
Mario Hüttel 2017-03-31 13:45:38 +02:00
parent b5fbdb4bb6
commit 6e5d32350c
2 changed files with 28 additions and 20 deletions

View File

@ -30,8 +30,8 @@ typedef uint8_t CID_t;
void initModuleHw();
int SDIO_sendCmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns);
int SDIO_getResp(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t* responseBuffer);
int SDIO_send_cmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns);
int SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t* responseBuffer);
void SDIO_wait_cmd_sent();
@ -225,7 +225,7 @@ void switchPrescaler(uint8_t clkdiv) {
//Send Command
//Clear respone Flags
//->CRC Fail, complete response, Timeout
int SDIO_sendCmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns){
int SDIO_send_cmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns){
//Clear Flags
SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_CMDRENDC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_CMDSENTC;
//Send command
@ -239,7 +239,7 @@ void SDIO_wait_cmd_sent() {
SDIO->ICR |= SDIO_ICR_CMDSENTC;
}
int SDIO_getResp(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;
@ -249,9 +249,8 @@ int SDIO_getResp(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffe
//Exclude ACMD41 and CMD2 from valid CRC check
if ((SDIO->STA & SDIO_STA_CCRCFAIL)) {
if(expectedCMD == 0x3f) {
//This command does not have a CRC...Doushite....
break;//Hopefully the response is correct. Even without CRC....
if(expectedCMD == 0x3f) { // TODO: This seems odd..
break;
} else
return CCRCFAIL;
}
@ -281,9 +280,9 @@ int SDIO_send_CMD55(){
uint32_t response;
do {
//Execute Command and check for valid response
SDIO_sendCmd(55, cardInfo.rca, SHORT_ANS);
SDIO_send_cmd(55, cardInfo.rca, SHORT_ANS);
if (!SDIO_getResp(55, SHORT_ANS, &response))
if (!SDIO_get_response(55, SHORT_ANS, &response))
{
//Response valid. Check if Card has accepted switch to application command mode
converter.value = response;
@ -302,8 +301,8 @@ ACMD41_RESP_t SDIO_send_ACMD41(uint8_t HCS){
do {
SDIO_sendCmd(41, (HCS ? (1<<30) : 0) | (1<<28), SHORT_ANS);
if (!SDIO_getResp(0x3F, SHORT_ANS, &response)) {
SDIO_send_cmd(41, (HCS ? (1<<30) : 0) | (1<<28), SHORT_ANS);
if (!SDIO_get_response(0x3F, SHORT_ANS, &response)) {
if (response & OCS_BUSY) { // Card is ready... Who knows why this bit is called busy...
if (response & OCS_CCS) {
return ACMD41_RESP_SDXC;
@ -326,8 +325,8 @@ int SDIO_send_CMD2() {
uint32_t response[4];
int retry = 0x20;
do {
SDIO_sendCmd(2, 0, LONG_ANS);
if (!SDIO_getResp(0x3F, LONG_ANS, response)) return 0;
SDIO_send_cmd(2, 0, LONG_ANS);
if (!SDIO_get_response(0x3F, LONG_ANS, response)) return 0;
}while(retry-- > 0);
}
@ -335,8 +334,8 @@ int SDIO_send_CMD3(uint16_t* rca) {
uint32_t response;
int retry = 0x20;
do {
SDIO_sendCmd(3, 0, SHORT_ANS);
if (!SDIO_getResp(3, SHORT_ANS, &response)) {
SDIO_send_cmd(3, 0, SHORT_ANS);
if (!SDIO_get_response(3, SHORT_ANS, &response)) {
// TODO: Do some *optional* checking
*rca = ((response & 0xFFFF0000) >> 16);
return 0;
@ -346,7 +345,7 @@ int SDIO_send_CMD3(uint16_t* rca) {
}
int SDIO_send_CMD0() {
SDIO_sendCmd(0, 0, NO_ANS);
SDIO_send_cmd(0, 0, NO_ANS);
SDIO_wait_cmd_sent();
return 0;
}
@ -356,8 +355,8 @@ CMD8_RESP_t SDIO_send_CMD8() {
int res = 0;
int retry = 0x20;
do {
SDIO_sendCmd(8, 0x1CC, SHORT_ANS);
res = SDIO_getResp(8, SHORT_ANS, &response);
SDIO_send_cmd(8, 0x1CC, SHORT_ANS);
res = SDIO_get_response(8, SHORT_ANS, &response);
if (res == 0) {
if (response & 0x100)
return CMD8_RESP_ACK;
@ -368,6 +367,9 @@ CMD8_RESP_t SDIO_send_CMD8() {
return CMD8_RESP_TIMEOUT;
}
/**
* @brief initDetectandProtectionPins
*/
void initDetectandProtectionPins() {
#if SDIO_ENABLE_WRITEPROT==1
WRITEPROT_PORT->PUPDR |= ((WRITEPROT_PULLUP ? 1 : 0)<<WRITEPROT_PIN*2);
@ -378,6 +380,10 @@ void initDetectandProtectionPins() {
__DSB();
}
/**
* @brief checkNotInserted
* @return return 0 if card is inserted, else 1
*/
int checkNotInserted() {
#if SDIO_ENABLE_INS
return ((INS_PORT->IDR & INS_PIN) == INS_ACTIVE_LEVEL ? 0 : 1);
@ -385,7 +391,10 @@ int checkNotInserted() {
return 0; // Assume Card is inserted
#endif
}
/**
* @brief checkWriteProtection
* @return 0 if card is writable.
*/
int checkWriteProtection() {
#if SDIO_ENABLE_WRITEPROT
return ((WRITEPROT_PORT->IDR & WRITEPROT_PIN) == WRITEPROT_ACTIVE_LEVEL ? 1 : 0);

1
main.c
View File

@ -20,7 +20,6 @@ int main() {
__DSB();
GPIOD->MODER = OUTPUT(12);
SysTick_Config(8*1680000);
while(1);
}