sdspi, vfs_fat: allow sharing SPI bus among devices, and mounting multiple SD cards
This commit is contained in:
@@ -4,33 +4,35 @@ SD SPI Host Driver
|
||||
Overview
|
||||
--------
|
||||
|
||||
The SD SPI host driver allows using the SPI2 (HSPI) or SPI3 (VSPI) controller for communication with SD cards.
|
||||
The SD SPI host driver allows communicating with one or more SD cards by the SPI Master driver which makes use of the SPI host. Each card is accessed through an SD SPI device represented by an `sdspi_dev_handle_t` spi_handle returned when attaching the device to an SPI bus by calling `sdspi_host_init_device`. The bus should be already initialized before (by `spi_bus_initialize`).
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
This driver's naming pattern was adopted from the :doc:`SDMMC Host <sdmmc_host>` driver due to their similarity. Likewise, the APIs of both drivers are also very similar.
|
||||
|
||||
The SD SPI host driver has the following modes:
|
||||
SD SPI driver (access the SD card in SPI mode) offers lower throughput but makes pin selection more flexible. With the help of the GPIO matrix, an SPI peripheral's signals can be routed to any {IDF_TARGET_NAME} pin. Otherwise, if SDMMC host driver is used (See :doc:`SDMMC Host <sdmmc_host>`) to access the card in SD 1-bit/4-bit mode, higher throughput can be reached but it requires routing the signals through their dedicated IO_MUX pins only.
|
||||
|
||||
- **SPI mode**: offers lower throughput but makes pin selection more flexible. With the help of the GPIO matrix, an SPI peripheral's signals can be routed to any {IDF_TARGET_NAME} pin.
|
||||
- **1-bit SD mode**: offers higher throughput but requires routing the signals through their dedicated IO_MUX pins only.
|
||||
With the help of :doc:`SPI Master driver <spi_master>` based on, the SPI bus can be shared among SD cards and other SPI devices. The SPI Master driver will handle exclusive access from different tasks.
|
||||
|
||||
The SD SPI driver uses software-controlled CS signal.
|
||||
|
||||
Currently, the SD SPI driver cannot handle multi-threaded environments as does not support time-division multiplexing on the same SPI bus. It means that if your application needs to communicate with an SD card and other devices on the same SPI bus, the application itself must ensure that its different tasks do not try to access the SPI slaves at the same time.
|
||||
|
||||
|
||||
How to Use
|
||||
----------
|
||||
|
||||
The state and configurations of the SD SPI host driver are stored in a :cpp:type:`sdmmc_host_t` structure. This structure can be initialized using the :c:macro:`SDSPI_HOST_DEFAULT` macro.
|
||||
Firstly, use the macro :c:macro:`SDSPI_DEVICE_CONFIG_DEFAULT` to initialize a structure :cpp:type:`sdmmc_slot_config_t`, which is used to initialize an SD SPI device. This macro will also fill in the default pin mappings, which is same as the pin mappings of SDMMC host driver. Modify the host and pins of the structure to desired value. Then call `sdspi_host_init_device` to initialize the SD SPI device and attach to its bus.
|
||||
|
||||
The state and configurations of the SD slot are stored in a :cpp:type:`sdmmc_slot_config_t` structure. Use the macro :c:macro:`SDSPI_SLOT_CONFIG_DEFAULT` to initialize the structure and to fill in the default pin mappings (SD mode pin mappings).
|
||||
Then use :c:macro:`SDSPI_HOST_DEFAULT` macro to initialize a :cpp:type:`sdmmc_host_t` structure, which is used to store the state and configurations of upper layer (SD/SDIO/MMC driver). Modify the `slot` parameter of the structure to the SD SPI device spi_handle just returned from `sdspi_host_init_device`. Call `sdmmc_card_init` with the :cpp:type:`sdmmc_host_t` to probe and initialize the SD card.
|
||||
|
||||
Now you can use SD/SDIO/MMC driver functions to access your card!
|
||||
|
||||
Other Details
|
||||
-------------
|
||||
|
||||
Only the following driver's API functions are normally used by most applications:
|
||||
|
||||
- :cpp:func:`sdspi_host_init`
|
||||
- :cpp:func:`sdspi_host_init_slot`
|
||||
- :cpp:func:`sdspi_host_init_device`
|
||||
- :cpp:func:`sdspi_host_remove_device`
|
||||
- :cpp:func:`sdspi_host_deinit`
|
||||
|
||||
Other functions are mostly used by the protocol level SD/SDIO/MMC driver via function pointers in the :cpp:type:`sdmmc_host_t` structure. For more details, see :doc:`the SD/SDIO/MMC Driver <../storage/sdmmc>`.
|
||||
|
||||
Reference in New Issue
Block a user