anonymous wrote on Thursday, May 24, 2012:
I am using a STM32 Cortex-M3 and just recently got FatFS up and running with a SD card in SPI mode. I would like to modify the disk_read() and disk_write() functions to use DMA transfers. I understand how to use the DMA peripherals to transfer the data, and how to enable the DMA interrupts so they are triggered when the transfer is complete.
How should I ensure that the disk_read() / disk_write() functions don’t try to trigger another DMA transfer when one is already taking place?
I have read the user manual and searched the forums and it seems like what I need to do is to use a binary semaphore (vSemaphoreCreateBinary()). Then in the beginning of the disk_read()/disk_write() functions, I would call xSemaphoreTake(). Once this returns, I can safely start a DMA transfer. Then, in the DMA interrupt, if the transfer is complete, I would call xSemaphoreGiveFromISR().
I was thinking that I would implement the DMA Interrupt directly in the diskio.c file (where disk_read()/disk_write() ) are implemented, and make the semaphore have file scope so that only disk_read()/disk_write() and the interrupt can touch the semaphore.
Does this seem reasonable? Is there a better/different approach?
The disk_read()/disk_write() functions are called from higher level FatFS functions such as f_read()/f_write(), which themselves would be called from various tasks in my project. Are there any requirements on the implementation of disk_read()/disk_write() to make sure this all works properly? I think they currently both access a variable that is at file scope (disk_status) in diskio.c, will this cause any issues?