Modified SDMMCv1 and SDMMCv2 drivers to incorporate a buffer in their own structure, an external buffer is no more needed.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13416 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2020-03-14 10:14:04 +00:00
parent 16946c0851
commit a94ac981fe
5 changed files with 17 additions and 55 deletions

View File

@ -88,21 +88,10 @@ SDCDriver SDCD2;
/* Driver local variables and types. */
/*===========================================================================*/
#if STM32_SDC_SDMMC_UNALIGNED_SUPPORT
/**
* @brief Buffer for temporary storage during unaligned transfers.
*/
static union {
uint32_t alignment;
uint8_t buf[MMCSD_BLOCK_SIZE];
} u;
#endif /* STM32_SDC_SDMMC_UNALIGNED_SUPPORT */
/**
* @brief SDIO default configuration.
*/
static const SDCConfig sdc_default_cfg = {
NULL,
SDC_MODE_4BIT
};
@ -920,9 +909,9 @@ bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk,
if (((unsigned)buf & 3) != 0) {
uint32_t i;
for (i = 0; i < blocks; i++) {
if (sdc_lld_read_aligned(sdcp, startblk, u.buf, 1))
if (sdc_lld_read_aligned(sdcp, startblk, sdcp->buf, 1))
return HAL_FAILED;
memcpy(buf, u.buf, MMCSD_BLOCK_SIZE);
memcpy(buf, sdcp->buf, MMCSD_BLOCK_SIZE);
buf += MMCSD_BLOCK_SIZE;
startblk++;
}
@ -955,9 +944,9 @@ bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk,
if (((unsigned)buf & 3) != 0) {
uint32_t i;
for (i = 0; i < blocks; i++) {
memcpy(u.buf, buf, MMCSD_BLOCK_SIZE);
memcpy(sdcp->buf, buf, MMCSD_BLOCK_SIZE);
buf += MMCSD_BLOCK_SIZE;
if (sdc_lld_write_aligned(sdcp, startblk, u.buf, 1))
if (sdc_lld_write_aligned(sdcp, startblk, sdcp->buf, 1))
return HAL_FAILED;
startblk++;
}

View File

@ -268,15 +268,6 @@ typedef struct SDCDriver SDCDriver;
* @note It could be empty on some architectures.
*/
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. 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.
*/
uint8_t *scratchpad;
/**
* @brief Bus width.
*/
@ -350,6 +341,10 @@ struct SDCDriver {
* @note Needed for debugging aid.
*/
SDMMC_TypeDef *sdmmc;
/**
* @brief Buffer for internal operations.
*/
uint8_t buf[MMCSD_BLOCK_SIZE];
};
/*===========================================================================*/

View File

@ -57,21 +57,10 @@ SDCDriver SDCD2;
/* Driver local variables and types. */
/*===========================================================================*/
#if STM32_SDC_SDMMC_UNALIGNED_SUPPORT
/**
* @brief Buffer for temporary storage during unaligned transfers.
*/
static union {
uint32_t alignment;
uint8_t buf[MMCSD_BLOCK_SIZE];
} u;
#endif /* STM32_SDC_SDMMC_UNALIGNED_SUPPORT */
/**
* @brief SDIO default configuration.
*/
static const SDCConfig sdc_default_cfg = {
NULL,
SDC_MODE_4BIT
};
@ -788,9 +777,9 @@ bool sdc_lld_read(SDCDriver *sdcp, uint32_t startblk,
if (((unsigned)buf & 3) != 0) {
uint32_t i;
for (i = 0; i < blocks; i++) {
if (sdc_lld_read_aligned(sdcp, startblk, u.buf, 1))
if (sdc_lld_read_aligned(sdcp, startblk, sdcp->buf, 1))
return HAL_FAILED;
memcpy(buf, u.buf, MMCSD_BLOCK_SIZE);
memcpy(buf, sdcp->buf, MMCSD_BLOCK_SIZE);
buf += MMCSD_BLOCK_SIZE;
startblk++;
}
@ -823,9 +812,9 @@ bool sdc_lld_write(SDCDriver *sdcp, uint32_t startblk,
if (((unsigned)buf & 3) != 0) {
uint32_t i;
for (i = 0; i < blocks; i++) {
memcpy(u.buf, buf, MMCSD_BLOCK_SIZE);
memcpy(sdcp->buf, buf, MMCSD_BLOCK_SIZE);
buf += MMCSD_BLOCK_SIZE;
if (sdc_lld_write_aligned(sdcp, startblk, u.buf, 1))
if (sdc_lld_write_aligned(sdcp, startblk, sdcp->buf, 1))
return HAL_FAILED;
startblk++;
}

View File

@ -180,15 +180,6 @@ typedef struct SDCDriver SDCDriver;
* @note It could be empty on some architectures.
*/
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. 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.
*/
uint8_t *scratchpad;
/**
* @brief Bus width.
*/
@ -250,6 +241,10 @@ struct SDCDriver {
* @brief Input clock frequency.
*/
uint32_t clkfreq;
/**
* @brief Buffer for internal operations.
*/
uint8_t buf[MMCSD_BLOCK_SIZE];
};
/*===========================================================================*/

View File

@ -373,16 +373,10 @@ static bool sdc_detect_bus_clk(SDCDriver *sdcp, sdcbusclk_t *clk) {
static bool mmc_detect_bus_clk(SDCDriver *sdcp, sdcbusclk_t *clk) {
uint32_t cmdarg;
uint32_t resp[1];
uint8_t *scratchpad = sdcp->config->scratchpad;
/* Safe default.*/
*clk = SDC_CLK_25MHz;
/* Use safe default when there is no space for data.*/
if (NULL == scratchpad) {
return HAL_SUCCESS;
}
cmdarg = mmc_cmd6_construct(MMC_SWITCH_WRITE_BYTE, 185, 1, 0);
if (!(sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SWITCH, cmdarg, resp) ||
MMCSD_R1_ERROR(resp[0]))) {
@ -688,7 +682,7 @@ bool sdcConnect(SDCDriver *sdcp) {
/* The card is a MMC, checking if it is a large device.*/
if (_mmcsd_get_slice(sdcp->csd, MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE) > 1U) {
uint8_t *ext_csd = sdcp->config->scratchpad;
uint8_t *ext_csd = sdcp->buf;
/* Size detection requires the buffer.*/
if (NULL == ext_csd) {