|
|

楼主 |
发表于 2026-7-23 16:47:12
|
显示全部楼层
还得请教 void test_file_rw(void)
{
uint8_t buf[512];
uint8_t read_buf[512];
FILE *fp;
printf("=== File RW Test ===\r\n");
/* 写入 */
memset(buf, 0xAB, 512);
fp = fopen("N0:/test.bin", "w+b");
if (!fp) {
printf("FAIL: fopen write\r\n");
return;
}
size_t w = fwrite(buf, 1, 512, fp);
printf("Write: %d bytes\r\n", w);
fflush(fp);
fclose(fp);
/* 读取 */
fp = fopen("N0:/test.bin", "rb");
if (!fp) {
printf("FAIL: fopen read\r\n");
return;
}
size_t r = fread(read_buf, 1, 512, fp);
printf("Read: %d bytes\r\n", r);
fclose(fp);
/* 比较 */
if (memcmp(buf, read_buf, 512) == 0) {
printf("PASS: Data matches!\r\n");
} else {
printf("FAIL: Byte[0]=0x%02X (expected 0xAB)\r\n", read_buf[0]);
}
} 测试fs,=== File RW Test ===
Write: 512 bytes
Read: 512 bytes
FAIL: Byte[0]=0xC8 (expected 0xAB) 数据不对,挂载,格式化都没问题。 |
|