uSD card write operation stops after some time.
Hello everyone,
I am student and using the FATFS middleware to log sensor data to a uSD card using stm32f746g dev board. The data gets logged only for the first few minutes (8 minutes) and then the f_write() returns a status as FR_LOCKED (16).
What could be a possible reason to this and is there a way to overcome this issue?
I have attached my custom file write function below for reference.
Appreciate your help and thanks in advance.
Regards.
FRESULT uSD_file_write(char *ptr_filename, char *ptr_write_buffer) {
FRESULT res;
FIL myFile;
uint32_t bytes_written;
// Check uSD card is mounted or not
res = uSD_is_mount();
if(res != FR_OK) {
return res;
}
// 1. try to open file in append and write mode
//res = f_open(&myFile, ptr_filename, FA_OPEN_EXISTING | FA_OPEN_APPEND | FA_WRITE);
res = f_open(&myFile, ptr_filename, FA_OPEN_APPEND | FA_WRITE);
if(res != FR_OK) {
return res;
}
// 2. write data to file
res = f_write(&myFile, ptr_write_buffer, strlen(ptr_write_buffer), (void *)&bytes_written);
//res = f_sync(&myFile); // Flushes cached info of a writing file (NOT NECESSARY THOUGH!!)
// 3. close file
f_close(&myFile);
return res;
}FRESULT uSD_is_mount(void) {
return f_mount(&mySDFatFs, SDPath, MOUNT_IMMEDIATELY);
}