I'm trying to read a file on an SD card using FATFS in an RTOS. The card successfully mounts in a separate source file in the RTOS, but when I try to use the FatFs operations in my own source file, I get the result FR_NOT_ENABLED.
This is a somewhat strange scenario that requires some context: I am an electronics technician student who has taken on the rather daunting task of re-purposing an MCU and its proprietary RTOS. Within the RTOS, there is already a source file that mounts the SD card (let's call it sd.cpp) and another file (let's call it Sensors.cpp) that writes sensor data files to it. I've made sure to include all relevant header files in my source file (which, for clarity's sake, let's call myfile.cpp).
I've tried a few things: the first was implementing the f_mount operation directly in myfile.cpp. This caused the FR_DISK_ERR result, which I understand is due to the fact that it's already mounted in another file, so that's obviously out of the picture. From there I tried commenting out all instances of the SD card in the Sensors.cpp, but this opens up a real "can of worms" that I'd rather save until other options are exhausted...
I believe what it comes down to is figuring out how to pass the SD workspace from sd.cpp to myfile.cpp. I've tried to study Sensors.cpp to understand how it is done there, but unfortunately its contents is far beyond my comprehension as a mere electronics technician student.
This is an STM32L476RG using the GNU-ARM tool chain and OpenOCD build tools.
Code is all pretty standard FATFS stuff. The SD mount function in the SD.cpp:
FATFS fs;
bool isMounted = false;
FRESULT fsMountSd(){
FRESULT res = f_mount(&fs, "0:", 1);
if( res == FR_OK) isMounted = true;
if (isMounted = true){
CLI_printMessage("SD Card mounted");
}
return res;
}
This returns FR_OK and prints "SD Card mounted" to the CLI.
Then there's my own FatFs operations in the myfile.cpp:
FIL config; //file object of from the SD card
FRESULT fr;
FILINFO fno;
//check for config.txt file
fr = f_stat("0:config.txt", &fno); //check for config.txt file
if (fr == FR_OK){
CLI_printMessage("File found!");
}
This works when I run the f_stat operation in the sd.cpp module, confirming that it's an issue of not finding the file system object in the myfile.cpp.
I've also tried utilizing pointers in the sd.cpp mount function:
FATFS *fs;
bool isMounted = false;
FRESULT fsMountSd(){
FRESULT res = f_mount(fs, "0:", 1);
if( res == FR_OK) isMounted = true;
if (isMounted = true){
CLI_printMessage("SD Card mounted");
}
return res;
}
When I tried this I also added the line "extern FATFS* fs;" to the sd.h file. Unfortunately this was also unsuccessful.
Worth adding that I've read over all documentation on the highly informative Fatfs support page.
So in short: I'm hoping to get FR_OK from this f_stat (checking for the file) in myfile.cpp so I can move on. I hope this was detailed enough, as my last attempt at asking this question on here was very quickly (and understandably) down voted!