title: Passing the workspace created with f_mount to another source file
body: <p>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.</p>
  
  <p>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).</p>
  
  <p>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... </p>
  
  <p>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. </p>
  
  <p>This is an STM32L476RG using the GNU-ARM tool chain and OpenOCD build tools.  </p>
  
  <p>Code is all pretty standard FATFS stuff. The SD mount function in the SD.cpp: </p>
  
  <pre><code>FATFS fs;
  bool isMounted = false;
  
  FRESULT fsMountSd(){
      FRESULT res = f_mount(&amp;fs, "0:", 1);
      if( res == FR_OK) isMounted = true;
      if (isMounted = true){
      CLI_printMessage("SD Card mounted");
      }
      return res;
  }
  </code></pre>
  
  <p>This returns FR_OK and prints "SD Card mounted" to the CLI. </p>
  
  <p>Then there's my own FatFs operations in the myfile.cpp: </p>
  
  <pre><code>FIL config; //file object of  from the SD card
  
  
  FRESULT fr;
  FILINFO fno;
  
  //check for config.txt file
  fr = f_stat("0:config.txt", &amp;fno);    //check for config.txt file
  
  if (fr == FR_OK){
        CLI_printMessage("File found!");
  }
  </code></pre>
  
  <p>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.  </p>
  
  <p>I've also tried utilizing pointers in the sd.cpp mount function: </p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>When I tried this I also added the line "extern FATFS* fs;" to the sd.h file. Unfortunately this was also unsuccessful. </p>
  
  <p>Worth adding that I've read over all documentation on the highly informative <a href="http://elm-chan.org/fsw/ff/00index_e.html" rel="nofollow noreferrer">Fatfs support page</a>.</p>
  
  <p>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!</p>