Merge branch 'bugfix/sdmmc_auto_stop_cmd_v3.1' into 'release/v3.1'

sdmmc: enable host auto_stop only for certain commands (backport for v3.1)

See merge request idf/esp-idf!2817
This commit is contained in:
Angus Gratton 2018-08-01 14:29:03 +08:00
commit 34a4a96ded
2 changed files with 16 additions and 5 deletions

View file

@ -31,11 +31,13 @@
#define MMC_SEND_EXT_CSD 8 /* R1 */
#define MMC_SEND_CSD 9 /* R2 */
#define MMC_SEND_CID 10 /* R1 */
#define MMC_READ_DAT_UNTIL_STOP 11 /* R1 */
#define MMC_STOP_TRANSMISSION 12 /* R1B */
#define MMC_SEND_STATUS 13 /* R1 */
#define MMC_SET_BLOCKLEN 16 /* R1 */
#define MMC_READ_BLOCK_SINGLE 17 /* R1 */
#define MMC_READ_BLOCK_MULTIPLE 18 /* R1 */
#define MMC_WRITE_DAT_UNTIL_STOP 20 /* R1 */
#define MMC_SET_BLOCK_COUNT 23 /* R1 */
#define MMC_WRITE_BLOCK_SINGLE 24 /* R1 */
#define MMC_WRITE_BLOCK_MULTIPLE 25 /* R1 */

View file

@ -272,6 +272,16 @@ static esp_err_t handle_event(sdmmc_command_t* cmd, sdmmc_req_state_t* state,
return ESP_OK;
}
static bool cmd_needs_auto_stop(const sdmmc_command_t* cmd)
{
/* SDMMC host needs an "auto stop" flag for the following commands: */
return cmd->datalen > 0 &&
(cmd->opcode == MMC_WRITE_BLOCK_MULTIPLE ||
cmd->opcode == MMC_READ_BLOCK_MULTIPLE ||
cmd->opcode == MMC_WRITE_DAT_UNTIL_STOP ||
cmd->opcode == MMC_READ_DAT_UNTIL_STOP);
}
static sdmmc_hw_cmd_t make_hw_cmd(sdmmc_command_t* cmd)
{
sdmmc_hw_cmd_t res = { 0 };
@ -303,12 +313,11 @@ static sdmmc_hw_cmd_t make_hw_cmd(sdmmc_command_t* cmd)
res.rw = 1;
}
assert(cmd->datalen % cmd->blklen == 0);
if ((cmd->datalen / cmd->blklen) > 1) {
res.send_auto_stop = 1;
}
res.send_auto_stop = cmd_needs_auto_stop(cmd) ? 1 : 0;
}
ESP_LOGV(TAG, "%s: opcode=%d, rexp=%d, crc=%d", __func__,
res.cmd_index, res.response_expect, res.check_response_crc);
ESP_LOGV(TAG, "%s: opcode=%d, rexp=%d, crc=%d, auto_stop=%d", __func__,
res.cmd_index, res.response_expect, res.check_response_crc,
res.send_auto_stop);
return res;
}