From d5fb75afc4c7203500108fd573f90bfbbd1ac498 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 1 May 2011 10:33:44 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2909 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/sdc_lld.c | 38 +++++++++++++++++++++++++++++--- os/hal/platforms/STM32/sdc_lld.h | 6 +++-- os/hal/src/sdc.c | 10 ++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/os/hal/platforms/STM32/sdc_lld.c b/os/hal/platforms/STM32/sdc_lld.c index 626702084..ecd09f1b8 100644 --- a/os/hal/platforms/STM32/sdc_lld.c +++ b/os/hal/platforms/STM32/sdc_lld.c @@ -206,6 +206,7 @@ void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg) { /** * @brief Sends an SDIO command with a short response expected. + * @note The CRC is not verified. * * @param[in] sdcp pointer to the @p SDCDriver object * @param[in[ cmd card command @@ -222,6 +223,37 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp) { uint32_t sta; + (void)sdcp; + SDIO->ARG = arg; + SDIO->CMD = (uint32_t)cmd | SDIO_CMD_WAITRESP_0 | SDIO_CMD_CPSMEN; + while (((sta = SDIO->STA) & (SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT | + SDIO_STA_CCRCFAIL)) == 0) + ; + SDIO->ICR = 0xFFFFFFFF; + if ((sta & (SDIO_STA_CTIMEOUT)) != 0) + return TRUE; + *resp = SDIO->RESP1; + return FALSE; +} + +/** + * @brief Sends an SDIO command with a short response expected and CRC. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[in[ cmd card command + * @param[in] arg command argument + * @param[out] resp pointer to the response buffer (one word) + * @return The operation status. + * @retval FALSE the operation succeeded. + * @retval TRUE the operation failed because timeout, CRC check or + * other errors. + * + * @notapi + */ +bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp) { + uint32_t sta; + (void)sdcp; SDIO->ARG = arg; SDIO->CMD = (uint32_t)cmd | SDIO_CMD_WAITRESP_0 | SDIO_CMD_CPSMEN; @@ -236,7 +268,7 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, } /** - * @brief Sends an SDIO command with a long response expected. + * @brief Sends an SDIO command with a long response expected and CRC. * * @param[in] sdcp pointer to the @p SDCDriver object * @param[in[ cmd card command @@ -249,8 +281,8 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, * * @notapi */ -bool_t sdc_lld_send_cmd_long(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp) { +bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp) { uint32_t sta; diff --git a/os/hal/platforms/STM32/sdc_lld.h b/os/hal/platforms/STM32/sdc_lld.h index fff6133b2..5f54f3b50 100644 --- a/os/hal/platforms/STM32/sdc_lld.h +++ b/os/hal/platforms/STM32/sdc_lld.h @@ -160,8 +160,10 @@ extern "C" { void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg); bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp); - bool_t sdc_lld_send_cmd_long(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, - uint32_t *resp); + bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp); + bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, + uint32_t *resp); #ifdef __cplusplus } #endif diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 07f25aa65..7cfac6705 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -146,17 +146,17 @@ bool_t sdcConnect(SDCDriver *sdcp) { sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0); /* V2.0 cards detection.*/ - if (!sdc_lld_send_cmd_short(sdcp, SDC_CMD_SEND_IF_COND, - SDC_CMD8_PATTERN, &resp)) + if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND, + SDC_CMD8_PATTERN, &resp)) sdcp->cardmode |= SDC_MODE_CARDTYPE_SDV20; /* Voltage verification.*/ if (((resp >> 8) & 0xF) != 1) goto failed; - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) goto failed; else { /* MMC or SD detection.*/ - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) sdcp->cardmode |= SDC_MODE_CARDTYPE_MMC; } @@ -173,7 +173,7 @@ bool_t sdcConnect(SDCDriver *sdcp) { i = 0; while (TRUE) { chThdSleepMilliseconds(10); - if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp)) + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp)) goto failed; if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, &resp)) goto failed;