diff --git a/Core/Src/main.c b/Core/Src/main.c index 1a37926..16b6ac0 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -411,6 +411,7 @@ static HAL_StatusTypeDef MountFileSystemForSampling(void) extern FATFS SDFatFS; extern char SDPath[4]; extern SD_HandleTypeDef hsd; + BYTE work[_MAX_SS]; if (g_fatfs_mounted_for_sampling) { return HAL_OK; // 已经挂载 @@ -422,32 +423,48 @@ static HAL_StatusTypeDef MountFileSystemForSampling(void) return HAL_ERROR; } -// FRESULT format_result = f_mkfs(SDPath, FM_FAT32, 0, NULL, 0); + // 目标格式参数:FAT32,簇大小32768字节(512字节/扇区 × 64扇区/簇) + #define TARGET_CLUSTER_SIZE_BYTES 32768U + #define TARGET_SECTOR_SIZE_BYTES 512U + #define TARGET_SECTORS_PER_CLUSTER (TARGET_CLUSTER_SIZE_BYTES / TARGET_SECTOR_SIZE_BYTES) // 64 // 尝试挂载文件系统 FRESULT mount_result = f_mount(&SDFatFS, SDPath, 1); - if (mount_result != FR_OK) { - if (mount_result == FR_NO_FILESYSTEM) - { - DebugOutput_SendString("No filesystem found, formatting...\r\n"); - - // 格式化为FAT32 - FRESULT format_result = f_mkfs(SDPath, FM_FAT32, 0, NULL, 0); - - if (format_result == FR_OK) { - DebugOutput_SendString("Format successful, remounting...\r\n"); - mount_result = f_mount(&SDFatFS, SDPath, 1); - if (mount_result != FR_OK) { - DebugOutput_SendString("Remount after format failed\r\n"); - return HAL_ERROR; - } - } else { - DebugOutput_SendString("Format failed\r\n"); + uint8_t need_format = 0; + + if (mount_result == FR_OK) { + // 挂载成功,验证文件系统类型和簇大小是否符合目标格式 + if (SDFatFS.fs_type != FS_FAT32) { + DebugOutput_SendString("Not FAT32, reformatting...\r\n"); + f_mount(NULL, SDPath, 0); + need_format = 1; + } else if (SDFatFS.csize != TARGET_SECTORS_PER_CLUSTER) { + DebugOutput_SendString("Cluster size mismatch, reformatting...\r\n"); + f_mount(NULL, SDPath, 0); + need_format = 1; + } + } else if (mount_result == FR_NO_FILESYSTEM) { + DebugOutput_SendString("No filesystem found, formatting...\r\n"); + need_format = 1; + } else { + DebugOutput_SendString("Mount failed with other error\r\n"); + return HAL_ERROR; + } + + if (need_format) { + FRESULT format_result = f_mkfs(SDPath, FM_FAT32, TARGET_CLUSTER_SIZE_BYTES, work, sizeof(work)); + + if (format_result == FR_OK) { + DebugOutput_SendString("Format successful, remounting...\r\n"); + mount_result = f_mount(&SDFatFS, SDPath, 1); + + if (mount_result != FR_OK) { + DebugOutput_SendString("Remount after format failed\r\n"); return HAL_ERROR; } } else { - DebugOutput_SendString("Mount failed with other error\r\n"); + DebugOutput_SendString("Format failed\r\n"); return HAL_ERROR; } } @@ -570,9 +587,10 @@ int main(void) } } +// #define NEED_FORMAT_SD #ifdef NEED_FORMAT_SD // Raw_Hardware_Test(); -// SDNAND_ForceFormat_and_Mount(); + SDNAND_ForceFormat_and_Mount(); Run_SDNAND_SpeedTest_V2(); while(1) { diff --git a/Scripts/ATEMParse.7z b/Scripts/ATEMParse.7z new file mode 100644 index 0000000..4ad34ee Binary files /dev/null and b/Scripts/ATEMParse.7z differ diff --git a/Scripts/atem_parse.py b/Scripts/ATEMParse.py similarity index 100% rename from Scripts/atem_parse.py rename to Scripts/ATEMParse.py