I admit that I have used FatFS only with an RTOS. Good that you are using it in another context, that helps to improve things :smileyhappy:. I had to make some changes to the FAT_FileSystem and SD_Card components in order to work with your scenario.
There are two things:
a) The 'Reentrant' property controls the FatFS _FS_REENTRANT flag.
This controls the reentrancy of FatFS (not directly the parallel access of the SPI bus!). Enabling _FS_REENTRANT, you have two choices: use the RTOS to create a semaphore (e.g. FreeRTOS): this ensures that multiple tasks can access FatFS. If you are not using an RTOS, then you can provide a name for the lock handle (e.g. HANDLE or int, as in the properties) and do whatever you want with it. But this means that you need to provide your own implementation of ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant() and ff_rel_grant().
b) parallel access to the SPI bus: that must be done on a lower level: on the SD card SPI access level. Still you need to implement in your application a synchronization method to avoid parallel bus access. This can be done with the OnActivate() and OnDeactivate() events in the SD_Card
I think in your case the best thing is:
- in the FatFS component, have 'User Sync Functions' (see below) set to 'no' with RTOS set to 'disabled': this will just call the lower level Activate() and Deactivate() methods.
- in the SD_Card component enable the events OnActivate() and OnDeactivate(). Implement your own synchronization method in the event callback for these (events.c)
What happens: FatFS will use ff_cre_syncobj(), ff_del_syncobj(), ff_req_grant() and ff_rel_grant(), and they will call the SD card Activate() and Deactivate(). And your user code will make sure in the event callbacks that nobody is accessing the SPI bus in parallel.
- I have uploaded the new FatFS component to the website:
http://www.steinerberg.com/EmbeddedComponents/FAT_FileSystem/ (V1.115)
http://www.steinerberg.com/EmbeddedComponents/SD_Card (V1.149)
I hope that works for you?
Thanks!
BK