From 7c1422770ef052e4509a27210a4262797df351ed Mon Sep 17 00:00:00 2001 From: Uladzimir Pylinski Date: Thu, 19 Feb 2015 15:25:48 +0000 Subject: SDIO. Working area buffer now handles using pointer in SDConfig structure. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7692 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/sdc_lld.h | 13 +++++++++++-- os/hal/src/sdc.c | 14 ++++---------- 2 files changed, 15 insertions(+), 12 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 428ef1568..ddca0e578 100644 --- a/os/hal/ports/STM32/LLD/sdc_lld.h +++ b/os/hal/ports/STM32/LLD/sdc_lld.h @@ -219,9 +219,18 @@ typedef struct SDCDriver SDCDriver; */ typedef struct { /** - * @brief Bus width(board specific). + * @brief Bus width (board specific). */ - sdcbusmode_t bus_width; + sdcbusmode_t bus_width; + /** + * @brief Working area for memory consuming operations during init + * procedures (temporal storage for EXT_CSD, etc.). + * @note Buffer must be word aligned and big enough to store 512 bytes. + * @note It is mandatory for MMC bigger than 2GB. + * @note Memory can be freed after @p sdcConnect function call. Do not + * forge to set this pointer to @p NULL after freeing. + */ + uint8_t *scratchpad; } SDCConfig; /** diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index f401334e9..73ea60fbe 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -84,11 +84,6 @@ static const struct SDCDriverVMT sdc_vmt = { (bool (*)(void *, BlockDeviceInfo *))sdcGetInfo }; -/** - * @brief Temporal storage for different purposes (extended CSD, etc.). - */ -static uint8_t scratchpad[512]; - /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ @@ -308,18 +303,16 @@ 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; + uint32_t cmdarg = 0; + uint8_t *scratchpad = sdcp->config->scratchpad; *clk = SDC_CLK_25MHz; /* safe default */ - cmdarg = 0; - memset(scratchpad, 0x55, sizeof(scratchpad)); if (sdc_lld_read_special(sdcp, scratchpad, 64, MMCSD_CMD_SWITCH, cmdarg)) return HAL_FAILED; if ((sdc_cmd6_extract_info(SD_SWITCH_FUNCTION_SPEED, scratchpad) & 2) == 2) { cmdarg = sdc_cmd6_construct(SD_SWITCH_SET, SD_SWITCH_FUNCTION_SPEED, 1); - memset(scratchpad, 0x55, sizeof(scratchpad)); if (sdc_lld_read_special(sdcp, scratchpad, 64, MMCSD_CMD_SWITCH, cmdarg)) return HAL_FAILED; if (HAL_SUCCESS == sdc_cmd6_check_status(SD_SWITCH_FUNCTION_SPEED, scratchpad)) @@ -576,7 +569,8 @@ void sdcStop(SDCDriver *sdcp) { */ bool sdcConnect(SDCDriver *sdcp) { uint32_t resp[1]; - sdcbusclk_t clk; + sdcbusclk_t clk = SDC_CLK_25MHz; + uint8_t *scratchpad = sdcp->config->scratchpad; osalDbgCheck(sdcp != NULL); osalDbgAssert((sdcp->state == BLK_ACTIVE) || (sdcp->state == BLK_READY), -- cgit v1.2.3