Page 1 of 1

Using MMC driver with other SPI devices

Posted: Sun Jul 14, 2019 6:05 pm
by HDKLog
Hello,
I've got one of these TFT display breakout boards with SD card socket which shares same SPI interface with display. I already wrote driver which communicates with display and follows ChibiOS Hal communication with mutual exclusion:

Code: Select all

spiAcquireBus()
spiStart()
spiSelect()

//spiSend(), spiReceive() and spiExchange() calls

spiUnselect();
spiReleaseBus();


The problem is that MMC driver encapsulates SPI calls and uses SPI without mutual exclusions and it doesn't follow calling sequence I described above (for example mmcConnect() just starts SPI driver, establishes connection with SD card and live driver in that state), which is a problem because I can't use same SPI for communication with different SPI devices at same bus. I can't use communication between mmcConnect() and mmcConnect() because I already have USB driver, which pulls data frequently and that will be performance penalty if I will connect and disconnect driver on every block reading and writing operation. Is there some workaround or fixes for my issue?

Best regards, Harry.

Re: Using MMC driver with other SPI devices

Posted: Sun Jul 14, 2019 6:19 pm
by Giovanni
Hi,

The MMC driver calls spiStart() each time you call a function in that module, this means that you can configure SPI as you like using another configuration. This can be used when SPI is shared between an SDMMC device and other peripherals using separate CSs.

If you need mutual exclusion then you have to aquire before calling MMC function and release afterward, this is required because some operations are split in multiple function calls, you need to keep the whole sequence in the same mutual exclusion zone. See mmcStartSequentialWrite(), mmcSequentialWrite(), mmcStopSequentialWrite() for example.

Giovanni

Re: Using MMC driver with other SPI devices

Posted: Mon Jul 15, 2019 5:50 pm
by HDKLog
So each time I call any MMC driver function I should put it in between spiAcquireBus() and spiReleaseBus() and also if I use FATFS library i should put all FATFS function calls between them. Shouldn't be nice to have these all encapsulated in MMC driver functions calls and option like HAL_USE_MMC_SPI_MUTUAL_EXCLUSION in halconf.h to enable or disable it?

Re: Using MMC driver with other SPI devices

Posted: Mon Jul 15, 2019 5:55 pm
by Giovanni
That would have to go in fatfs_diskio eventually, not around FatFS function calls.

Giovanni