RA Flexible Software Package Documentation
Release v5.6.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 RA MCUs. This module implements the SD/MMC Interface.
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. |
eMMC Support |
| Disabled | If selected code for eMMC device 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. | |
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 MCU 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). |
Access Interrupt Priority | MCU Specific Options | Select the access interrupt priority. | |
Card Interrupt Priority | MCU Specific Options | Select the card interrupt priority. | |
DTC Interrupt Priority | MCU Specific Options | Select the DTC interrupt priority. |
The following interrupts are required to use the r_sdhi module:
Using SD/MMC with DTC:
Using SD/MMC with DMAC:
The Card interrupt is optional and only available on MCU packages that have the SDnCD pin (n = channel number).
The SDMMC MCU peripheral (SDHI) uses the PCLKA for its clock source. The SDMMC driver selects the optimal built-in divider based on the PCLKA frequency and the maximum clock rate allowed by the device obtained at media initialization.
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 RA Configuration editor by selecting the pin under Pin Selection -> Ports.
When Card Detection is configured to "CD Pin" in the RA 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.
When data transfers are not 4-byte aligned or not a multiple of 4 bytes, a software copy of the block size (up to 512 bytes) is done in the DMA Request interrupt. This blocks all other interrupts that are a lower or equal priority to the access interrupt until the software copy is complete.
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 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.
Data transfers should be 4-byte aligned and a multiple of 4 bytes in size whenever possible. This recommendation applies to the read(), write(), readIoExt(), and writeIoExt() APIs. When data transfers are 4-byte aligned and a multiple of 4-bytes, the r_sdhi driver is zero copy and takes full advantage of hardware acceleration by the DMAC or DTC. When data transfers are not 4-byte aligned or not a multiple of 4 bytes an extra CPU interrupt is required for each block transferred and a software copy is used to move data to the destination buffer.
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. |
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. |
FSP_ERR_NOT_OPEN | Driver has not been initialized. |
FSP_ERR_CARD_INIT_FAILED | Device was not identified as an SD card or eMMC device. |
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_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_WRITE_FAILED | Write operation failed. |
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().
FSP_ERR_UNSUPPORTED | SDIO is not supported. |
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().
FSP_ERR_UNSUPPORTED | SDIO is not supported. |
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().
FSP_ERR_UNSUPPORTED | SDIO is not supported. |
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().
FSP_ERR_UNSUPPORTED | SDIO is not supported. |
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_ERR_UNSUPPORTED | SDIO is not supported. |
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. |