Pārlūkot izejas kodu

更新CPU工程mmc驱动
优化mmc驱动mmc_select_speed_mode函数对于speed_mode字段提取及判断错误从而导致函数异常返回问题。

helen 1 nedēļu atpakaļ
vecāks
revīzija
77fbce8703

+ 12 - 12
amt630hv160-freertos-beta/ArkmicroFiles/libcpu-amt630hv160/source/sdio/mmc.c

@@ -281,17 +281,18 @@ out:
 
 static int mmc_select_speed_mode(struct mmcsd_card *card, uint8_t *ext_csd, EXT_CSD_HS_types mode)
 {
-	static uint32_t speed_mode = 0;
-	uint8_t *bw_ext_csd;
+	uint8_t speed_mode;
+	uint8_t *bw_ext_csd = NULL;
 	int err = 0;
+
 	if(card == NULL || ext_csd == NULL){
 		TRACE_ERROR("emmc parse ext csd fail, invaild args");
 		return -1;
-	 }
+	}
 
-	speed_mode = *((uint32_t *)&ext_csd[EXT_CSD_HS_TIMING]);
-	if(speed_mode != mode){
-		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, mode);
+	speed_mode = ext_csd[EXT_CSD_HS_TIMING];
+	if(speed_mode != (uint8_t)mode){
+		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, (uint8_t)mode);
 		if (err)
 			goto out;
 
@@ -299,14 +300,14 @@ static int mmc_select_speed_mode(struct mmcsd_card *card, uint8_t *ext_csd, EXT_
 		if (err)
 			goto out;
 
-		speed_mode = *((uint32_t *)&bw_ext_csd[EXT_CSD_HS_TIMING]);
-		if(speed_mode != mode){
-			printf("mmc_select_speed_mode fail!\n");
-			err =-1;
+		speed_mode = bw_ext_csd[EXT_CSD_HS_TIMING];
+		if(speed_mode != (uint8_t)mode){
+			TRACE_ERROR("mmc_select_speed_mode fail! expect %d, current %d", (uint8_t)mode, speed_mode);
+			err = -1;
 			goto out;
 		}
 
-		*((uint32_t *)&ext_csd[EXT_CSD_HS_TIMING]) = speed_mode;
+		ext_csd[EXT_CSD_HS_TIMING] = speed_mode;
 	}
 
 out:
@@ -314,7 +315,6 @@ out:
 		vPortFree(bw_ext_csd);
 
 	return err;
-
 }
 
 /*