From f908425b134363bc2f549075bd3a8b49f0f28e27 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 12 Jul 2017 21:04:54 +0800 Subject: [PATCH] sdmmc: introduce is_app_cmd flag, check it along with opcode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘make_hw_cmd’ function checks opcodes in a few cases. Comparing opcode does not tell the whole story, because for some SD commands there is are APP commands with the same opcodes. This change introduces a flag which indicates whether the next command is going to be an APP command. The check for APP_SET_BUS_WIDTH command is updated to use this flag. This fixes a bug with an unexpected STOP_TRANSMISSION command sent after SWITCH_FUNC command, which has opcode 6, same as APP_SET_BUS_WIDTH. --- components/driver/sdmmc_transaction.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/driver/sdmmc_transaction.c b/components/driver/sdmmc_transaction.c index 3cc5ee5da..8f06be88e 100644 --- a/components/driver/sdmmc_transaction.c +++ b/components/driver/sdmmc_transaction.c @@ -73,6 +73,7 @@ const uint32_t SDMMC_CMD_ERR_MASK = static sdmmc_desc_t s_dma_desc[SDMMC_DMA_DESC_CNT]; static sdmmc_transfer_state_t s_cur_transfer = { 0 }; static QueueHandle_t s_request_mutex; +static bool s_is_app_cmd; // This flag is set if the next command is an APP command static esp_err_t handle_idle_state_events(); static sdmmc_hw_cmd_t make_hw_cmd(sdmmc_command_t* cmd); @@ -88,6 +89,7 @@ esp_err_t sdmmc_host_transaction_handler_init() if (!s_request_mutex) { return ESP_ERR_NO_MEM; } + s_is_app_cmd = false; return ESP_OK; } @@ -145,6 +147,7 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo) break; } } + s_is_app_cmd = (ret == ESP_OK && cmdinfo->opcode == MMC_APP_CMD); xSemaphoreGive(s_request_mutex); return ret; } @@ -228,7 +231,7 @@ static sdmmc_hw_cmd_t make_hw_cmd(sdmmc_command_t* cmd) } else { res.wait_complete = 1; } - if (cmd->opcode == SD_APP_SET_BUS_WIDTH) { + if (s_is_app_cmd && cmd->opcode == SD_APP_SET_BUS_WIDTH) { res.send_auto_stop = 1; res.data_expected = 1; }