SDIO HOST API 参考
该模块分为两个部分 API, 包括 SDH SDMMC 和 SDH SPI
SDH SDMMC Macros
-
WM_DRV_SDH_SDMMC_MAX_NUM_BLOCKS
Defines the maximum number of blocks supported by the SDHC/SDMMC driver.
SDH SDMMC Enumerations
-
enum wm_drv_sdh_sdmmc_card_type_t
Enumeration for SDH_SDMMC card types.
Values:
-
enumerator WM_DRV_SDH_SDMMC_CARD_TYPE_SD
Standard SD card
-
enumerator WM_DRV_SDH_SDMMC_CARD_TYPE_SDSC
SD Standard Capacity
-
enumerator WM_DRV_SDH_SDMMC_CARD_TYPE_SDHC
SD High Capacity
-
enumerator WM_DRV_SDH_SDMMC_CARD_TYPE_MAX
-
enumerator WM_DRV_SDH_SDMMC_CARD_TYPE_SD
SDH SDMMC Structures
-
struct wm_drv_sdh_sdmmc_card_info_t
Structure representing the card information.
Public Members
-
long long capacity
Card capacity in bytes
-
uint32_t block_size
Card block size
-
wm_drv_sdh_sdmmc_card_csd_ver_t csd_ver
CSD version
-
wm_drv_sdh_sdmmc_card_type_t type
Card type
-
uint32_t rca
Relative Card Address
-
long long capacity
SDH SDMMC Functions
-
wm_device_t *wm_drv_sdh_sdmmc_init(char *dev_name)
Initializes the SDH SDMMC device.
This function initializes the SDH SDMMC device using the specified device name. It allocates resources, sets up necessary configurations, and prepares the device for further operations.
- 参数:
dev_name – [in] The name of the device to initialize, as defined in the device tree.
- 返回:
A pointer to the device structure if the initialization succeeds.
NULL if the initialization fails or the device name is not recognized, or the device has already been initialized.
-
int wm_drv_sdh_sdmmc_deinit(wm_device_t *dev)
Deinitializes the SDH SDMMC device.
This function is used to release the resources and stop any ongoing operations of the SDH SDMMC device. It should be called when the device is no longer needed to ensure clean resource management.
- 参数:
dev – [in] Pointer to the device structure that needs to be deinitialized.
- 返回:
WM_ERR_SUCCESS if the deinitialization succeeds.
WM_ERR_INVALID_PARAM if the provided device pointer is NULL or invalid.
Other error codes may be returned based on the specific failure.
-
int wm_drv_sdh_sdmmc_read_blocks(wm_device_t *dev, uint8_t *buf, uint32_t start_block, uint32_t num_blocks)
Reads blocks from the SDH SDMMC device.
This function reads a specified number of data blocks from the SDH SDMMC device starting from the specified block address. It’s used for transferring data from the SDH SDMMC device to the host memory.
备注
The operation block cannot exceed the capacity of the card, otherwise it will result in data loss
The maximum number of num_blocks is 127 blocks
- 参数:
dev – [in] Pointer to the device structure of the SDH SDMMC.
buf – [in] Pointer to the buffer where the read data will be stored.
start_block – [in] The starting block number from where to read the data.
num_blocks – [in] The number of blocks to read.
- 返回:
WM_ERR_SUCCESS if the read operation completes successfully.
WM_ERR_INVALID_PARAM if the device pointer or buffer pointer is NULL, or if the parameters are out of valid range.
Other error codes may be returned to reflect different failure conditions.
-
int wm_drv_sdh_sdmmc_write_blocks(wm_device_t *dev, const uint8_t *buf, uint32_t start_block, uint32_t num_blocks)
Writes blocks to the SDH SDMMC device.
This function writes a specified number of data blocks to the SDH SDMMC device starting from the specified block address. It’s used for transferring data from the host memory to the SDH SDMMC device.
备注
The operation block cannot exceed the capacity of the card, otherwise it will result in data loss
The maximum number of num_blocks is 127 blocks
- 参数:
dev – [in] Pointer to the device structure of the SDH SDMMC.
buf – [in] Pointer to the buffer containing the data to be written.
start_block – [in] The starting block number where the data will be written.
num_blocks – [in] The number of blocks to write.
- 返回:
WM_ERR_SUCCESS if the write operation completes successfully.
WM_ERR_INVALID_PARAM if the device pointer or buffer pointer is NULL, or if the parameters are out of valid range.
Other error codes may be returned to reflect different failure conditions.
-
int wm_drv_sdh_sdmmc_get_card_info(wm_device_t *dev, wm_drv_sdh_sdmmc_card_info_t *card_info)
Gets the card information of the SDH_SDMMC device.
This function retrieves the card information such as capacity, block size, card type, CSD version, RCA, and other relevant details from the SDH_SDMMC device.
- 参数:
dev – [in] Pointer to the device structure.
card_info – [out] Pointer to the structure where the card information will be stored.
- 返回:
WM_ERR_SUCCESS Success
WM_ERR_INVALID_PARAM Invalid parameter
SDH SPI Functions
-
wm_device_t *wm_drv_sdh_spi_init(char *dev_name)
Initializes the SDH_SPI device.
This function initializes the SDH_SPI device using the specified device name. It allocates resources, sets up necessary configurations, and prepares the device for further operations.
- 参数:
dev_name – [in] The name of the device to initialize, as defined in the device tree.
- 返回:
A pointer to the device structure if the initialization succeeds.
NULL if the initialization fails or the device name is not recognized, or the device has already been initialized.
-
int wm_drv_sdh_spi_deinit(wm_device_t *dev)
Deinitializes the SDH_SPI device.
This function is used to release the resources and stop any ongoing operations of the SDH_SPI device. It should be called when the device is no longer needed to ensure clean resource management.
- 参数:
dev – [in] Pointer to the device structure that needs to be deinitialized.
- 返回:
WM_ERR_SUCCESS if the deinitialization succeeds.
WM_ERR_INVALID_PARAM if the provided device pointer is NULL or invalid.
Other error codes may be returned based on the specific failure.
-
int wm_drv_sdh_spi_transceive_sync(wm_device_t *dev, const wm_dt_hw_spim_dev_cfg_t *config, spim_transceive_t *desc, uint32_t ms_to_wait)
Synchronously transmits and receives data through the SDH_SPI device.
This function performs a synchronous data transfer using the SDH_SPI device. It blocks until the operation is complete or the specified timeout is reached.
备注
The freq in the config parameter supports 1/2, 1/4, 1/6, 1/8, 1/10, 1/12, 1/14, 1/16 of the CPU clock, it is recommended not to exceed 60MHz, and the CPU clock corresponding to WM_RCC_TYPE_CPU can be obtained through the RCC module.
The mode in the config parameter only supports 0 (CPOL=0,CPHA=0).
The spim_transceive_t structure’s member parameters tx_buf and tx_len can be used, while other member parameters are not available and are only included to maintain the same API parameters as the SPI master.
The maximum data length is 65536 bytes.
The SDH_SPI is a half-duplex communication interface and cannot perform read and write operations simultaneously.
It is primarily used in scenarios that involve only write operations, such as driving TFT displays.
- 参数:
dev – [in] Pointer to the device structure of the SDH_SPI.
config – [in] Pointer to a structure containing the configuration parameters for the SDH_SPI device.
desc – [in] Pointer to a structure containing the transmission and reception parameters.
ms_to_wait – [in] Maximum time in milliseconds to wait for the operation to complete.
- 返回:
WM_ERR_SUCCESS if the operation completes successfully.
WM_ERR_INVALID_PARAM if the device pointer or description pointer is NULL, or if the parameters are out of valid range.
Other error codes may be returned to reflect different failure conditions.
-
int wm_drv_sdh_spi_transceive_async(wm_device_t *dev, const wm_dt_hw_spim_dev_cfg_t *config, spim_transceive_t *desc, wm_spim_callback_t callback, void *usr_data)
Asynchronously transmits and receives data through the SDH_SPI device.
This function initiates an asynchronous data transfer using the SDH_SPI device. It returns immediately, and the specified callback function is called when the operation is complete or an error occurs.
备注
The freq in the config parameter supports 1/2, 1/4, 1/6, 1/8, 1/10, 1/12, 1/14, 1/16 of the CPU clock, it is recommended not to exceed 60MHz, and the CPU clock corresponding to WM_RCC_TYPE_CPU can be obtained through the RCC module.
The mode in the config parameter only supports 0 (CPOL=0,CPHA=0)
The maximum data length is 65532 bytes.
The spim_transceive_t structure’s member parameters tx_buf and tx_len can be used, while other member parameters are not available and are only included to maintain the same API parameters as the SPI master.
The SDH_SPI is a half-duplex communication interface and cannot perform read and write operations simultaneously.
It is primarily used in scenarios that involve only write operations, such as driving TFT displays.
The data length must be aligned with 4 bytes.
- 参数:
dev – [in] Pointer to the device structure of the SDH_SPI.
config – [in] Pointer to a structure containing the configuration parameters for the SDH_SPI device.
desc – [in] Pointer to a structure containing the transmission and reception parameters.
callback – [in] Function to be called when the operation is complete, cannot perform blocking operations within callback.
usr_data – [in] User-defined data to pass to the callback function.
- 返回:
WM_ERR_SUCCESS if the operation is successfully initiated.
WM_ERR_INVALID_PARAM if the device pointer, description pointer, or callback function is NULL.
Other error codes may be returned to reflect different failure conditions.