aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/ports/STM32/LLD/sdc_lld.h4
-rw-r--r--os/hal/src/sdc.c11
2 files changed, 10 insertions, 5 deletions
diff --git a/os/hal/ports/STM32/LLD/sdc_lld.h b/os/hal/ports/STM32/LLD/sdc_lld.h
index ddca0e578..8c0f7eb4c 100644
--- a/os/hal/ports/STM32/LLD/sdc_lld.h
+++ b/os/hal/ports/STM32/LLD/sdc_lld.h
@@ -227,8 +227,8 @@ typedef struct {
* 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.
+ * @note Memory can be freed after @p sdcConnect return. Do not
+ * forget 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 bdd6bddea..260c7f861 100644
--- a/os/hal/src/sdc.c
+++ b/os/hal/src/sdc.c
@@ -308,6 +308,10 @@ static bool sdc_detect_bus_clk(SDCDriver *sdcp, sdcbusclk_t *clk) {
*clk = SDC_CLK_25MHz; /* safe default */
+ /* 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))
return HAL_FAILED;
@@ -623,9 +627,10 @@ bool sdcConnect(SDCDriver *sdcp) {
goto failed;
sdc_lld_set_data_clk(sdcp, clk);
- /* Reads extended CSD if needed.*/
- if (SDC_MODE_CARDTYPE_MMC == (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) &&
- mmcsdGetSlice(sdcp->csd, MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE) > 1) {
+ /* Reads extended CSD if needed and possible.*/
+ if (NULL != scratchpad &&
+ SDC_MODE_CARDTYPE_MMC == (sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) &&
+ mmcsdGetSlice(sdcp->csd, MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE) > 1) {
if(sdc_lld_read_special(sdcp, scratchpad, 512, MMCSD_CMD_SEND_EXT_CSD, 0))
goto failed;
}