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

add:tf卡部分读写参数可配置

alienwalker 7 месяцев назад
Родитель
Сommit
0588b10e97

+ 2 - 0
components/fatfs/diskio_impl.c

@@ -24,6 +24,8 @@
 uint16_t FATFS_POWER_DELAY = 1;
 BYTE FATFS_DEBUG = 0; // debug log, 0 -- disable , 1 -- enable
 BYTE FATFS_POWER_PIN = 0xff;
+uint8_t FATFS_NO_CRC_CHECK = 0;
+uint16_t FATFS_WRITE_TO = 100;
 
 static block_disk_t disks[FF_VOLUMES+1] = {0};
 

+ 8 - 3
components/fatfs/diskio_spitf.c

@@ -86,7 +86,7 @@
 #define SD_CMD_READ_OCR               58  /* CMD55 = 0x79 */
 #define SD_DEFAULT_BLOCK_SIZE (512)
 
-#define SPI_TF_WRITE_TO_MS	(100)
+#define SPI_TF_WRITE_TO_MS	(FATFS_WRITE_TO)
 #define SPI_TF_READ_TO_MS	(100)
 
 typedef struct
@@ -196,7 +196,6 @@ typedef struct
 	uint8_t SpiID;
 	uint8_t SDHCState;
 	uint8_t IsInitDone;
-	uint8_t IsCRCCheck;
 	uint8_t SDHCError;
 	uint8_t SPIError;
 	uint8_t ExternResult[64];
@@ -208,6 +207,8 @@ typedef struct
 
 #define SPI_TF_WAIT(x) luat_rtos_task_sleep(x)
 
+extern uint8_t FATFS_NO_CRC_CHECK;
+extern uint16_t FATFS_WRITE_TO;
 static luat_spitf_ctrl_t g_s_spitf;
 static void luat_spitf_read_config(luat_spitf_ctrl_t *spitf);
 
@@ -488,7 +489,11 @@ READ_REST_DATA:
 		luat_spi_transfer(spitf->SpiID, (const char *)pBuf, RemainingLen, (char *)pBuf, RemainingLen);
 		memset(spitf->TempData, 0xff, 2);
 		luat_spi_transfer(spitf->SpiID, (const char *)spitf->TempData, 2, (char *)spitf->TempData, 2);
-//		if (spitf->IsCRCCheck)
+		if (FATFS_NO_CRC_CHECK)
+		{
+
+		}
+		else
 		{
 			crc16 = CRC16Cal(spitf->DataBuf.Data + spitf->DataBuf.Pos * __SDHC_BLOCK_LEN__, __SDHC_BLOCK_LEN__, 0, CRC16_CCITT_GEN, 0);
 			crc16_check = BytesGetBe16(spitf->TempData);

+ 17 - 2
components/fatfs/luat_lib_fatfs.c

@@ -28,6 +28,8 @@ static FATFS *fs = NULL;		/* FatFs work area needed for each volume */
 extern BYTE FATFS_DEBUG; // debug log, 0 -- disable , 1 -- enable
 extern BYTE FATFS_POWER_PIN;
 extern uint16_t FATFS_POWER_DELAY;
+extern uint8_t FATFS_NO_CRC_CHECK;
+extern uint16_t FATFS_WRITE_TO;
 DRESULT diskio_open_ramdisk(BYTE pdrv, size_t len);
 DRESULT diskio_open_spitf(BYTE pdrv, void* userdata);
 DRESULT diskio_open_sdio(BYTE pdrv, void* userdata);
@@ -301,7 +303,7 @@ static int fatfs_getfree(lua_State *L)
 /**
 设置调试模式
 @api fatfs.debug(value)
-@bool 是否进入调试模式,true代表进入调试模式,增加调试日志
+@int 是否进入调试模式,1代表进入调试模式,增加调试日志
 @return nil 无返回值
  */
 static int fatfs_debug_mode(lua_State *L) {
@@ -309,6 +311,19 @@ static int fatfs_debug_mode(lua_State *L) {
 	return 0;
 }
 
+/**
+设置fatfs一些特殊参数,大部分卡无需配置,部分不能正常读写的卡,经过配置后可能能读写成功
+@api fatfs.config(crc_check, write_to)
+@int 读取时是否跳过CRC检查,1跳过不检查CRC,0不跳过检查CRC,默认不跳过,除非TF卡不支持CRC校验,否则不应该跳过!
+@int 单次写入超时时间,单位ms,默认100ms。
+@return nil 无返回值
+ */
+static int fatfs_config(lua_State *L) {
+	FATFS_NO_CRC_CHECK = luaL_optinteger(L, 1, 0);
+	FATFS_WRITE_TO = luaL_optinteger(L, 1, 100);
+	return 0;
+}
+
 #if 0
 
 // ------------------------------------------------
@@ -634,7 +649,7 @@ static const rotable_Reg_t reg_fatfs[] =
   { "mount",	ROREG_FUNC(fatfs_mount)}, //初始化,挂载
   { "getfree",	ROREG_FUNC(fatfs_getfree)}, // 获取文件系统大小,剩余空间
   { "debug",	ROREG_FUNC(fatfs_debug_mode)}, // 调试模式,打印更多日志
-
+  { "config",		ROREG_FUNC(fatfs_config)}, //初始化,挂载, 别名方法
   { "unmount",	ROREG_FUNC(fatfs_unmount)}, // 取消挂载
 #if 0
   { "mkfs",		ROREG_FUNC(fatfs_mkfs)}, // 格式化!!!