Просмотр исходного кода

sdmmc: introduce is_app_cmd flag, check it along with opcode

‘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.
Ivan Grokhotkov 8 лет назад
Родитель
Сommit
f908425b13
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      components/driver/sdmmc_transaction.c

+ 4 - 1
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;
     }