RAFW Flexible Software Package Documentation  Release v2.0.1

 
SD/MMC (r_sdemmc_w)

Functions

fsp_err_t R_SDEMMC_W_Open (sdmmc_ctrl_t *const p_api_ctrl, sdmmc_cfg_t const *const p_cfg)
 
fsp_err_t R_SDEMMC_W_MediaInit (sdmmc_ctrl_t *const p_api_ctrl, sdmmc_device_t *const p_device)
 
fsp_err_t R_SDEMMC_W_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_SDEMMC_W_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_SDEMMC_W_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_SDEMMC_W_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_SDEMMC_W_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_SDEMMC_W_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_SDEMMC_W_IoIntEnable (sdmmc_ctrl_t *const p_api_ctrl, bool enable)
 
fsp_err_t R_SDEMMC_W_StatusGet (sdmmc_ctrl_t *const p_api_ctrl, sdmmc_status_t *const p_status)
 
fsp_err_t R_SDEMMC_W_Erase (sdmmc_ctrl_t *const p_api_ctrl, uint32_t const start_sector, uint32_t const sector_count)
 
fsp_err_t R_SDEMMC_W_CallbackSet (sdmmc_ctrl_t *const p_api_ctrl, void(*p_callback)(sdmmc_callback_args_t *), void *const p_context, sdmmc_callback_args_t *const p_callback_memory)
 
fsp_err_t R_SDEMMC_W_ResultGet (sdmmc_ctrl_t *const p_api_ctrl, sdemmc_w_transfer_result_t *p_result)
 
fsp_err_t R_SDEMMC_W_Close (sdmmc_ctrl_t *const p_api_ctrl)
 

Detailed Description

Driver for the SD/MMC Host Interface (SDEMMC_W) peripheral on RA for Wireless (RAFW) MCUs. This module implements the SD/MMC Interface.

Overview

Features

Configuration

Build Time Configurations for r_sdemmc_w

The following build time configurations are defined in fsp_cfg/r_sdemmc_w_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
SD Support
  • Disabled
  • Enabled
Enabled If selected code for SD card support is included in the build.
eMMC Support
  • Disabled
  • Enabled
Disabled If selected code for eMMC device support is included in the build.
SDIO Support
  • Disabled
  • Enabled
Disabled If selected code for SDIO card support is included in the build.

Configurations for Storage > SD/MMC/SDIO (r_sdemmc_w)

This module can be added to the Stacks tab via New Stack > Storage > SD/MMC/SDIO (r_sdemmc_w).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_sdmmc0 Module name.
Bus WidthMCU Specific OptionsSelect the bus width.
Block SizeValue must be an integer between 1 and 512512 Select the media block size. Must be 512 for SD cards or eMMC devices. Must be 1-512 for SDIO.
Clk_divValue must be an integer between 0 and 2550 Clock divide value. Must be 0-255.
Port Selection
  • Port P0_[13:4]
  • Port P1_[3:0] and P1_[15:10]
Port P1_[3:0] and P1_[15:10] Select SD/eMMC/SDIO host port. Must be 0 or 1.
rxclk_in selection
  • clkout signal
  • clkout_inv signal
clkout signal Select SD/eMMC/SDIO rxclk_in selection. Must be 0 or 1.
Pull enable
  • All lines pull disabled
  • CMD and Datas pull enabled
CMD and Datas pull enabled Select SD/eMMC/SDIO PADS mode pull enable.
Pull selection
  • Pull down
  • Pull up
Pull up Set SD/eMMC/SDIO PADS mode pull selection.
Card Detection
  • Not Used
  • CD Pin
Not Used Select the card detection method.
Write Protection
  • Not Used
  • WP Pin
Not Used 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.
CallbackName must be a valid C symbolg_sdmmc0_callback A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR).
Access and Card Interrupt PriorityMCU Specific OptionsSelect the access and card interrupt priority.

Configurations for Connectivity > SDIO Device (r_sdemmc_w)

This module can be added to the Stacks tab via New Stack > Connectivity > SDIO Device (r_sdemmc_w).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_sdmmc_sdio_device0 Module name.
Bus Width
  • 1 Bit
  • 4 Bits
  • 8 Bits
4 Bits Select the bus width.
Block SizeValue must be an integer between 1 and 512512 Select the media block size. Must be 512 for SD cards or eMMC devices. Must be 1-512 for SDIO.
Drive current
  • 2mA
  • 4mA
  • 8mA
  • 14mA
2mA Pads drive current
Port Selection
  • Port P0_[13:8]
  • Port P1_[15:10]
Port P0_[13:8] Select SDIO device port. Must be 0 or 1.
Pull enable
  • All lines pull disabled
  • CMD and Datas pull enabled
CMD and Datas pull enabled Select SDIO device PADS mode pull enable.
Pull selection
  • Pull down
  • Pull up
Pull up Set SDIO device PADS mode pull selection.
CallbackName must be a valid C symbolg_sdio0_callback A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR).
SDIO Interrupt PriorityMCU Specific OptionsSelect the SDIO interrupt priority.

Interrupt Configurations:

The following interrupts are required to use the r_sdemmc_w module:

Using SD/MMC:

Using SDIO Device:

The Card interrupt is optional and only available on MCU packages that have the CDETECT pin.

Clock Configuration

The SDMMC MCU peripheral (SDEMMC_W) uses the PERI_CLK for its clock source. The SDMMC driver selects the optimal built-in divider based on the PERI_CLK frequency and the maximum clock rate allowed by the device obtained at media initialization.

Pin Configuration

The SDMMC driver supports the following pins: port_sel 0

port_sel 1

CDETECT can be assigned any GPIO.

WPROTECT can be assigned any GPIO.

Once the SD host use the port_sel 0, SDIO device should use port_sel 1. And the SD host use the port_sel 1, SDIO device should use port_sel 0.

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 RA6W1/RA6W2 Configuration editor by selecting the pin under Pin Selection -> Ports.

Usage Notes

Card Detection

When Card Detection is configured to "CD Pin" in the RA6W1/RA6W2 Configuration editor, interrupt flags are cleared and card detection is enabled during R_SDEMMC_W_Open().

R_SDEMMC_W_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_SDEMMC_W_MediaInit() must be called before reading from the card or writing to the card.

Note
R_SDEMMC_W_StatusGet() should be used to initially determine the card state after opening the interface.

Timing Notes for R_SDEMMC_W_MediaInit

The R_SDEMMC_W_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.

Limitations

Developers should be aware of the following limitations when using the SDEMMC_W:

Blocking Calls

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_SDEMMC_W_StatusGet or through receipt of a callback.

Note
Due to the variability in clocking configurations it is recommended to determine blocking delays experimentally on the target system.

Examples

Basic Example

This is a basic example of minimal use of the r_sdemmc_w in an application.

uint8_t g_dest[SDEMMC_W_MAX_BLOCK_SIZE] BSP_ALIGN_VARIABLE(4);
uint8_t g_src[SDEMMC_W_MAX_BLOCK_SIZE] BSP_ALIGN_VARIABLE(4);
uint32_t g_transfer_complete = 0;
/* The callback is called when a transfer completes. */
static void r_sdemmc_example_callback (sdmmc_callback_args_t * p_args)
{
{
g_transfer_complete = 1;
}
}
fsp_err_t r_sdemmc_basic_example (void)
{
/* Initialize g_src to known data */
for (uint32_t i = 0; i < SDEMMC_W_MAX_BLOCK_SIZE; i++)
{
g_src[i] = (uint8_t) ('A' + (i % 26));
}
/* Open the SDEMMC_W driver. */
fsp_err_t err = R_SDEMMC_W_Open(&g_sdmmc0_ctrl, &g_sdmmc0_cfg);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
/* A device shall be ready to accept the first command within 1ms from detecting VDD min. Reference section 6.4.1.1
* "Power Up Time of Card" in the SD Physical Layer Simplified Specification Version 6.00. */
/* Initialize the SD card. This should not be done until the card is plugged in for SD devices. */
err = R_SDEMMC_W_MediaInit(&g_sdmmc0_ctrl, &g_device0);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
err = R_SDEMMC_W_CallbackSet(&g_sdmmc0_ctrl, r_sdemmc_example_callback, NULL, NULL);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
/* Store SDIO status. */
g_sdio_uut0 = (SDMMC_CARD_TYPE_SDIO == g_device0.card_type);
if(!g_sdio_uut0)
{
err = R_SDEMMC_W_Write(&g_sdmmc0_ctrl, g_src, 3, 1);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
{
uint32_t timeout = 0x1000000;
err = R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
while ((status.transfer_in_progress) && (timeout > 0U))
{
/* Wait for a data line free. */
R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
timeout--;
}
}
err = R_SDEMMC_W_Read(&g_sdmmc0_ctrl, g_dest, 3, 1);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
{
uint32_t timeout = 0x1000000;
err = R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
while ((status.transfer_in_progress) && (timeout > 0U))
{
/* Wait for a data line free. */
R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
timeout--;
}
}
}
uint32_t timeout = 0x1000000;
err = R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
while ((status.transfer_in_progress) && (timeout > 0U))
{
/* Wait for a data line free. */
R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
timeout--;
}
err = R_SDEMMC_W_Close(&g_sdmmc0_ctrl);
return err;
}

Card Detection Example

This is an example of using SDEMMC_W when the card may not be plugged in. The card detection interrupt must be enabled to use this example.

bool g_card_inserted = false;
/* The callback is called when a card detection event occurs if the card detection interrupt is enabled. */
static void r_sdemmc_card_detect_example_callback (sdmmc_callback_args_t * p_args)
{
{
g_card_inserted = true;
}
{
g_card_inserted = false;
}
}
fsp_err_t r_sdemmc_card_detect_example (void)
{
/* Open the SDEMMC_W driver. This enables the card detection interrupt. */
fsp_err_t err = R_SDEMMC_W_Open(&g_sdmmc0_ctrl, &g_sdmmc0_cfg);
/* Handle any errors. This function should be defined by the user. */
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
/* A device shall be ready to accept the first command within 1ms from detecting VDD min. Reference section 6.4.1.1
* "Power Up Time of Card" in the SD Physical Layer Simplified Specification Version 6.00. */
/* Initialize the SD card after card insertion is detected. */
err = R_SDEMMC_W_MediaInit(&g_sdmmc0_ctrl, &g_device0);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
err = R_SDEMMC_W_CallbackSet(&g_sdmmc0_ctrl, r_sdemmc_card_detect_example_callback, NULL, NULL);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
/* Check if card is inserted. */
err = R_SDEMMC_W_StatusGet(&g_sdmmc0_ctrl, &status);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
if (!status.card_inserted)
{
while (!g_card_inserted)
{
/* Wait for a card insertion interrupt. */
}
}
err = R_SDEMMC_W_Close(&g_sdmmc0_ctrl);
return err;
}

Data Structures

union  sdemmc_w_event_t
 
struct  sdio_device_dma_config
 
struct  sdemmc_w_extended_cfg_t
 
struct  sdemmc_w_transfer_result_t
 
struct  sdemmc_w_instance_ctrl_t
 

Enumerations

enum  sdemmc_w_transfer_dir_t
 
enum  sdemmc_w_priv_event_t
 
enum  sdemmc_w_sdio_device_drive_current_t
 
enum  sdemmc_w_role_t
 

Data Structure Documentation

◆ sdemmc_w_event_t

union sdemmc_w_event_t

Private structure used in sdemmc_w_instance_ctrl_t.

◆ sdio_device_dma_config

struct sdio_device_dma_config

SDIO DMA configuration

Data Fields
uint32_t sdio_dma_length DMA length.
uint32_t sdio_dma_buf_address DMA buffer address.

◆ sdemmc_w_extended_cfg_t

struct sdemmc_w_extended_cfg_t

Extended SDMMC interface configuration

Data Fields
sdio_device_dma_config dma_config_tx ADMA Region physical memory.
sdio_device_dma_config dma_config_rx ADMA Region physical memory.
uint32_t sdemmc_w_role SD/eMMC/SDIO host or SDIO device.
uint8_t clk_div Clock divider value.
uint8_t host_port_sel SD/eMMC/SDIO host port selection. 0: P0_[13:4], 1: P1_[3:0] and P1_[15:10].
uint8_t host_rxclk_in_sel SD/eMMC/SDIO host rxclk_in selection. 0: clkout signal, 1: clkout_inv signal.
uint8_t host_pull_en_cfg SD/eMMC/SDIO host PADs mode pull enable.
uint8_t host_pull_sel_cfg SD/eMMC/SDIO host PADs mode pull selection.
uint8_t device_port_sel SDIO device port selection. 0: Port P0_[13:8], 1: Port P1_[15:10].
uint8_t device_pull_en_cfg SDIO device PADs mode pull enable.
uint8_t device_pull_sel_cfg SDIO device PADs mode pull selection.
sdemmc_w_sdio_device_drive_current_t drive_current Drive current.

◆ sdemmc_w_transfer_result_t

struct sdemmc_w_transfer_result_t

SDMMC extended callback arguments structure

Data Fields
uint32_t sdio_blk_or_byte This bit indicates current transaction is Block(1)/Byte(0)
uint32_t sdio_blk_size The block size programmed by the SD host.
uint32_t sdio_blk_count The block count transferred from/to the SD host.

◆ sdemmc_w_instance_ctrl_t

struct sdemmc_w_instance_ctrl_t

SDMMC instance control block. This is private to the FSP and should not be used or modified by the application.

Data Fields

uint32_t open
 Indicates whether the open() API has been successfully called.
 
sdmmc_cfg_t const * p_cfg
 Pointer to instance configuration.
 
sdmmc_device_t device
 Information of the media device used.
 
bool sector_addressing
 Whether or not use sector addressing in transfer.
 
bool transfer_in_progress
 Whether or not transfer is in progress.
 
bool initialized
 Whether or not driver is initialized.
 
SDIO_Type * p_reg
 Base SDIO register for this channel.
 
SDEMMC_Type * p_reg_mmc
 Base SD/eMMC register for this channel.
 
volatile sdemmc_w_event_t sdemmc_w_event
 Events of SDEMMC_W.
 
sdemmc_w_transfer_result_t result
 Extended callback arguments.
 
void(* p_callback )(sdmmc_callback_args_t *)
 Pointer to callback.
 
sdmmc_callback_args_tp_callback_memory
 Pointer to optional callback argument memory.
 
void * p_context
 Pointer to context to be passed into callback function.
 

Enumeration Type Documentation

◆ sdemmc_w_transfer_dir_t

Private enumeration used in sdemmc_w_instance_ctrl_t.

Enumerator
SDEMMC_W_TRANSFER_DIR_NONE 

The transfer direction is none.

SDEMMC_W_TRANSFER_DIR_READ 

The transfer direction is read.

SDEMMC_W_TRANSFER_DIR_WRITE 

The transfer direction is write.

◆ sdemmc_w_priv_event_t

Private enumeration used in sdmmc_callback_args_t.

Enumerator
SDEMMC_W_PRIV_EVENT_CARD_REMOVED 

Card removed event.

SDEMMC_W_PRIV_EVENT_CARD_INSERTED 

Card inserted event.

SDEMMC_W_PRIV_EVENT_RESPONSE 

Response event.

SDEMMC_W_PRIV_EVENT_SDIO 

IO event.

SDEMMC_W_PRIV_EVENT_TRANSFER_COMPLETE 

Read or write complete.

SDEMMC_W_PRIV_EVENT_TRANSFER_ERROR 

Read or write failed.

SDEMMC_W_PRIV_EVENT_ERASE_COMPLETE 

Erase completed.

SDEMMC_W_PRIV_EVENT_ERASE_BUSY 

Erase timeout, poll sdmmc_api_t::statusGet.

SDEMMC_W_PRIV_EVENT_SDIO_FN1_WR_OVR 

IO event.

SDEMMC_W_PRIV_EVENT_SDIO_FN1_RD_OVR 

IO event.

SDEMMC_W_PRIV_EVENT_SDIO_FN1_MSG_RDY 

IO event.

SDEMMC_W_PRIV_EVENT_SDIO_FN1_ACK_TO_ARM 

IO event.

◆ sdemmc_w_sdio_device_drive_current_t

SDIO pads drive current

Enumerator
SDEMMC_W_SDIO_DEVICE_DRIVE_CURRENT_2 

2 mA @3.3V

SDEMMC_W_SDIO_DEVICE_DRIVE_CURRENT_4 

4 mA @3.3V

SDEMMC_W_SDIO_DEVICE_DRIVE_CURRENT_8 

8 mA @3.3V

SDEMMC_W_SDIO_DEVICE_DRIVE_CURRENT_14 

14 mA @3.3V

◆ sdemmc_w_role_t

SDIO role used in sdmmc_cfg_t p_extend.

Enumerator
SDEMMC_W_ROLE_HOST 

Act as SD/eMMC/SDIO host.

SDEMMC_W_ROLE_DEVICE 

Act as SDIO device.

Function Documentation

◆ R_SDEMMC_W_Open()

fsp_err_t R_SDEMMC_W_Open ( sdmmc_ctrl_t *const  p_api_ctrl,
sdmmc_cfg_t const *const  p_cfg 
)

Opens the driver. Resets SDEMMC_W, and enables card detection interrupts if card detection is enabled. R_SDEMMC_W_MediaInit must be called after this function before any other functions can be used.

Implements sdmmc_api_t::open().

Example:

/* Open the SDEMMC_W driver. */
fsp_err_t err = R_SDEMMC_W_Open(&g_sdmmc0_ctrl, &g_sdmmc0_cfg);
Return values
FSP_SUCCESSModule is now open.
FSP_ERR_ASSERTIONNull 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_OPENDriver has already been opened with this instance of the control structure.
FSP_ERR_IRQ_BSP_DISABLEDAccess interrupt is not enabled.
FSP_ERR_IP_CHANNEL_NOT_PRESENTRequested channel does not exist on this MCU.

◆ R_SDEMMC_W_MediaInit()

fsp_err_t R_SDEMMC_W_MediaInit ( sdmmc_ctrl_t *const  p_api_ctrl,
sdmmc_device_t *const  p_device 
)

Initializes the SDEMMC_W hardware and completes identification and configuration for the SD or eMMC or SDIO device. This procedure requires several sequential commands. This function blocks until all identification and configuration commands are complete.

Implements sdmmc_api_t::mediaInit().

Example:

/* A device shall be ready to accept the first command within 1ms from detecting VDD min. Reference section 6.4.1.1
* "Power Up Time of Card" in the SD Physical Layer Simplified Specification Version 6.00. */
/* Initialize the SD card. This should not be done until the card is plugged in for SD devices. */
err = R_SDEMMC_W_MediaInit(&g_sdmmc0_ctrl, &g_device0);
Return values
FSP_SUCCESSModule is now ready for read/write access.
FSP_ERR_ASSERTIONNull 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_OPENDriver has not been initialized.
FSP_ERR_TIMEOUTDevice did not respond.
FSP_ERR_INVALID_DATAUnrecognized structure version.
FSP_ERR_UNSUPPORTEDUnsupported device.
FSP_ERR_INVALID_STATESending command retry failure.
FSP_ERR_OUT_OF_MEMORYThere is no more memory available.
FSP_ERR_NOT_FOUNDCard not exist.

◆ R_SDEMMC_W_Read()

fsp_err_t R_SDEMMC_W_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:

err = R_SDEMMC_W_Read(&g_sdmmc0_ctrl, g_dest, 3, 1);
Return values
FSP_SUCCESSData read successfully.
FSP_ERR_ASSERTIONNULL pointer.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_DEVICE_BUSYDriver is busy with a previous operation.
FSP_ERR_UNSUPPORTEDSD and eMMC support disabled in SDEMMC_W_CFG_SD_SUPPORT_ENABLE and SDEMMC_W_CFG_EMMC_SUPPORT_ENABLE.
FSP_ERR_TIMEOUTDevice did not respond.

◆ R_SDEMMC_W_Write()

fsp_err_t R_SDEMMC_W_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:

err = R_SDEMMC_W_Write(&g_sdmmc0_ctrl, g_src, 3, 1);
Return values
FSP_SUCCESSCard write finished successfully.
FSP_ERR_ASSERTIONHandle or Source address is NULL.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_DEVICE_BUSYDriver is busy with a previous operation.
FSP_ERR_CARD_WRITE_PROTECTEDSD card is Write Protected.
FSP_ERR_WRITE_FAILEDWrite operation failed.
FSP_ERR_UNSUPPORTEDSD and eMMC support disabled in SDEMMC_W_CFG_SD_SUPPORT_ENABLE and SDEMMC_W_CFG_EMMC_SUPPORT_ENABLE.
FSP_ERR_TIMEOUTDevice did not respond.

◆ R_SDEMMC_W_ReadIo()

fsp_err_t R_SDEMMC_W_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.

Return values
FSP_SUCCESSData read successfully.
FSP_ERR_ASSERTIONNULL pointer.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_UNSUPPORTEDSDIO support disabled in SDEMMC_W_CFG_SDIO_SUPPORT_ENABLE.
FSP_ERR_TIMEOUTDevice did not respond.
FSP_ERR_DEVICE_BUSYDevice is holding DAT0 low (device is busy) or another operation is ongoing.

◆ R_SDEMMC_W_WriteIo()

fsp_err_t R_SDEMMC_W_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.

Return values
FSP_SUCCESSCard write finished successfully.
FSP_ERR_ASSERTIONHandle or Source address is NULL.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_WRITE_FAILEDWrite operation failed.
FSP_ERR_UNSUPPORTEDSDIO support disabled in SDEMMC_W_CFG_SDIO_SUPPORT_ENABLE.
FSP_ERR_TIMEOUTDevice did not respond.
FSP_ERR_DEVICE_BUSYDevice is holding DAT0 low (device is busy) or another operation is ongoing.
FSP_ERR_UNSUPPORTEDSDIO support disabled in SDEMMC_W_CFG_SDIO_SUPPORT_ENABLE.

◆ R_SDEMMC_W_ReadIoExt()

fsp_err_t R_SDEMMC_W_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.

Return values
FSP_SUCCESSData read successfully.
FSP_ERR_ASSERTIONNULL pointer, or count is not in the valid range of 1-512 for byte mode or 1-511 for block mode.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_DEVICE_BUSYDriver is busy with a previous operation.
FSP_ERR_INVALID_ARGUMENTParameter passed into function was invalid.
FSP_ERR_TIMEOUTDevice did not respond.
FSP_ERR_UNSUPPORTEDSDIO support disabled in SDEMMC_W_CFG_SDIO_SUPPORT_ENABLE.

◆ R_SDEMMC_W_WriteIoExt()

fsp_err_t R_SDEMMC_W_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.

Return values
FSP_SUCCESSCard write finished successfully.
FSP_ERR_ASSERTIONNULL pointer, or count is not in the valid range of 1-512 for byte mode or 1-511 for block mode.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_DEVICE_BUSYDriver is busy with a previous operation.
FSP_ERR_INVALID_ARGUMENTParameter passed into function was invalid.
FSP_ERR_TIMEOUTDevice did not respond.
FSP_ERR_UNSUPPORTEDSDIO support disabled in SDEMMC_W_CFG_SDIO_SUPPORT_ENABLE.

◆ R_SDEMMC_W_IoIntEnable()

fsp_err_t R_SDEMMC_W_IoIntEnable ( sdmmc_ctrl_t *const  p_api_ctrl,
bool  enable 
)

Enables or disables the SDIO Interrupt. Implements sdmmc_api_t::ioIntEnable().

Return values
FSP_SUCCESSCard enabled or disabled SDIO interrupts successfully.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_ASSERTIONNULL pointer.
FSP_ERR_DEVICE_BUSYDriver is busy with a previous operation.
FSP_ERR_UNSUPPORTEDSDIO support disabled in SDEMMC_W_CFG_SDIO_SUPPORT_ENABLE.

◆ R_SDEMMC_W_StatusGet()

fsp_err_t R_SDEMMC_W_StatusGet ( sdmmc_ctrl_t *const  p_api_ctrl,
sdmmc_status_t *const  p_status 
)

Provides driver status. Implements sdmmc_api_t::statusGet().

Return values
FSP_SUCCESSStatus stored in p_status.
FSP_ERR_ASSERTIONNULL pointer.
FSP_ERR_NOT_OPENDriver has not been initialized.

◆ R_SDEMMC_W_Erase()

fsp_err_t R_SDEMMC_W_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().

Poll the status to determine when erase is complete.

Return values
FSP_SUCCESSErase operation requested.
FSP_ERR_ASSERTIONA required pointer is NULL or an argument is invalid.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_CARD_NOT_INITIALIZEDCard was unplugged.
FSP_ERR_CARD_WRITE_PROTECTEDSD card is Write Protected.
FSP_ERR_RESPONSEDevice responded with an error.
FSP_ERR_TIMEOUTDevice did not respond.
FSP_ERR_UNSUPPORTEDSD and eMMC support disabled in SDEMMC_W_CFG_SD_SUPPORT_ENABLE and SDEMMC_W_CFG_EMMC_SUPPORT_ENABLE.
FSP_ERR_DEVICE_BUSYDevice is holding DAT0 low (device is busy) or another operation is ongoing.

◆ R_SDEMMC_W_CallbackSet()

fsp_err_t R_SDEMMC_W_CallbackSet ( sdmmc_ctrl_t *const  p_api_ctrl,
void(*)(sdmmc_callback_args_t *)  p_callback,
void *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.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.

◆ R_SDEMMC_W_ResultGet()

fsp_err_t R_SDEMMC_W_ResultGet ( sdmmc_ctrl_t *const  p_api_ctrl,
sdemmc_w_transfer_result_t p_result 
)

Get the SDEMMC transfer result.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
Note
This function should only be called from an ISR or within a critical section to ensure the result reflects the current transfer and not a subsequent one.

◆ R_SDEMMC_W_Close()

fsp_err_t R_SDEMMC_W_Close ( sdmmc_ctrl_t *const  p_api_ctrl)

Closes an open SD/MMC device. Implements sdmmc_api_t::close().

Return values
FSP_SUCCESSSuccessful close.
FSP_ERR_ASSERTIONThe parameter p_ctrl is NULL.
FSP_ERR_NOT_OPENDriver has not been initialized.
FSP_ERR_TIMEOUTDevice did not respond.