✨ feat(filesystem): 增强SD卡文件系统挂载与格式化逻辑
- 添加工作缓冲区以支持带参数的格式化操作
- 重构挂载逻辑,在挂载成功后验证文件系统类型和簇大小是否符合目标格式(FAT32,簇大小32KB)
- 将格式化条件判断与执行分离,提高代码可读性
- 使用宏定义目标簇大小和扇区大小参数,便于维护
🔧 chore(scripts): 重命名脚本文件并添加压缩包
- 将`atem_parse.py`重命名为`ATEMParse.py`以遵循命名规范
- 添加`ATEMParse.7z`压缩包文件
This commit is contained in:
parent
973dfad5c7
commit
4f8feccc06
@ -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)
|
||||
{
|
||||
|
||||
BIN
Scripts/ATEMParse.7z
Normal file
BIN
Scripts/ATEMParse.7z
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user