High level interface to the Secure Digital Input Output (SDIO).
The SDIO protocol is an extension of the SD interface for general I/O functions. Refer to the SD Specifications Part 1 SDIO Specifications Version 4.10 for more information on the SDIO protocol and specifications.
The host functionality of this driver allows commands to be sent over the SDIO bus; the supported commands can be found in mtb_hal_sdio_host_command_t. Bulk data transfer is supported via mtb_hal_sdio_bulk_transfer().
The device functionality of this driver allows configuring the SDIO device for receiving commands from the host. Data can be sent and received from/to application buffers.
Features
- Supports 4-bit interface
- Supports Ultra High Speed (UHS-I) mode
- Supports Default Speed (DS), High Speed (HS), SDR12, SDR25 and SDR50 speed modes
- Supports SDIO card interrupts in both 1-bit SD and 4-bit SD modes
- Supports Standard capacity (SDSC), High capacity (SDHC) and Extended capacity (SDXC) memory
Quick Start
Initialize SDIO by using the Device Configurator and selecting pins according to the target device used. Specify the SDIO configuration using the configuration structure (const mtb_hal_sdio_configurator_t * config).
Code Snippets
Host Code Snippets
Snippet1: Simple SDIO Host Initialization example
The following snippet shows how to initialize the SDIO host interface with a pre-defined configuration
#define BLOCK_SIZE (512)
#define SDIO_FREQ_HF (100000000UL)
{
.frequencyhal_hz = SDIO_FREQ_HF,
.is_sdio_dev = false
};
Cy_SD_Host_Init(SDIO_sdio_hal_config.base, SDIO_sdio_hal_config.host_config, &sdio_context);
NVIC_EnableIRQ(SDIO_IRQ);
uint16_t block_size
Block size (max block size for device mode)
Definition: mtb_hal_sdio.h:266
cy_rslt_t mtb_hal_sdio_configure(mtb_hal_sdio_t *obj, const mtb_hal_sdio_cfg_t *config)
Configure the SDIO block.
Definition: mtb_hal_sdhc.c:2105
cy_rslt_t mtb_hal_sdio_setup(mtb_hal_sdio_t *obj, const mtb_hal_sdio_configurator_t *config, const mtb_hal_clock_t *clock, cy_stc_sd_host_context_t *sdio_context)
Sets up a HAL instance to use the specified hardware resource.
Definition: mtb_hal_sdhc.c:2041
SDIO initial configuration struct.
Definition: mtb_hal_sdio.h:263
uint32_t cy_rslt_t
Provides the result of an operation as a structured bitfield.
Definition: cy_result.h:459
Context structure.
Definition: cy_sd_host.h:1399
@ CY_SD_HOST_BUS_WIDTH_4_BIT
The 4-bit mode data transfer width.
Definition: cy_sd_host.h:1189
cy_en_sd_host_status_t Cy_SD_Host_Init(SDHC_Type *base, const cy_stc_sd_host_init_config_t *config, cy_stc_sd_host_context_t *context)
Initializes the SD host module.
Definition: cy_sd_host.c:2950
void Cy_SD_Host_Enable(SDHC_Type *base)
Enables the SD host block.
Definition: cy_sd_host.c:4275
cy_en_sd_host_status_t Cy_SD_Host_SetHostBusWidth(SDHC_Type *base, cy_en_sd_host_bus_width_t width)
Only changes the bus width on the host side.
Definition: cy_sd_host.c:4418
IRQn_Type intrSrc
Interrupt source.
Definition: cy_sysint.h:227
Initialization configuration structure for a single interrupt channel.
Definition: cy_sysint.h:225
cy_en_sysint_status_t Cy_SysInt_Init(const cy_stc_sysint_t *config, cy_israddress userIsr)
Initializes the referenced interrupt by setting the priority and the interrupt vector.
Definition: cy_sysint_v2.c:80
SDIO object.
Definition: mtb_hal_hw_types_sdio_mxsdhc.h:58
Snippet2: Configure Host Interrupt
The following snippet shows how to configure an interrupt to handle host specific events. Refer mtb_hal_sdio_event_t for different types of events.
{
CY_UNUSED_PARAMETER(handler_arg);
CY_UNUSED_PARAMETER(event);
switch (event)
{
{
break;
}
{
break;
}
{
break;
}
default:
{
break;
}
}
}
void snippet_mtb_hal_host_sdio_interrupt_init()
{
}
void mtb_hal_sdio_register_callback(mtb_hal_sdio_t *obj, mtb_hal_sdio_event_callback_t callback, void *callback_arg)
Register an SDIO event callback handler.
Definition: mtb_hal_sdhc.c:2272
void mtb_hal_sdio_enable_event(mtb_hal_sdio_t *obj, mtb_hal_sdio_event_t event, bool enable)
Configure the callback event.
Definition: mtb_hal_sdhc.c:2285
mtb_hal_sdio_event_t
Types of events that could be asserted by SDIO.
Definition: mtb_hal_sdio.h:176
@ MTB_HAL_SDIO_CMD_COMPLETE
Command Complete.
Definition: mtb_hal_sdio.h:179
@ MTB_HAL_SDIO_CARD_INSERTION
Set if the Card Inserted in the Present State.
Definition: mtb_hal_sdio.h:186
@ MTB_HAL_SDIO_ALL_INTERRUPTS
Used to enable/disable all interrupts events.
Definition: mtb_hal_sdio.h:207
@ MTB_HAL_SDIO_XFER_COMPLETE
Host read/write transfer is complete.
Definition: mtb_hal_sdio.h:180
Snippet3: Sending Host Commands
The following snippet shows how to send a particular command. Some steps of the card initialization have been provided for reference. Refer to mtb_hal_sdio_host_command_t for different commands.
uint32_t response;
bool f8Flag = false;
#define MY_SDIO_CMD_NO_ARG (0u)
#define MY_SDIO_CMD8 ((mtb_hal_sdio_host_command_t)8u)
#define MY_SDIO_CMD8_VHS_27_36 (0x100UL)
#define MY_SDIO_CMD8_PATTERN_MASK (0xFFUL)
#define MY_SDIO_CMD8_CHECK_PATTERN (0xAAUL)
MY_SDIO_CMD_NO_ARG, &response);
MY_SDIO_CMD8_CHECK_PATTERN,
&response);
if (MY_SDIO_CMD8_CHECK_PATTERN == (response & MY_SDIO_CMD8_PATTERN_MASK))
{
f8Flag = true;
}
else
{
}
if (f8Flag)
{
}
cy_rslt_t mtb_hal_sdio_host_send_cmd(mtb_hal_sdio_t *obj, mtb_hal_sdio_host_transfer_type_t direction, mtb_hal_sdio_host_command_t command, uint32_t argument, uint32_t *response)
Send command to the SDIO device.
Definition: mtb_hal_sdhc.c:2144
@ MTB_HAL_SDIO_CMD_GO_IDLE_STATE
Go to idle state.
Definition: mtb_hal_sdio.h:220
@ MTB_HAL_SDIO_XFER_TYPE_WRITE
Write to the card.
Definition: mtb_hal_sdio.h:234
Snippet4: Host Bulk Data Transfer
The following snippet shows how to start a bulk data transfer.
#define DATA_LENGTH (5u)
#define MY_SDIO_CMD_NO_ARG (0u)
uint32_t data[DATA_LENGTH] = { '1', '2', '3', '4', '5' };
uint32_t response;
MY_SDIO_CMD_NO_ARG,
data,
DATA_LENGTH,
&response);
cy_rslt_t mtb_hal_sdio_host_bulk_transfer(mtb_hal_sdio_t *obj, mtb_hal_sdio_host_transfer_type_t direction, uint32_t argument, const uint32_t *data, uint16_t length, uint32_t *response)
Perform a bulk data transfer.
Definition: mtb_hal_sdhc.c:2222
Device Code Snippets
Snippet1: Simple SDIO Device Initialization example
The following snippet shows how to initialize the SDIO device interface with a pre-defined configuration
#define BLOCK_SIZE (512)
#define SDIO_FREQ (50000000UL)
{
.frequenmtb_hal_hz = SDIO_FREQ,
.is_sdio_dev = true
};
rslt = mtb_hal_sdio_init(&sdio_object,
SDIO_CMD_PIN,
SDIO_CLK_PIN,
SDIO_DATA0_PIN,
SDIO_DATA1_PIN,
SDIO_DATA2_PIN,
SDIO_DATA3_PIN);
Snippet2: Configure Device Interrupt
The following snippet shows how to configure an interrupt to handle device specific events. Refer mtb_hal_sdio_event_t for different types of events.
{
CY_UNUSED_PARAMETER(handler_arg);
CY_UNUSED_PARAMETER(event);
switch (event)
{
case MTB_HAL_SDIO_DEV_HOST_INFO:
{
break;
}
case MTB_HAL_SDIO_DEV_READ_COMPLETE:
{
break;
}
case MTB_HAL_SDIO_DEV_READ_ERROR:
{
break;
}
default:
{
break;
}
}
}
void snippet_mtb_hal_dev_sdio_interrupt_init()
{
#define INTERRUPT_PRIORITY (3u)
}
Snippet3: Device Async Read
The following snippet shows how to start an async read.
{
if ((handler_arg != NULL) && (event == MTB_HAL_SDIO_DEV_READ_COMPLETE))
{
}
}
void snippet_mtb_hal_sdio_dev_async_read()
{
#define DATA_LENGTH (5u)
#define INTERRUPT_PRIORITY (3u)
uint8_t data[DATA_LENGTH] = { '1', '2', '3', '4', '5' };
uint32_t handler_args = 0;
(void*)&handler_args);
MTB_HAL_SDIO_DEV_READ_ERROR),
INTERRUPT_PRIORITY,
true);
mtb_hal_sdio_dev_read_async(&sdio_obj, &data[0], DATA_LENGTH);
while (mtb_hal_sdio_is_busy(&sdio_obj))
{
}
}
Snippet4: Device Mailbox Write
The following snippet shows how to write to the mailbox.
void snippet_mtb_hal_sdio_dev_write_mailbox()
{
#define HOST_MAILBOX_BITS (0x5u)
#define HOST_MAILBOX_DATA (0x3u)
uint32_t data = HOST_MAILBOX_DATA;
cy_rslt_t status = mtb_hal_sdio_dev_mailbox_write(&sdio_obj, HOST_MAILBOX_BITS, &data);
{
}
}
#define CY_RSLT_SUCCESS
cy_rslt_t return value indicating success
Definition: cy_result.h:486
|
|
typedef void(* | mtb_hal_sdio_event_callback_t) (void *callback_arg, mtb_hal_sdio_event_t event) |
| | Callback for SDIO events.
|
| |
|
| enum | mtb_hal_sdio_event_t {
MTB_HAL_SDIO_CMD_COMPLETE = 0x00001
,
MTB_HAL_SDIO_XFER_COMPLETE = 0x00002
,
MTB_HAL_SDIO_BGAP_EVENT = 0x00004
,
MTB_HAL_SDIO_DMA_INTERRUPT = 0x00008
,
MTB_HAL_SDIO_BUF_WR_READY = 0x00010
,
MTB_HAL_SDIO_BUF_RD_READY = 0x00020
,
MTB_HAL_SDIO_CARD_INSERTION = 0x00040
,
MTB_HAL_SDIO_CARD_REMOVAL = 0x00080
,
MTB_HAL_SDIO_CARD_INTERRUPT = 0x00100
,
MTB_HAL_SDIO_INT_A = 0x00200
,
MTB_HAL_SDIO_INT_B = 0x00400
,
MTB_HAL_SDIO_INT_C = 0x00800
,
MTB_HAL_SDIO_RE_TUNE_EVENT = 0x01000
,
MTB_HAL_SDIO_FX_EVENT = 0x02000
,
MTB_HAL_SDIO_CQE_EVENT = 0x04000
,
MTB_HAL_SDIO_ERR_INTERRUPT = 0x08000
,
MTB_HAL_SDIO_ALL_INTERRUPTS = 0x0E1FF
} |
| | Types of events that could be asserted by SDIO. More...
|
| |
| enum | mtb_hal_sdio_host_command_t {
MTB_HAL_SDIO_CMD_GO_IDLE_STATE = 0
,
MTB_HAL_SDIO_CMD_SEND_RELATIVE_ADDR = 3
,
MTB_HAL_SDIO_CMD_IO_SEND_OP_COND = 5
,
MTB_HAL_SDIO_CMD_SELECT_CARD = 7
,
MTB_HAL_SDIO_CMD_VOLTAGE_SWITCH = 11
,
MTB_HAL_SDIO_CMD_GO_INACTIVE_STATE = 15
,
MTB_HAL_SDIO_CMD_IO_RW_DIRECT = 52
,
MTB_HAL_SDIO_CMD_IO_RW_EXTENDED = 53
} |
| | Commands that can be issued. More...
|
| |
| enum | mtb_hal_sdio_host_transfer_type_t {
MTB_HAL_SDIO_XFER_TYPE_READ
,
MTB_HAL_SDIO_XFER_TYPE_WRITE
} |
| | Types of transfer that can be performed. More...
|
| |
| enum | mtb_hal_sdio_host_io_voltage_t {
MTB_HAL_SDIO_IO_VOLTAGE_3_3V = 0U
,
MTB_HAL_SDIO_IO_VOLTAGE_1_8V = 1U
} |
| | I/O voltage levels. More...
|
| |
| enum | mtb_hal_sdio_host_io_volt_action_type_t {
MTB_HAL_SDIO_IO_VOLT_ACTION_SWITCH_SEQ_ONLY = 1U
,
MTB_HAL_SDIO_IO_VOLT_ACTION_NONE = 2U
} |
| | SDIO I/O voltage select principle. More...
|
| |
|
| cy_rslt_t | mtb_hal_sdio_setup (mtb_hal_sdio_t *obj, const mtb_hal_sdio_configurator_t *config, const mtb_hal_clock_t *clock, cy_stc_sd_host_context_t *sdio_context) |
| | Sets up a HAL instance to use the specified hardware resource. More...
|
| |
| cy_rslt_t | mtb_hal_sdio_configure (mtb_hal_sdio_t *obj, const mtb_hal_sdio_cfg_t *config) |
| | Configure the SDIO block. More...
|
| |
| void | mtb_hal_sdio_register_callback (mtb_hal_sdio_t *obj, mtb_hal_sdio_event_callback_t callback, void *callback_arg) |
| | Register an SDIO event callback handler. More...
|
| |
| void | mtb_hal_sdio_enable_event (mtb_hal_sdio_t *obj, mtb_hal_sdio_event_t event, bool enable) |
| | Configure the callback event. More...
|
| |
| cy_rslt_t | mtb_hal_sdio_process_interrupt (mtb_hal_sdio_t *obj) |
| | Process interrupts related related to an SDIO instance. More...
|
| |
| cy_rslt_t | mtb_hal_sdio_host_send_cmd (mtb_hal_sdio_t *obj, mtb_hal_sdio_host_transfer_type_t direction, mtb_hal_sdio_host_command_t command, uint32_t argument, uint32_t *response) |
| | Send command to the SDIO device. More...
|
| |
| cy_rslt_t | mtb_hal_sdio_host_bulk_transfer (mtb_hal_sdio_t *obj, mtb_hal_sdio_host_transfer_type_t direction, uint32_t argument, const uint32_t *data, uint16_t length, uint32_t *response) |
| | Perform a bulk data transfer. More...
|
| |
| cy_rslt_t | mtb_hal_sdio_host_set_io_voltage (mtb_hal_sdio_t *obj, mtb_hal_sdio_host_io_voltage_t io_voltage, mtb_hal_sdio_host_io_volt_action_type_t io_switch_type) |
| | Set the voltage level of the I/O line. More...
|
| |
◆ mtb_hal_sdio_cfg_t
| struct mtb_hal_sdio_cfg_t |
| Data Fields |
|
uint32_t |
frequencyhal_hz |
Clock frequency in hertz (target SDIO frequency for device mode) |
|
uint16_t |
block_size |
Block size (max block size for device mode) |
|
bool |
is_sdio_dev |
0 if SDIO host, 1 if SDIO device |
◆ mtb_hal_sdio_event_t
Types of events that could be asserted by SDIO.
| Enumerator |
|---|
| MTB_HAL_SDIO_CMD_COMPLETE | Command Complete.
|
| MTB_HAL_SDIO_XFER_COMPLETE | Host read/write transfer is complete.
|
| MTB_HAL_SDIO_BGAP_EVENT | Set when both read/write transaction is stopped.
|
| MTB_HAL_SDIO_DMA_INTERRUPT | Host controller detects an SDMA Buffer Boundary during transfer.
|
| MTB_HAL_SDIO_BUF_WR_READY | Set if the Buffer Write Enable changes from 0 to 1.
|
| MTB_HAL_SDIO_BUF_RD_READY | Set if the Buffer Read Enable changes from 0 to 1.
|
| MTB_HAL_SDIO_CARD_INSERTION | Set if the Card Inserted in the Present State.
|
| MTB_HAL_SDIO_CARD_REMOVAL | Set if the Card Inserted in the Present State.
|
| MTB_HAL_SDIO_CARD_INTERRUPT | Synchronized value of the DAT[1] interrupt input for SD mode.
|
| MTB_HAL_SDIO_INT_A | Reserved: set to 0.
|
| MTB_HAL_SDIO_INT_B | Reserved: set to 0.
|
| MTB_HAL_SDIO_INT_C | Reserved: set to 0.
|
| MTB_HAL_SDIO_RE_TUNE_EVENT | Reserved: set to 0.
|
| MTB_HAL_SDIO_FX_EVENT | Set when R[14] of response register is set to 1.
|
| MTB_HAL_SDIO_CQE_EVENT | Set if Command Queuing/Crypto event has occurred.
|
| MTB_HAL_SDIO_ERR_INTERRUPT | Set if any of the bits in the Error Interrupt Status register are set.
|
| MTB_HAL_SDIO_ALL_INTERRUPTS | Used to enable/disable all interrupts events.
|
◆ mtb_hal_sdio_host_command_t
Commands that can be issued.
| Enumerator |
|---|
| MTB_HAL_SDIO_CMD_GO_IDLE_STATE | Go to idle state.
|
| MTB_HAL_SDIO_CMD_SEND_RELATIVE_ADDR | Send a relative address.
|
| MTB_HAL_SDIO_CMD_IO_SEND_OP_COND | Send an OP IO.
|
| MTB_HAL_SDIO_CMD_SELECT_CARD | Send a card select.
|
| MTB_HAL_SDIO_CMD_VOLTAGE_SWITCH | Voltage switch.
|
| MTB_HAL_SDIO_CMD_GO_INACTIVE_STATE | Go to inactive state.
|
| MTB_HAL_SDIO_CMD_IO_RW_DIRECT | Perform a direct read/write.
|
| MTB_HAL_SDIO_CMD_IO_RW_EXTENDED | Perform an extended read/write.
|
◆ mtb_hal_sdio_host_transfer_type_t
Types of transfer that can be performed.
| Enumerator |
|---|
| MTB_HAL_SDIO_XFER_TYPE_READ | Read from the card.
|
| MTB_HAL_SDIO_XFER_TYPE_WRITE | Write to the card.
|
◆ mtb_hal_sdio_host_io_voltage_t
I/O voltage levels.
| Enumerator |
|---|
| MTB_HAL_SDIO_IO_VOLTAGE_3_3V | I/O voltage is 3.3V.
|
| MTB_HAL_SDIO_IO_VOLTAGE_1_8V | I/O voltage is 1.8V.
|
◆ mtb_hal_sdio_host_io_volt_action_type_t
SDIO I/O voltage select principle.
| Enumerator |
|---|
| MTB_HAL_SDIO_IO_VOLT_ACTION_SWITCH_SEQ_ONLY | HAL driver performs switching sequence (if voltage is being switched to 1.8V) and changes io_volt_sel pin level accordingly. No commands are being send to the card in this mode.
|
| MTB_HAL_SDIO_IO_VOLT_ACTION_NONE | I/O voltage is changed by changing io_volt_sel pin's level. No commands are being sent to the card in this mode.
|
◆ mtb_hal_sdio_setup()
Sets up a HAL instance to use the specified hardware resource.
This hardware resource must have already been configured via the PDL.
- Note
- It is required that after calling mtb_hal_sdio_setup a User must call Cy_SD_Host_SetHostBusWidth to set the bus width to 4 (CY_SD_HOST_BUS_WIDTH_4_BIT).
- Parameters
-
| [out] | obj | The HAL driver instance object. The caller must allocate the memory for this object, but the HAL will initialize its contents |
| [in] | config | The configurator-generated HAL config structure for this peripheral instance |
| [in] | clock | The HAL clock object that is connected to this peripheral instance |
| [in] | sdio_context | The context for the sdio instance allocated by the user |
- Returns
- the status of the HAL setup
◆ mtb_hal_sdio_configure()
Configure the SDIO block.
SDIO is either a host or a device type. This function allows specifying the features for either type. Refer to mtb_hal_sdio_cfg_t for more information.
- Parameters
-
| [in,out] | obj | The SDIO object |
| [in] | config | The SDIO configuration to apply |
- Returns
- The status of the configure request.
Returns CY_RSLT_SUCCESS on successful operation.
◆ mtb_hal_sdio_register_callback()
◆ mtb_hal_sdio_enable_event()
◆ mtb_hal_sdio_process_interrupt()
Process interrupts related related to an SDIO instance.
- Parameters
-
| obj | HAL object for which the interrupt should be processed |
- Returns
- CY_RSLT_SUCCESS if the interrupt was processed successfully; otherwise an error
◆ mtb_hal_sdio_host_send_cmd()
Send command to the SDIO device.
See mtb_hal_sdio_host_command_t for list of available commands. This will block until the command is completed.
- Parameters
-
| [in,out] | obj | The SDIO host object |
| [in] | direction | The direction of transfer (read/write) |
| [in] | command | The command to send to the SDIO device |
| [in] | argument | The argument to the command |
| [out] | response | The response from the SDIO device |
- Returns
- The status of the command transfer.
Returns CY_RSLT_SUCCESS on successful operation. Refer Snippet3: Sending Host Commands for more information.
◆ mtb_hal_sdio_host_bulk_transfer()
Perform a bulk data transfer.
Sends MTB_HAL_SDIO_CMD_IO_RW_EXTENDED command (CMD=53) which allows writing and reading of a large number of I/O registers with a single command. This will block until the transfer is completed.
If D-cache is enabled, the user needs to make sure that the data pointer passed to the mtb_hal_sdio_host_bulk_transfer function points to a buffer which is aligned to the cache line size (__SCB_DCACHE_LINE_SIZE). The length of buffer data must be a multiple of the cache line size to ensure cache coherency. CY_ALIGN(__SCB_DCACHE_LINE_SIZE) macro can be used for alignment.
Refer to DCACHE_Management for more information.
- Parameters
-
| [in,out] | obj | The SDIO host object |
| [in] | direction | The direction of transfer (read/write) |
| [in] | argument | The argument to the command |
| [in] | data | The data to send to the SDIO device. A bulk transfer is done in block size (default: 64 bytes) chunks for better performance. Therefore, the size of the data buffer passed into this function must be at least length bytes, and if 'length' is greater than the configured block size, it must also be a multiple of the block size. |
| [in] | length | The number of bytes to send. Must be less than the block size set up by the user (default: 64 bytes) OR be aligned with the block size. For example. the following lengths are legal for a block size of 64 bytes: 10, 29, 33, 64, 128, 192... |
| [out] | response | The response from the SDIO device |
- Returns
- The status of the bulk transfer operation.
Returns CY_RSLT_SUCCESS on successful operation. Refer Snippet4: Host Bulk Data Transfer for more information.
◆ mtb_hal_sdio_host_set_io_voltage()
Set the voltage level of the I/O line.
This function changes the logic level on the io_volt_sel pin. It assumes that this line is used to control a regulator connected to the VDDIO of the MCU. This regulator allows for switching between the 3.3V and 1.8V signaling. High level on the pin stands for 1.8V signaling, while low - for 3.3V.
- Parameters
-
| [in] | obj | The SDIO host object |
| [in] | io_voltage | I/O voltage to be set on lines |
| [in] | io_switch_type | Defines how I/O voltage will be switched |
- Returns
- The status of the operation