Readinf file from sdcard while in task

bruce4243 wrote on Tuesday, August 16, 2016:

I’m able to open and read files from an sdcard during an initialization section of code before starting the scheduler. I try to open and read a file from the same sdcard within a task after the scheduler is started and am not able to perform the read.

I don’t get an error opening the file; however, when attempting a read I get an error:
FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */

I tried suspending the scheduler before the read, using critical sections etc, but am not able to perform a read. Any suggestions on how to proceed?

rtel wrote on Tuesday, August 16, 2016:

Which file system are you using?
Where did the integration come from?
How is the driver written - polling or interrupt driven?

bruce4243 wrote on Tuesday, August 16, 2016:

I’m using the FAT file system. The integration came from FreeRTOS. I’m not sure how the driver is written.

The versions are:
FATFS 8255 / Revision ID /
tskKERNEL_VERSION_NUMBER “V8.0.0”

To open the file:
FRESULT Res = f_open(&fil, path, flags);
To read the file:
FRESULT = f_read((FIL*)fh, dst, size*num, &nRead);

I have no error opening it, just readig it. As a test I was able to open and read that same file before starting the scheduler.

rtel wrote on Wednesday, August 17, 2016:

I’m using the FAT file system

That doesn’t narrow it down much…

FATFS

…but that does.

I’m not sure how the driver is written

Hmm. I think you are going to have to look at that as, without knowing what it is doing, you will not know if it is safe to use in a mult-threaded application.

FATFS itself has a configuration parameter that, with the provision of a small FreeRTOS port layer, wraps its API functions with macros that take and then give a semaphore to make the API functions thread safe, but the driver needs to be thread safe too (and compatible with FreeRTOS if it is using interrupts).

bruce4243 wrote on Wednesday, August 17, 2016:

I checked more about the FATFS integration and found it is from Xilinx for the zynq chip, not FreeRTOS. The driver that it reads the sdcard in ADMA2 polled mode.

This is not a perminate piece of code, it’s a stop-gap until other functionality is ready. If it’s a threading issue I’m fine with pausing the scheduler, but when I tried that it still did not work. Shouldn’t it be enough to halt the scheduler when doing the read from sdcard?

bruce4243 wrote on Wednesday, August 17, 2016:

The problem was, in addition to pausing the scheduler, I had not disabled the D cache, it’s working now in the task. Thanks for the support.