Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: betovar/libmaple
...
head fork: betovar/libmaple
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
58 libraries/Card/SecureDigital/Commands.h
@@ -191,4 +191,62 @@ typedef enum SDIOAppCommand {
/** ACMD52-59 - Reserved */
} SDIOAppCommand;
+typedef enum SDIOStatusResponseTag {
+ //CardStatusResponse Tags
+ SDIO_CSR_NO_ERROR = 0,
+ SDIO_CSR_ERROR = 1,
+ SDIO_CSR_NOT_PROTECTED = 0,
+ SDIO_CSR_PROTECTED = 1,
+ SDIO_CSR_CARD_UNLOCKED = 0,
+ SDIO_CSR_CARD_LOCKED = 1,
+ SDIO_CSR_SUCCESS = 0,
+ SDIO_CSR_FAILURE = 1,
+ SDIO_CSR_ECC_ENABLED = 0,
+ SDIO_CSR_ECC_DISABLED = 1,
+ SDIO_CSR_CLEARED = 0,
+ SDIO_CSR_SET = 1,
+ SDIO_CSR_IDLE = 0,
+ SDIO_CSR_NOT_READY = 0,
+ SDIO_CSR_READY = 1,
+ SDIO_CSR_IDENT = 2,
+ SDIO_CSR_STBY = 3,
+ SDIO_CSR_TRAN = 4,
+ SDIO_CSR_DATA = 5,
+ SDIO_CSR_RCV = 6,
+ SDIO_CSR_PRG = 7,
+ SDIO_CSR_DIS = 8,
+ SDIO_CSR_IO_MODE = 15,
+ SDIO_CSR_APP_DISABLED = 0,
+ SDIO_CSR_APP_ENABLED = 1,
+ //SdStatusResponse Tags
+ SDIO_SSR_1BIT_WIDTH = 0,
+ SDIO_SSR_4BIT_WIDTH = 2,
+ SDIO_SSR_NOT_SECURED = 0,
+ SDIO_SSR_SECURED = 1,
+ SDIO_SSR_REG_CARD = 0,
+ SDIO_SSR_ROM_CARD = 1,
+ SDIO_SSR_OTP_CARD = 2,
+ SDIO_SSR_SPEED_CLASS_0 = 0,
+ SDIO_SSR_SPEED_CLASS_2 = 1,
+ SDIO_SSR_SPEED_CLASS_4 = 2,
+ SDIO_SSR_SPEED_CLASS_6 = 3,
+ SDIO_SSR_SPEED_CLASS_10 = 4,
+ SDIO_SSR_AU_SIZE_NOT_DEF = 0,
+ SDIO_SSR_AU_SIZE_16KB = 1,
+ SDIO_SSR_AU_SIZE_32KB = 2,
+ SDIO_SSR_AU_SIZE_64KB = 3,
+ SDIO_SSR_AU_SIZE_128KB = 4,
+ SDIO_SSR_AU_SIZE_256KB = 5,
+ SDIO_SSR_AU_SIZE_512KB = 6,
+ SDIO_SSR_AU_SIZE_1MB = 7,
+ SDIO_SSR_AU_SIZE_2MB = 8,
+ SDIO_SSR_AU_SIZE_4MB = 9,
+ SDIO_SSR_AU_SIZE_8MB = 10,
+ SDIO_SSR_AU_SIZE_12MB = 11,
+ SDIO_SSR_AU_SIZE_16MB = 12,
+ SDIO_SSR_AU_SIZE_24MB = 13,
+ SDIO_SSR_AU_SIZE_32MB = 14,
+ SDIO_SSR_AU_SIZE_64MB = 15,
+} SDIOStatusResponseTag;
+
#endif
View
84 libraries/Card/SecureDigital/SDMC.cpp
@@ -38,7 +38,8 @@
#define SDIO_SDXC_POWER_CONTROL (0x1 << 28)
#define SDIO_SWITCH_1V8_REQUEST (0x1 << 24) //Not allowed on STM32
#define SDIO_CHECK_PATTERN 0xAA //Recommended but not fixed
-#define SDIO_HOST_SUPPLY_VOLTAGE (0x1 << 8)
+#define SDIO_VOLTAGE_SUPPLIED 0x1
+#define SDIO_HOST_SUPPLY_VOLTAGE (SDIO_VOLTAGE_SUPPLIED << 8)
#if CYCLES_PER_MICROSECOND != 72
/* TODO [0.2.0?] something smarter than this */
@@ -73,41 +74,37 @@ void SecureDigitalMemoryCard::end(void) {
/**
* @brief Card Initialization and Identification Flow (SD mode)
*/
-void SecureDigitalMemoryCard::test(void) {
- if (sdio_card_detect()) {
- SerialUSB.println("SDIO_DBG: Card detected");
- } else {
- SerialUSB.println("SDIO_DBG: Card not detected");
- }
-}
-/**
- * @brief Card Initialization and Identification Flow (SD mode)
- */
void SecureDigitalMemoryCard::init(void) {
+ SerialUSB.println("SDIO_DBG: Initializing card");
if (sdio_card_detect()) {
SerialUSB.println("SDIO_DBG: Card detected");
} else {
- SerialUSB.println("SDIO_DBG: Card not detected");
+ SerialUSB.println("SDIO_ERR: Card not detected");
+ return;
}
sdio_power_on(this->sdio_d);
- sdio_clock_enable(this->sdio_d);
SerialUSB.println("SDIO_DBG: Powered on");
delay(1);
+ SerialUSB.println("SDIO_DBG: Sending CMD0");
this->cmd(GO_IDLE_STATE); //CMD0
- sdio_clear_interrupt(this->sdio_d, ~SDIO_ICR_RESERVED);
- SerialUSB.println("SDIO_DBG: Idle state reached");
- icr R7;
+ //sdio_clear_interrupt(this->sdio_d, ~SDIO_ICR_RESERVED);
+ SerialUSB.println("SDIO_DBG: Card in idle state");
+ icr status;
CSD.version = CSD_UNDEFINED;
+ SerialUSB.println("SDIO_DBG: Sending CMD8");
this->cmd(SEND_IF_COND, //CMD8
SDIO_HOST_SUPPLY_VOLTAGE | SDIO_CHECK_PATTERN,
SDIO_WRSP_SHRT,
- (uint32*)&R7);
- SerialUSB.println("SDIO_DBG: Interface condition checked");
+ (uint32*)&status);
uint32 arg;
if (sdio_get_status(this->sdio_d, SDIO_STA_CMDREND)) {
- if ((R7.CHECK_PATTERN != SDIO_CHECK_PATTERN) |
- (R7.VOLTAGE_ACCEPTED != SDIO_HOST_SUPPLY_VOLTAGE)) {
- SerialUSB.println("SDIO_ERR: Unusuable Card");
+ if ((status.CHECK_PATTERN != SDIO_CHECK_PATTERN) ||
+ (status.VOLTAGE_ACCEPTED != SDIO_VOLTAGE_SUPPLIED)) {
+ SerialUSB.println("SDIO_ERR: Unusuable Card,");
+ SerialUSB.print(" Check pattern ");
+ SerialUSB.println(status.CHECK_PATTERN, HEX);
+ SerialUSB.print(" Accepted voltage ");
+ SerialUSB.println(status.VOLTAGE_ACCEPTED, BIN);
return;
}
arg = SDIO_HOST_CAPACITY_SUPPORT;
@@ -117,6 +114,7 @@ void SecureDigitalMemoryCard::init(void) {
//prob version 1.x memory card
CSD.version = CSD_VERSION1;
}
+ SerialUSB.println("SDIO_DBG: Sending inquiry ACMD41");
this->acmd(SD_SEND_OP_COND, //ACMD41: inquiry ACMD41
arg,
SDIO_WRSP_SHRT,
@@ -139,6 +137,7 @@ void SecureDigitalMemoryCard::init(void) {
//version 2.00 or later High/Ext Capacity
CSD.version = CSD_VERSION2;
}
+ SerialUSB.println("SDIO_DBG: Interface condition check passed");
/** Voltage Switch not supported
if (OCR.S18A == 1) {
this->cmd(VOLTAGE_SWITCH, 0, //CMD11
@@ -151,6 +150,7 @@ void SecureDigitalMemoryCard::init(void) {
SDIO_WRSP_SHRT, (uint32*)&this->RCA);
this->getCSD();
//this->getSCR();
+ SerialUSB.println("SDIO_DBG: Initialization complete");
}
/**
@@ -180,7 +180,7 @@ void SecureDigitalMemoryCard::blockSize(SDIOBlockSize size) {
this->cmd(SET_BLOCKLEN, (0x1 << size),
SDIO_WRSP_SHRT, (uint32*)&status);
if (status.ERROR == SDIO_CSR_ERROR) {
- SerialUSB.println("SDIO_ERR: error in SET_BLOCKLEN respsonse");
+ SerialUSB.println("SDIO_ERR: Error in SET_BLOCKLEN respsonse");
}
}
@@ -218,29 +218,28 @@ void SecureDigitalMemoryCard::cmd(SDIOCommand cmd,
SDIOWaitResp wrsp,
uint32 *resp) {
sdio_clear_interrupt(this->sdio_d, ~SDIO_ICR_RESERVED);
- sdio_cfg_interrupt(this->sdio_d, //SDIO_MASK_CMDACTIE |
+ sdio_cfg_interrupt(this->sdio_d, SDIO_MASK_CMDACTIE |
SDIO_MASK_CMDSENTIE | SDIO_MASK_CMDRENDIE |
SDIO_MASK_CTIMEOUTIE | SDIO_MASK_CCRCFAILIE, 2);
sdio_load_arg(this->sdio_d, arg);
+ sdio_clock_enable(this->sdio_d);
sdio_send_cmd(this->sdio_d, (wrsp << SDIO_CMD_WAITRESP_BIT) | cmd |
SDIO_CMD_CPSMEN | SDIO_CMD_IEN);
- if (sdio_get_status(this->sdio_d, SDIO_STA_CMDACT)) {
+ if (sdio_is_cmd_act(this->sdio_d)) {
SerialUSB.println("SDIO_DBG: Command active");
- } else {
- SerialUSB.println("SDIO_DBG: Command inactive");
}
switch (wrsp) {
case SDIO_WRSP_NONE:
- //check cmdsent
+ SerialUSB.print("SDIO_DBG: Waiting for CMDSENT...");
this->wait(SDIO_FLAG_CMDSENT);
- SerialUSB.println("SDIO_DBG: Command sent");
+ SerialUSB.println(" Command sent");
//sdio_clear_interrupt(this->sdio_d, SDIO_ICR_CMDSENTC);
break;
case SDIO_WRSP_SHRT:
case SDIO_WRSP_LONG:
- //wait for resp
+ SerialUSB.print("SDIO_DBG: Waiting for CMDREND...");
this->wait(SDIO_FLAG_CMDREND);
- SerialUSB.println("SDIO_DBG: Command response recieved");
+ SerialUSB.println(" Response recieved");
//sdio_clear_interrupt(this->sdio_d, SDIO_ICR_CMDRENDC);
break;
default:
@@ -307,10 +306,12 @@ void SecureDigitalMemoryCard::acmd(SDIOAppCommand acmd,
uint32 *resp) {
csr status;
this->cmd(APP_CMD, (RCA.RCA << 16), SDIO_WRSP_SHRT, (uint32*)&status);
- if (status.APP_CMD == SDIO_CSR_APP_ENABLED) { //FIXME
- this->cmd((SDIOCommand)acmd, arg, wrsp, resp);
+ if (status.APP_CMD == SDIO_CSR_APP_DISABLED) {
+ SerialUSB.println("SDIO_ERR: AppCommand failed to enable");
+ return;
}
-
+ SerialUSB.println("SDIO_DBG: AppCommand enabled");
+ this->cmd((SDIOCommand)acmd, arg, wrsp, resp);
}
/**
@@ -475,13 +476,20 @@ void SecureDigitalMemoryCard::disable(SDIOInterruptFlag flag) {
void SecureDigitalMemoryCard::wait(SDIOInterruptFlag flag) {
while (!sdio_get_status(this->sdio_d, (0x1 << flag))) {
if (sdio_get_status(this->sdio_d, SDIO_STA_CTIMEOUT)) {
- //sdio_clear_interrupt(this->sdio_d, SDIO_ICR_CTIMEOUTC);
+ SerialUSB.println("");
SerialUSB.println("SDIO_ERR: Command timeout");
return;
- } else {
- SerialUSB.println(this->sdio_d->regs->STA, HEX);
- delay(100);
+ }
+ if (sdio_get_status(this->sdio_d, SDIO_STA_CCRCFAIL)) {
+ SerialUSB.println("");
+ SerialUSB.println("SDIO_ERR: Response CRC fail");
+ return;
+ }
+ if (sdio_get_status(this->sdio_d, SDIO_STA_DCRCFAIL)) {
+ SerialUSB.println("");
+ SerialUSB.println("SDIO_ERR: Data CRC fail");
+ return;
}
}
- sdio_clear_interrupt(this->sdio_d, (0x1 << flag));
+ //sdio_clear_interrupt(this->sdio_d, (0x1 << flag));
}
View
61 libraries/Card/SecureDigital/SDMC.h
@@ -73,7 +73,8 @@ typedef enum SDIOClockFrequency {
SDIO_500_KHZ = 142,
SDIO_400_KHZ = 178,
SDIO_300_KHZ = 238,
- SDIO_CLK_INIT = SDIO_400_KHZ
+ SDIO_CLK_INIT = SDIO_400_KHZ,
+ SDIO_CLK_DATA = SDIO_24_MHZ
} SDIOClockFrequency;
typedef enum SDIOBlockSize {
@@ -127,64 +128,6 @@ typedef enum SDIOInterruptFlag {
//SDIO_FLAG_ALL = 37
} SDIOInterruptFlag;
-typedef enum SDIOStatusResponseTag {
- //CardStatusResponse Tags
- SDIO_CSR_NO_ERROR = 0,
- SDIO_CSR_ERROR = 1,
- SDIO_CSR_NOT_PROTECTED = 0,
- SDIO_CSR_PROTECTED = 1,
- SDIO_CSR_CARD_UNLOCKED = 0,
- SDIO_CSR_CARD_LOCKED = 1,
- SDIO_CSR_SUCCESS = 0,
- SDIO_CSR_FAILURE = 1,
- SDIO_CSR_ECC_ENABLED = 0,
- SDIO_CSR_ECC_DISABLED = 1,
- SDIO_CSR_CLEARED = 0,
- SDIO_CSR_SET = 1,
- SDIO_CSR_IDLE = 0,
- SDIO_CSR_NOT_READY = 0,
- SDIO_CSR_READY = 1,
- SDIO_CSR_IDENT = 2,
- SDIO_CSR_STBY = 3,
- SDIO_CSR_TRAN = 4,
- SDIO_CSR_DATA = 5,
- SDIO_CSR_RCV = 6,
- SDIO_CSR_PRG = 7,
- SDIO_CSR_DIS = 8,
- SDIO_CSR_IO_MODE = 15,
- SDIO_CSR_APP_DISABLED = 0,
- SDIO_CSR_APP_ENABLED = 1,
- //SdStatusResponse Tags
- SDIO_SSR_1BIT_WIDTH = 0,
- SDIO_SSR_4BIT_WIDTH = 2,
- SDIO_SSR_NOT_SECURED = 0,
- SDIO_SSR_SECURED = 1,
- SDIO_SSR_REG_CARD = 0,
- SDIO_SSR_ROM_CARD = 1,
- SDIO_SSR_OTP_CARD = 2,
- SDIO_SSR_SPEED_CLASS_0 = 0,
- SDIO_SSR_SPEED_CLASS_2 = 1,
- SDIO_SSR_SPEED_CLASS_4 = 2,
- SDIO_SSR_SPEED_CLASS_6 = 3,
- SDIO_SSR_SPEED_CLASS_10 = 4,
- SDIO_SSR_AU_SIZE_NOT_DEF = 0,
- SDIO_SSR_AU_SIZE_16KB = 1,
- SDIO_SSR_AU_SIZE_32KB = 2,
- SDIO_SSR_AU_SIZE_64KB = 3,
- SDIO_SSR_AU_SIZE_128KB = 4,
- SDIO_SSR_AU_SIZE_256KB = 5,
- SDIO_SSR_AU_SIZE_512KB = 6,
- SDIO_SSR_AU_SIZE_1MB = 7,
- SDIO_SSR_AU_SIZE_2MB = 8,
- SDIO_SSR_AU_SIZE_4MB = 9,
- SDIO_SSR_AU_SIZE_8MB = 10,
- SDIO_SSR_AU_SIZE_12MB = 11,
- SDIO_SSR_AU_SIZE_16MB = 12,
- SDIO_SSR_AU_SIZE_24MB = 13,
- SDIO_SSR_AU_SIZE_32MB = 14,
- SDIO_SSR_AU_SIZE_64MB = 15,
-} SDIOStatusResponseTag;
-
class SecureDigitalMemoryCard {
public:
ocr OCR;
View
19 main.cpp
@@ -23,7 +23,11 @@ void setup() {
void loop() {
waitForButtonPress();
- SDMC.test();
+ SerialUSB.println("SDIO_DBG: Starting SDMC test");
+ SDMC.begin();
+ SDMC.init();
+ SDMC.end();
+ SerialUSB.println("SDIO_DBG: Test complete");
}
// Force init to be called *first*, i.e. before static object allocation.
@@ -38,15 +42,4 @@ int main(void) {
loop();
}
return 0;
-}
-
-/**
- toggleLED();
- SerialUSB.println("SDIO_DBG: Running SDMC test");
- SDMC.begin();
- SerialUSB.println("SDIO_DBG: Initializing card");
- SDMC.init();
- SerialUSB.println("SDIO_DBG: Test complete");
- SDMC.end();
- toggleLED();
-*/
+}

No commit comments for this range

Something went wrong with that request. Please try again.