From 3f403d2288bf2d06f7443ca227672ca7c178183f Mon Sep 17 00:00:00 2001 From: Uladzimir Pylinski Date: Mon, 23 Feb 2015 18:32:55 +0000 Subject: SDIO. Clock detection procedure for SDC now uses stack allocated buffer instead of provided in config. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7701 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/sdc_lld.h | 2 +- os/hal/src/sdc.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'os/hal') diff --git a/os/hal/ports/STM32/LLD/sdc_lld.h b/os/hal/ports/STM32/LLD/sdc_lld.h index dbad8df76..295ac5d24 100644 --- a/os/hal/ports/STM32/LLD/sdc_lld.h +++ b/os/hal/ports/STM32/LLD/sdc_lld.h @@ -222,7 +222,7 @@ typedef struct { * @brief Working area for memory consuming operations. * @note Buffer must be word aligned and big enough to store 512 bytes. * @note It is mandatory for detecting MMC cards bigger than 2GB else it - * can be @p NULL. + * can be @p NULL. SD cards do NOT need it. * @note Memory pointed by this buffer is only used by @p sdcConnect(), * afterward it can be reused for other purposes. */ diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index 8e5546f87..11fcfa51a 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -303,24 +303,26 @@ static bool sdc_cmd6_check_status(sd_switch_function_t function, * @notapi */ static bool sdc_detect_bus_clk(SDCDriver *sdcp, sdcbusclk_t *clk) { - uint32_t cmdarg = 0; - uint8_t *scratchpad = sdcp->config->scratchpad; + uint32_t cmdarg; + const size_t N = 64; + uint8_t tmp[N]; /* Safe default.*/ *clk = SDC_CLK_25MHz; - /* Use safe default when there is no space for data.*/ - if (NULL == scratchpad) - return HAL_SUCCESS; - - if (sdc_lld_read_special(sdcp, scratchpad, 64, MMCSD_CMD_SWITCH, cmdarg)) + /* Read switch functions' register.*/ + if (sdc_lld_read_special(sdcp, tmp, N, MMCSD_CMD_SWITCH, 0)) return HAL_FAILED; - if ((sdc_cmd6_extract_info(SD_SWITCH_FUNCTION_SPEED, scratchpad) & 2) == 2) { + /* Check card capabilities parsing acquired data.*/ + if ((sdc_cmd6_extract_info(SD_SWITCH_FUNCTION_SPEED, tmp) & 2) == 2) { + /* Construct command to set the bus speed.*/ cmdarg = sdc_cmd6_construct(SD_SWITCH_SET, SD_SWITCH_FUNCTION_SPEED, 1); - if (sdc_lld_read_special(sdcp, scratchpad, 64, MMCSD_CMD_SWITCH, cmdarg)) + /* Write constructed command and read operation status in single call.*/ + if (sdc_lld_read_special(sdcp, tmp, N, MMCSD_CMD_SWITCH, cmdarg)) return HAL_FAILED; - if (HAL_SUCCESS == sdc_cmd6_check_status(SD_SWITCH_FUNCTION_SPEED, scratchpad)) + /* Check card answer for success status bits.*/ + if (HAL_SUCCESS == sdc_cmd6_check_status(SD_SWITCH_FUNCTION_SPEED, tmp)) *clk = SDC_CLK_50MHz; } -- cgit v1.2.3