mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-06 04:48:44 +00:00
[update][fatfs] add write read test
This commit is contained in:
parent
05e403062c
commit
223589e8d9
2 changed files with 156 additions and 3 deletions
|
@ -55,16 +55,167 @@ void filesystem_init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SDU_DATA_CHECK 1
|
||||||
|
|
||||||
|
char test_data[] =
|
||||||
|
"I've been reading books of old \r\n\
|
||||||
|
The legends and the myths \r\n\
|
||||||
|
Achilles and his gold \r\n\
|
||||||
|
Hercules and his gifts \r\n\
|
||||||
|
Spiderman's control \r\n\
|
||||||
|
And Batman with his fists\r\n\
|
||||||
|
And clearly I don't see myself upon that list\r\n\
|
||||||
|
But she said, where'd you wanna go?\r\n\
|
||||||
|
How much you wanna risk?\r\n\
|
||||||
|
I'm not looking for somebody\r\n\
|
||||||
|
With some superhuman gifts\r\n\
|
||||||
|
Some superhero\r\n\
|
||||||
|
Some fairytale bliss\r\n\
|
||||||
|
Just something I can turn to\r\n\
|
||||||
|
Somebody I can kiss\r\n\
|
||||||
|
I want something just like this\r\n\r\n";
|
||||||
|
|
||||||
|
BYTE RW_Buffer[32 * 1024] = { 0 };
|
||||||
|
#if SDU_DATA_CHECK
|
||||||
|
BYTE Check_Buffer[sizeof(RW_Buffer)] = { 0 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void fatfs_write_read_test()
|
||||||
|
{
|
||||||
|
FRESULT ret;
|
||||||
|
FIL fnew;
|
||||||
|
UINT fnum;
|
||||||
|
|
||||||
|
uint32_t time_node, i, j;
|
||||||
|
|
||||||
|
/* full test data to buff */
|
||||||
|
for (uint32_t size = 0; size < (sizeof(RW_Buffer) - sizeof(test_data)); size += sizeof(test_data)) {
|
||||||
|
memcpy(&RW_Buffer[size], test_data, sizeof(test_data));
|
||||||
|
#if SDU_DATA_CHECK
|
||||||
|
memcpy(&Check_Buffer[size], test_data, sizeof(test_data));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write test */
|
||||||
|
LOG_I("\r\n******************** be about to write test... **********************\r\n");
|
||||||
|
ret = f_open(&fnew, "sd:test_file.txt", FA_CREATE_ALWAYS | FA_WRITE);
|
||||||
|
if (ret == FR_OK) {
|
||||||
|
time_node = (uint32_t)bflb_mtimer_get_time_ms();
|
||||||
|
/*write into file*/
|
||||||
|
ret = f_write(&fnew, RW_Buffer, 1024, &fnum);
|
||||||
|
for (i = 0; i < 1024; i++) {
|
||||||
|
ret = f_write(&fnew, RW_Buffer, sizeof(RW_Buffer), &fnum);
|
||||||
|
if (ret) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close file */
|
||||||
|
ret |= f_close(&fnew);
|
||||||
|
/* get time */
|
||||||
|
time_node = (uint32_t)bflb_mtimer_get_time_ms() - time_node;
|
||||||
|
|
||||||
|
if (ret == FR_OK) {
|
||||||
|
LOG_I("Write Test Succeed! \r\n");
|
||||||
|
LOG_I("Single data size:%d Byte, Write the number:%d, Total size:%d KB\r\n", sizeof(RW_Buffer), i, sizeof(RW_Buffer) * i >> 10);
|
||||||
|
LOG_I("Time:%dms, Write Speed:%d KB/s \r\n", time_node, ((sizeof(RW_Buffer) * i) >> 10) * 1000 / time_node);
|
||||||
|
} else {
|
||||||
|
LOG_F("Fail to write files(%d) num:%d\n", ret, i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG_F("Fail to open or create files.\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read test */
|
||||||
|
LOG_I("\r\n******************** be about to read test... **********************\r\n");
|
||||||
|
ret = f_open(&fnew, "sd:test_file.txt", FA_OPEN_EXISTING | FA_READ);
|
||||||
|
if (ret == FR_OK) {
|
||||||
|
time_node = (uint32_t)bflb_mtimer_get_time_ms();
|
||||||
|
|
||||||
|
ret = f_read(&fnew, RW_Buffer, 1024, &fnum);
|
||||||
|
for (i = 0; i < 1024; i++) {
|
||||||
|
ret = f_read(&fnew, RW_Buffer, sizeof(RW_Buffer), &fnum);
|
||||||
|
if (ret) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* close file */
|
||||||
|
ret |= f_close(&fnew);
|
||||||
|
/* get time */
|
||||||
|
time_node = (uint32_t)bflb_mtimer_get_time_ms() - time_node;
|
||||||
|
|
||||||
|
if (ret == FR_OK) {
|
||||||
|
LOG_I("Read Test Succeed! \r\n");
|
||||||
|
LOG_I("Single data size:%dByte, Read the number:%d, Total size:%d KB\r\n", sizeof(RW_Buffer), i, sizeof(RW_Buffer) * i >> 10);
|
||||||
|
LOG_I("Time:%dms, Read Speed:%d KB/s \r\n", time_node, ((sizeof(RW_Buffer) * i) >> 10) * 1000 / time_node);
|
||||||
|
} else {
|
||||||
|
LOG_F("Fail to read file: (%d), num:%d\n", ret, i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG_F("Fail to open files.\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check data */
|
||||||
|
#if SDU_DATA_CHECK
|
||||||
|
LOG_I("\r\n******************** be about to check test... **********************\r\n");
|
||||||
|
ret = f_open(&fnew, "sd:test_file.txt", FA_OPEN_EXISTING | FA_READ);
|
||||||
|
if (ret == FR_OK) {
|
||||||
|
ret = f_read(&fnew, RW_Buffer, 1024, &fnum);
|
||||||
|
for (i = 0; i < 1024; i++) {
|
||||||
|
ret = f_read(&fnew, RW_Buffer, sizeof(RW_Buffer), &fnum);
|
||||||
|
if (ret) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (j = 0; j < sizeof(RW_Buffer); j++) {
|
||||||
|
if (RW_Buffer[j] != Check_Buffer[j]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j < sizeof(RW_Buffer)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* close file */
|
||||||
|
ret |= f_close(&fnew);
|
||||||
|
|
||||||
|
if (ret == FR_OK) {
|
||||||
|
if (i < 1024 || j < sizeof(RW_Buffer)) {
|
||||||
|
LOG_I("Check Test Error! \r\n");
|
||||||
|
LOG_I("Data Error! Num:%d/1024, Byte:%d/%d", i, j, sizeof(RW_Buffer));
|
||||||
|
} else {
|
||||||
|
LOG_I("Check Test Succeed! \r\n");
|
||||||
|
LOG_I("All Data Is Good! \r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
LOG_F("Fail to read file: (%d), num:%d\n", ret, i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG_F("Fail to open files.\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
board_init();
|
board_init();
|
||||||
|
|
||||||
filesystem_init();
|
filesystem_init();
|
||||||
|
|
||||||
|
fatfs_write_read_test();
|
||||||
|
|
||||||
|
#ifdef CONFIG_VLIBC
|
||||||
|
LOG_I("\r\n******************** be about to vlibc test... **********************\r\n");
|
||||||
vlibc_file_t *fp = vlibc_fopen("sd:/test.txt", "w");
|
vlibc_file_t *fp = vlibc_fopen("sd:/test.txt", "w");
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
LOG_I("open file error\r\n");
|
LOG_F("open file error\r\n");
|
||||||
} else {
|
} else {
|
||||||
LOG_I("open file success\r\n");
|
LOG_I("open file success\r\n");
|
||||||
for (uint8_t i = 0; i < 10; i++) {
|
for (uint8_t i = 0; i < 10; i++) {
|
||||||
|
@ -76,6 +227,8 @@ int main(void)
|
||||||
LOG_I("close file success\r\n");
|
LOG_I("close file success\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
bflb_mtimer_delay_ms(200);
|
bflb_mtimer_delay_ms(200);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
set(CONFIG_VLIBC 1)
|
set(CONFIG_VLIBC 1)
|
||||||
set(CONFIG_VLIBC_FATFS 1)
|
set(CONFIG_VLIBC_FATFS 1)
|
||||||
|
|
||||||
set(CONFIG_BFLOG 1)
|
set(CONFIG_BFLOG 0)
|
||||||
set(CONFIG_FATFS 1)
|
set(CONFIG_FATFS 1)
|
||||||
|
|
||||||
set(CONFIG_BSP_COMMON 1)
|
set(CONFIG_BSP_COMMON 1)
|
||||||
set(CONFIG_BSP_SDH_SDCARD 1)
|
set(CONFIG_BSP_SDH_SDCARD 1)
|
||||||
set(CONFIG_BSP_FATFS_SDH_SDCARD 1)
|
set(CONFIG_FATFS_SDH_SDCARD 1)
|
Loading…
Add table
Add a link
Reference in a new issue