@@ -122,6 +122,8 @@ static void _isr_cd_pin(void *arg);
122122
123123static void _init (sdmmc_dev_t * sdmmc_dev )
124124{
125+ DEBUG ("[sdmmc] %s" , __func__ );
126+
125127 esp32_sdmmc_dev_t * dev = container_of (sdmmc_dev , esp32_sdmmc_dev_t , sdmmc_dev );
126128 assert (dev );
127129
@@ -243,7 +245,7 @@ static int _send_cmd(sdmmc_dev_t *sdmmc_dev, sdmmc_cmd_t cmd_idx, uint32_t arg,
243245 .data = 0 ,
244246 .datalen = 0 ,
245247 .blklen = 0 ,
246- .timeout_ms = 100 ,
248+ .timeout_ms = 1000 ,
247249 };
248250
249251 switch (resp_type ) {
@@ -266,7 +268,7 @@ static int _send_cmd(sdmmc_dev_t *sdmmc_dev, sdmmc_cmd_t cmd_idx, uint32_t arg,
266268 cmd .flags |= SCF_RSP_R5 ;
267269 break ;
268270 case SDMMC_R6 :
269- cmd .flags |= SCF_RSP_R7 ;
271+ cmd .flags |= SCF_RSP_R6 ;
270272 break ;
271273 case SDMMC_R7 :
272274 cmd .flags |= SCF_RSP_R7 ;
@@ -275,13 +277,13 @@ static int _send_cmd(sdmmc_dev_t *sdmmc_dev, sdmmc_cmd_t cmd_idx, uint32_t arg,
275277 break ;
276278 }
277279
280+ DEBUG ("[sdmmc] %s dev=%p slot=%d op=%" PRIu32 " arg=%" PRIx32 " flags=%x\n" ,
281+ __func__ , dev , dev -> config -> slot , cmd .opcode , cmd .arg , cmd .flags );
282+
278283 esp_err_t res = sdmmc_host_do_transaction (dev -> config -> slot , & cmd );
279284 if (res ) {
280285 return _esp_err_to_sdmmc_err_code (res );
281286 }
282- else if (cmd .error ) {
283- return _esp_err_to_sdmmc_err_code (cmd .error );
284- }
285287
286288 if ((resp_type == SDMMC_R1 ) || (resp_type == SDMMC_R1B )) {
287289 sdmmc_dev -> status = cmd .response [0 ];
@@ -299,6 +301,28 @@ static int _send_cmd(sdmmc_dev_t *sdmmc_dev, sdmmc_cmd_t cmd_idx, uint32_t arg,
299301 }
300302 }
301303
304+ if (cmd .error ) {
305+ #if CPU_FAM_ESP32S3
306+ /*
307+ * FIXME:
308+ * The host controller triggers an invalid response error on ESP32-S3,
309+ * although the response from the card is completely correct and is
310+ * received completely by the host controller. The reason for this is
311+ * not yet clear. The sequence of commands including all parameters
312+ * sent to the host controller as well as the timing are exactly the
313+ * same as in the IDF code. The initialization of the host controller
314+ * is also exactly the same as in the IDF code. The problem only
315+ * occurs with the ESP32-S3, but not with the ESP32. As a workaround,
316+ * we ignore invalid response errors on ESP32-S3.
317+ */
318+ if (cmd .error != ESP_ERR_INVALID_RESPONSE ) {
319+ return _esp_err_to_sdmmc_err_code (cmd .error );
320+ }
321+ #else
322+ return _esp_err_to_sdmmc_err_code (cmd .error );
323+ #endif
324+ }
325+
302326 return 0 ;
303327}
304328
@@ -385,7 +409,7 @@ static int _xfer_execute(sdmmc_dev_t *sdmmc_dev, sdmmc_xfer_desc_t *xfer,
385409 .data = xfer -> write ? (void * )data_wr : data_rd ,
386410 .datalen = xfer -> block_num * xfer -> block_size ,
387411 .blklen = xfer -> block_size ,
388- .timeout_ms = xfer -> write ? 2500 : 1000 , // TODO
412+ .timeout_ms = xfer -> write ? 2500 : 1000 , /* TODO */
389413 };
390414
391415 if (done ) {
@@ -397,7 +421,25 @@ static int _xfer_execute(sdmmc_dev_t *sdmmc_dev, sdmmc_xfer_desc_t *xfer,
397421 return _esp_err_to_sdmmc_err_code (res );
398422 }
399423 else if (cmd .error ) {
424+ #ifdef CPU_FAM_ESP32S3
425+ /*
426+ * FIXME:
427+ * The host controller triggers an invalid response error on ESP32-S3,
428+ * although the response from the card is completely correct and is
429+ * received completely by the host controller. The reason for this is
430+ * not yet clear. The sequence of commands including all parameters
431+ * sent to the host controller as well as the timing are exactly the
432+ * same as in the IDF code. The initialization of the host controller
433+ * is also exactly the same as in the IDF code. The problem only
434+ * occurs with the ESP32-S3, but not with the ESP32. As a workaround,
435+ * we ignore invalid response errors on ESP32-S3.
436+ */
437+ if (cmd .error != ESP_ERR_INVALID_RESPONSE ) {
438+ return _esp_err_to_sdmmc_err_code (cmd .error );
439+ }
440+ #else
400441 return _esp_err_to_sdmmc_err_code (cmd .error );
442+ #endif
401443 }
402444
403445 if (done ) {
0 commit comments