RZ/A Flexible Software Package Documentation
Release v3.3.0
|
|
Functions | |
fsp_err_t | R_SDHI_Open (sdmmc_ctrl_t *const p_api_ctrl, sdmmc_cfg_t const *const p_cfg) |
fsp_err_t | R_SDHI_MediaInit (sdmmc_ctrl_t *const p_api_ctrl, sdmmc_device_t *const p_device) |
fsp_err_t | R_SDHI_Read (sdmmc_ctrl_t *const p_api_ctrl, uint8_t *const p_dest, uint32_t const start_sector, uint32_t const sector_count) |
fsp_err_t | R_SDHI_Write (sdmmc_ctrl_t *const p_api_ctrl, uint8_t const *const p_source, uint32_t const start_sector, uint32_t const sector_count) |
fsp_err_t | R_SDHI_ReadIo (sdmmc_ctrl_t *const p_api_ctrl, uint8_t *const p_data, uint32_t const function, uint32_t const address) |
fsp_err_t | R_SDHI_WriteIo (sdmmc_ctrl_t *const p_api_ctrl, uint8_t *const p_data, uint32_t const function, uint32_t const address, sdmmc_io_write_mode_t const read_after_write) |
fsp_err_t | R_SDHI_ReadIoExt (sdmmc_ctrl_t *const p_api_ctrl, uint8_t *const p_dest, uint32_t const function, uint32_t const address, uint32_t *const count, sdmmc_io_transfer_mode_t transfer_mode, sdmmc_io_address_mode_t address_mode) |
fsp_err_t | R_SDHI_WriteIoExt (sdmmc_ctrl_t *const p_api_ctrl, uint8_t const *const p_source, uint32_t const function, uint32_t const address, uint32_t const count, sdmmc_io_transfer_mode_t transfer_mode, sdmmc_io_address_mode_t address_mode) |
fsp_err_t | R_SDHI_IoIntEnable (sdmmc_ctrl_t *const p_api_ctrl, bool enable) |
fsp_err_t | R_SDHI_StatusGet (sdmmc_ctrl_t *const p_api_ctrl, sdmmc_status_t *const p_status) |
fsp_err_t | R_SDHI_Erase (sdmmc_ctrl_t *const p_api_ctrl, uint32_t const start_sector, uint32_t const sector_count) |
fsp_err_t | R_SDHI_CallbackSet (sdmmc_ctrl_t *const p_api_ctrl, void(*p_callback)(sdmmc_callback_args_t *), void const *const p_context, sdmmc_callback_args_t *const p_callback_memory) |
fsp_err_t | R_SDHI_Close (sdmmc_ctrl_t *const p_api_ctrl) |
Driver for the SD/MMC Host Interface (SDHI) peripheral on RZ MPUs. This module implements the SD/MMC Interface.
NOTE: This document includes instructions for eMMC, but they are not supported in this version. NOTE: SD and SDIO support can only be used exclusively.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Unaligned Access Support |
| Enabled | If enabled, code for supporting buffers that are not aligned on a 4-byte boundary is included in the build. Only disable this if all buffers passed to the driver are 4-byte aligned. |
SD Support |
| Enabled | If selected code for SD card support is included in the build. |
SDIO Support |
| Disabled | If selected code for SDIO card support is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
Name | Name must be a valid C symbol | g_sdmmc0 | Module name. |
Channel | Value must be a non-negative integer | 0 | Select the channel. |
Bus Width | MCU Specific Options | Select the bus width. | |
Block Size | Value must be an integer between 1 and 512 | 512 | Select the media block size. Must be 512 for SD cards or eMMC devices. Must be 1-512 for SDIO. |
Card Detection |
| CD Pin | Select the card detection method. |
Write Protection |
| WP Pin | Select whether or not to use the write protect pin. Select Not Used if the MPU or device does not have a write protect pin. |
Callback | Name must be a valid C symbol | NULL | A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR). |
OXMN Interrupt Priority | Illegal interrupt priority level | 24 | OXMN interrupt priority(0-31). Note: If you specify the lowest priority (i.e.,31), no interrupt will occur. |
OXASIO Interrupt Priority | Illegal interrupt priority level | 24 | OXASIO interrupt priority(0-31). Note: If you specify the lowest priority (i.e.,31), no interrupt will occur. |
The following interrupts are required to use the r_sdhi module:
Using SD/MMC with internal DMAC:
The Card interrupt is optional and only available on MPU packages that have the SDnCD pin (n = channel number).
The SDMMC MPU peripheral (SDHI) uses the SDnΦ for its clock source. The SDMMC driver selects the optimal built-in divider based on the SDnΦ frequency and the maximum clock rate allowed by the device obtained at media initialization. (n = channel number)
The SDMMC driver supports the following pins (n = channel number):
The drive capacity for each pin should be set to "Medium" or "High" for most hardware designs. This can be configured in the Pins tab of the RZ Configuration editor by selecting the pin under Pin Selection -> Ports.
When Card Detection is configured to "CD Pin" in the RZ Configuration editor, interrupt flags are cleared and card detection is enabled during R_SDHI_Open().
R_SDHI_StatusGet() can be called to retrieve the current status of the card (including whether a card is present). If the Card Interrupt Priority is enabled, a callback is called when a card is inserted or removed.
If a card is removed and reinserted, R_SDHI_MediaInit() must be called before reading from the card or writing to the card.
The R_SDHI_MediaInit() API completes the entire device identification and configuration process. This involves several command-response cycles at a bus width of 1 bit and a bus speed of 400 kHz or less.
Developers should be aware of the following limitations when using the SDHI: The second argument of R_SDHI_Read and R_SDHI_Write has the following limitations:
The following functions block execution until the response is received for at least one command:
Once the function returns the status of the operation can be determined via R_SDHI_StatusGet or through receipt of a callback.
This is a basic example of minimal use of the r_sdhi in an application.
This is an example of using SDHI when the card may not be plugged in. The card detection interrupt must be enabled to use this example.
fsp_err_t R_SDHI_Open | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
sdmmc_cfg_t const *const | p_cfg | ||
) |
Opens the driver. Resets SDHI, and enables card detection interrupts if card detection is enabled. R_SDHI_MediaInit must be called after this function before any other functions can be used.
Implements sdmmc_api_t::open().
Example:
FSP_SUCCESS | Module is now open. |
FSP_ERR_ASSERTION | Null Pointer or block size is not in the valid range of 1-512. Block size must be 512 bytes for SD cards and eMMC devices. It is configurable for SDIO only. |
FSP_ERR_ALREADY_OPEN | Driver has already been opened with this instance of the control structure. |
FSP_ERR_IRQ_BSP_DISABLED | Access interrupt is not enabled. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | Requested channel does not exist on this MCU. |
fsp_err_t R_SDHI_MediaInit | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
sdmmc_device_t *const | p_device | ||
) |
Initializes the SDHI hardware and completes identification and configuration for the SD or eMMC device. This procedure requires several sequential commands. This function blocks until all identification and configuration commands are complete.
Implements sdmmc_api_t::mediaInit().
Example:
FSP_SUCCESS | Module is now ready for read/write access. |
FSP_ERR_ASSERTION | Null Pointer or block size is not in the valid range of 1-512. Block size must be 512 bytes for SD cards and eMMC devices. It is configurable for SDIO only. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_INIT_FAILED | Device was not identified as an SD card, eMMC device, or SDIO card. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Device is holding DAT0 low (device is busy) or another operation is ongoing. |
fsp_err_t R_SDHI_Read | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint8_t *const | p_dest, | ||
uint32_t const | start_sector, | ||
uint32_t const | sector_count | ||
) |
Reads data from an SD or eMMC device. Up to 0x10000 sectors can be read at a time. Implements sdmmc_api_t::read().
A callback with the event SDMMC_EVENT_TRANSFER_COMPLETE is called when the read data is available.
Example:
FSP_SUCCESS | Data read successfully. |
FSP_ERR_ASSERTION | NULL pointer. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Driver is busy with a previous operation. |
fsp_err_t R_SDHI_Write | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint8_t const *const | p_source, | ||
uint32_t const | start_sector, | ||
uint32_t const | sector_count | ||
) |
Writes data to an SD or eMMC device. Up to 0x10000 sectors can be written at a time. Implements sdmmc_api_t::write().
A callback with the event SDMMC_EVENT_TRANSFER_COMPLETE is called when the all data has been written and the device is no longer holding DAT0 low to indicate it is busy.
Example:
FSP_SUCCESS | Card write finished successfully. |
FSP_ERR_ASSERTION | Handle or Source address is NULL. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_DEVICE_BUSY | Driver is busy with a previous operation. |
FSP_ERR_CARD_WRITE_PROTECTED | SD card is Write Protected. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
fsp_err_t R_SDHI_ReadIo | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint8_t *const | p_data, | ||
uint32_t const | function, | ||
uint32_t const | address | ||
) |
The Read function reads a one byte register from an SDIO card. Implements sdmmc_api_t::readIo().
This function blocks until the command is sent and the response is received. p_data contains the register value read when this function returns.
FSP_SUCCESS | Data read successfully. |
FSP_ERR_ASSERTION | NULL pointer. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_UNSUPPORTED | SDIO support disabled in SDHI_CFG_SDIO_SUPPORT_ENABLE. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Device is holding DAT0 low (device is busy) or another operation is ongoing. |
fsp_err_t R_SDHI_WriteIo | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint8_t *const | p_data, | ||
uint32_t const | function, | ||
uint32_t const | address, | ||
sdmmc_io_write_mode_t const | read_after_write | ||
) |
Writes a one byte register to an SDIO card. Implements sdmmc_api_t::writeIo().
This function blocks until the command is sent and the response is received. The register has been written when this function returns. If read_after_write is true, p_data contains the register value read when this function returns.
FSP_SUCCESS | Card write finished successfully. |
FSP_ERR_ASSERTION | Handle or Source address is NULL. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_WRITE_FAILED | Write operation failed. |
FSP_ERR_UNSUPPORTED | SDIO support disabled in SDHI_CFG_SDIO_SUPPORT_ENABLE. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Device is holding DAT0 low (device is busy) or another operation is ongoing. |
fsp_err_t R_SDHI_ReadIoExt | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint8_t *const | p_dest, | ||
uint32_t const | function, | ||
uint32_t const | address, | ||
uint32_t *const | count, | ||
sdmmc_io_transfer_mode_t | transfer_mode, | ||
sdmmc_io_address_mode_t | address_mode | ||
) |
Reads data from an SDIO card function. Implements sdmmc_api_t::readIoExt().
This function blocks until the command is sent and the response is received. A callback with the event SDMMC_EVENT_TRANSFER_COMPLETE is called when the read data is available.
FSP_SUCCESS | Data read successfully. |
FSP_ERR_ASSERTION | NULL pointer, or count is not in the valid range of 1-512 for byte mode or 1-511 for block mode. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Driver is busy with a previous operation. |
FSP_ERR_UNSUPPORTED | SDIO support disabled in SDHI_CFG_SDIO_SUPPORT_ENABLE. |
fsp_err_t R_SDHI_WriteIoExt | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint8_t const *const | p_source, | ||
uint32_t const | function, | ||
uint32_t const | address, | ||
uint32_t const | count, | ||
sdmmc_io_transfer_mode_t | transfer_mode, | ||
sdmmc_io_address_mode_t | address_mode | ||
) |
Writes data to an SDIO card function. Implements sdmmc_api_t::writeIoExt().
This function blocks until the command is sent and the response is received. A callback with the event SDMMC_EVENT_TRANSFER_COMPLETE is called when the all data has been written.
FSP_SUCCESS | Card write finished successfully. |
FSP_ERR_ASSERTION | NULL pointer, or count is not in the valid range of 1-512 for byte mode or 1-511 for block mode. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Driver is busy with a previous operation. |
FSP_ERR_UNSUPPORTED | SDIO support disabled in SDHI_CFG_SDIO_SUPPORT_ENABLE. |
fsp_err_t R_SDHI_IoIntEnable | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
bool | enable | ||
) |
Enables or disables the SDIO Interrupt. Implements sdmmc_api_t::ioIntEnable().
FSP_SUCCESS | Card enabled or disabled SDIO interrupts successfully. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_ASSERTION | NULL pointer. |
FSP_ERR_DEVICE_BUSY | Driver is busy with a previous operation. |
FSP_ERR_UNSUPPORTED | SDIO support disabled in SDHI_CFG_SDIO_SUPPORT_ENABLE. |
fsp_err_t R_SDHI_StatusGet | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
sdmmc_status_t *const | p_status | ||
) |
Provides driver status. Implements sdmmc_api_t::statusGet().
FSP_SUCCESS | Status stored in p_status. |
FSP_ERR_ASSERTION | NULL pointer. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
fsp_err_t R_SDHI_Erase | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
uint32_t const | start_sector, | ||
uint32_t const | sector_count | ||
) |
Erases sectors of an SD card or eMMC device. Implements sdmmc_api_t::erase().
This function blocks until the erase command is sent. Poll the status to determine when erase is complete.
FSP_SUCCESS | Erase operation requested. |
FSP_ERR_ASSERTION | A required pointer is NULL or an argument is invalid. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_NOT_INITIALIZED | Card was unplugged. |
FSP_ERR_CARD_WRITE_PROTECTED | SD card is Write Protected. |
FSP_ERR_RESPONSE | Device responded with an error. |
FSP_ERR_TIMEOUT | Device did not respond. |
FSP_ERR_DEVICE_BUSY | Device is holding DAT0 low (device is busy) or another operation is ongoing. |
fsp_err_t R_SDHI_CallbackSet | ( | sdmmc_ctrl_t *const | p_api_ctrl, |
void(*)(sdmmc_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
sdmmc_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback with the option to provide memory for the callback argument structure. Implements sdmmc_api_t::callbackSet.
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
fsp_err_t R_SDHI_Close | ( | sdmmc_ctrl_t *const | p_api_ctrl | ) |
Closes an open SD/MMC device. Implements sdmmc_api_t::close().
FSP_SUCCESS | Successful close. |
FSP_ERR_ASSERTION | The parameter p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |