瀏覽代碼

Add more trys when switching data width

Try a few times before switching to other data widths. 
The original strategy (simply wait for 20ms ) failed on STM32H743 with an MTFC4GACAJCN-4M (4GB EMMC) when switching data width. 
(unless the debugging info is enabled, which add more delays)
With this EMMC, the fixed delay was set to 50ms for it to be able to work. 

Instead of a fixed delay, I think we better change to trying a few more times with smaller delays.
Jianjia Ma 4 年之前
父節點
當前提交
4e74279d27
共有 1 個文件被更改,包括 8 次插入5 次删除
  1. 8 5
      components/drivers/sdio/mmc.c

+ 8 - 5
components/drivers/sdio/mmc.c

@@ -300,7 +300,7 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
     MMCSD_BUS_WIDTH_1
     MMCSD_BUS_WIDTH_1
   };
   };
   struct rt_mmcsd_host *host = card->host;
   struct rt_mmcsd_host *host = card->host;
-  unsigned idx, bus_width = 0;
+  unsigned idx, trys, bus_width = 0;
   int err = 0;
   int err = 0;
 
 
   if (GET_BITS(card->resp_cid, 122, 4) < 4)
   if (GET_BITS(card->resp_cid, 122, 4) < 4)
@@ -335,10 +335,13 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
     if (err)
     if (err)
       continue;
       continue;
 
 
-    bus_width = bus_widths[idx];
-    mmcsd_set_bus_width(host, bus_width);
-    mmcsd_delay_ms(20); //delay 10ms
-    err = mmc_compare_ext_csds(card, ext_csd, bus_width);
+    for(trys = 0; trys < 5; trys++){
+        mmcsd_set_bus_width(host, bus_width);
+        mmcsd_delay_ms(10); 
+        err = mmc_compare_ext_csds(card, ext_csd, bus_width);
+        if(!err)
+            break;
+    }
     if (!err) {
     if (!err) {
       err = bus_width;
       err = bus_width;
       break;
       break;