PSoC 6 Hardware Abstraction Layer (HAL)
SDIO (Secure Digital Input Output)

General Description

High level interface for interacting with the Cypress SDIO interface.

The Secure Digital Input Output (SDIO) protocol is an extension of the SD interface for general I/O functions.

This driver allows commands to be sent over the SDIO bus; the supported commands can be found in cyhal_sdio_command_t. Bulk data transfer is also supported via cyhal_sdio_bulk_transfer().

Data Structures

struct  cyhal_sdio_cfg_t
 SDIO controller initial configuration. More...
 

Macros

#define CYHAL_SDIO_RET_NO_ERRORS   (0x00)
 
#define CYHAL_SDIO_RET_NO_SP_ERRORS   (0x01)
 
#define CYHAL_SDIO_RET_CMD_CRC_ERROR   (0x02)
 
#define CYHAL_SDIO_RET_CMD_IDX_ERROR   (0x04)
 
#define CYHAL_SDIO_RET_CMD_EB_ERROR   (0x08)
 
#define CYHAL_SDIO_RET_DAT_CRC_ERROR   (0x10)
 
#define CYHAL_SDIO_RET_CMD_TIMEOUT   (0x20)
 
#define CYHAL_SDIO_RET_DAT_TIMEOUT   (0x40)
 
#define CYHAL_SDIO_RET_RESP_FLAG_ERROR   (0x80)
 
#define CYHAL_SDIO_CLOCK_ERROR   (0x100)
 
#define CYHAL_SDIO_BAD_ARGUMENT   (0x200)
 
#define CYHAL_SDIO_SEMA_NOT_INITED   (0x400)
 
#define CYHAL_SDIO_FUNC_NOT_SUPPORTED   (0x800)
 
#define CYHAL_SDIO_CANCELED   (0x1000)
 
#define CYHAL_SDIO_RSLT_ERR_BAD_PARAM
 
#define CYHAL_SDIO_RSLT_ERR_CLOCK
 
#define CYHAL_SDIO_RSLT_ERR_SEMA_NOT_INITED
 
#define CYHAL_SDIO_RSLT_ERR_FUNC_RET(retVal)
 
#define CYHAL_SDIO_RSLT_CANCELED
 

Typedefs

typedef void(* cyhal_sdio_event_callback_t) (void *callback_arg, cyhal_sdio_event_t event)
 

Enumerations

enum  cyhal_sdio_command_t {
  CYHAL_SDIO_CMD_GO_IDLE_STATE = 0, CYHAL_SDIO_CMD_SEND_RELATIVE_ADDR = 3, CYHAL_SDIO_CMD_IO_SEND_OP_COND = 5, CYHAL_SDIO_CMD_SELECT_CARD = 7,
  CYHAL_SDIO_CMD_GO_INACTIVE_STATE = 15, CYHAL_SDIO_CMD_IO_RW_DIRECT = 52, CYHAL_SDIO_CMD_IO_RW_EXTENDED = 53
}
 
enum  cyhal_transfer_t { CYHAL_READ, CYHAL_WRITE }
 
enum  cyhal_sdio_event_t {
  CYHAL_SDIO_CMD_COMPLETE = 0x00001, CYHAL_SDIO_XFER_COMPLETE = 0x00002, CYHAL_SDIO_BGAP_EVENT = 0x00004, CYHAL_SDIO_DMA_INTERRUPT = 0x00008,
  CYHAL_SDIO_BUF_WR_READY = 0x00010, CYHAL_SDIO_BUF_RD_READY = 0x00020, CYHAL_SDIO_CARD_INSERTION = 0x00040, CYHAL_SDIO_CARD_REMOVAL = 0x00080,
  CYHAL_SDIO_CARD_INTERRUPT = 0x00100, CYHAL_SDIO_INT_A = 0x00200, CYHAL_SDIO_INT_B = 0x00400, CYHAL_SDIO_INT_C = 0x00800,
  CYHAL_SDIO_RE_TUNE_EVENT = 0x01000, CYHAL_SDIO_FX_EVENT = 0x02000, CYHAL_SDIO_CQE_EVENT = 0x04000, CYHAL_SDIO_ERR_INTERRUPT = 0x08000,
  CYHAL_SDIO_GOING_DOWN = 0x10000, CYHAL_SDIO_COMING_UP = 0x20000, CYHAL_SDIO_ALL_INTERRUPTS = 0x0E1FF
}
 

Functions

cy_rslt_t cyhal_sdio_init (cyhal_sdio_t *obj, cyhal_gpio_t cmd, cyhal_gpio_t clk, cyhal_gpio_t data0, cyhal_gpio_t data1, cyhal_gpio_t data2, cyhal_gpio_t data3)
 
void cyhal_sdio_free (cyhal_sdio_t *obj)
 
cy_rslt_t cyhal_sdio_configure (cyhal_sdio_t *obj, const cyhal_sdio_cfg_t *config)
 
cy_rslt_t cyhal_sdio_send_cmd (const cyhal_sdio_t *obj, cyhal_transfer_t direction, cyhal_sdio_command_t command, uint32_t argument, uint32_t *response)
 
cy_rslt_t cyhal_sdio_bulk_transfer (cyhal_sdio_t *obj, cyhal_transfer_t direction, uint32_t argument, const uint32_t *data, uint16_t length, uint32_t *response)
 
cy_rslt_t cyhal_sdio_transfer_async (cyhal_sdio_t *obj, cyhal_transfer_t direction, uint32_t argument, const uint32_t *data, uint16_t length)
 
bool cyhal_sdio_is_busy (const cyhal_sdio_t *obj)
 
cy_rslt_t cyhal_sdio_abort_async (const cyhal_sdio_t *obj)
 
void cyhal_sdio_register_callback (cyhal_sdio_t *obj, cyhal_sdio_event_callback_t callback, void *callback_arg)
 
void cyhal_sdio_enable_event (cyhal_sdio_t *obj, cyhal_sdio_event_t event, uint8_t intrPriority, bool enable)
 

Data Structure Documentation

◆ cyhal_sdio_cfg_t

struct cyhal_sdio_cfg_t
Data Fields
uint32_t frequencyhal_hz Clock frequency, in hertz.
uint16_t block_size Block size.

Macro Definition Documentation

◆ CYHAL_SDIO_RET_NO_ERRORS

#define CYHAL_SDIO_RET_NO_ERRORS   (0x00)

No error

◆ CYHAL_SDIO_RET_NO_SP_ERRORS

#define CYHAL_SDIO_RET_NO_SP_ERRORS   (0x01)

Non-specific error code

◆ CYHAL_SDIO_RET_CMD_CRC_ERROR

#define CYHAL_SDIO_RET_CMD_CRC_ERROR   (0x02)

There was a CRC error on the Command/Response

◆ CYHAL_SDIO_RET_CMD_IDX_ERROR

#define CYHAL_SDIO_RET_CMD_IDX_ERROR   (0x04)

The index for the command didn't match

◆ CYHAL_SDIO_RET_CMD_EB_ERROR

#define CYHAL_SDIO_RET_CMD_EB_ERROR   (0x08)

There was an end bit error on the command

◆ CYHAL_SDIO_RET_DAT_CRC_ERROR

#define CYHAL_SDIO_RET_DAT_CRC_ERROR   (0x10)

There was a data CRC Error

◆ CYHAL_SDIO_RET_CMD_TIMEOUT

#define CYHAL_SDIO_RET_CMD_TIMEOUT   (0x20)

The command didn't finish before the timeout period was over

◆ CYHAL_SDIO_RET_DAT_TIMEOUT

#define CYHAL_SDIO_RET_DAT_TIMEOUT   (0x40)

The data didn't finish before the timeout period was over

◆ CYHAL_SDIO_RET_RESP_FLAG_ERROR

#define CYHAL_SDIO_RET_RESP_FLAG_ERROR   (0x80)

There was an error in the resposne flag for command 53

◆ CYHAL_SDIO_CLOCK_ERROR

#define CYHAL_SDIO_CLOCK_ERROR   (0x100)

Failed to initial clock for SDIO

◆ CYHAL_SDIO_BAD_ARGUMENT

#define CYHAL_SDIO_BAD_ARGUMENT   (0x200)

Bad argument passed for SDIO

◆ CYHAL_SDIO_SEMA_NOT_INITED

#define CYHAL_SDIO_SEMA_NOT_INITED   (0x400)

Semaphore is not initiated

◆ CYHAL_SDIO_FUNC_NOT_SUPPORTED

#define CYHAL_SDIO_FUNC_NOT_SUPPORTED   (0x800)

Function is not supported

◆ CYHAL_SDIO_CANCELED

#define CYHAL_SDIO_CANCELED   (0x1000)

Operation canceled

◆ CYHAL_SDIO_RSLT_ERR_BAD_PARAM

#define CYHAL_SDIO_RSLT_ERR_BAD_PARAM
Value:
#define CYHAL_SDIO_BAD_ARGUMENT
Definition: cyhal_sdio.h:64
Module identifier for the SDIO module.
Definition: cyhal_modules.h:59
#define CY_RSLT_TYPE_ERROR
The result code is an error.
Definition: cy_result.h:143
#define CY_RSLT_CREATE(type, module, code)
Create a new cy_rslt_t value that encodes the specified type, module, and result code.
Definition: cy_result.h:126

Incorrect parameter value define

◆ CYHAL_SDIO_RSLT_ERR_CLOCK

#define CYHAL_SDIO_RSLT_ERR_CLOCK
Value:
Module identifier for the SDIO module.
Definition: cyhal_modules.h:59
#define CY_RSLT_TYPE_ERROR
The result code is an error.
Definition: cy_result.h:143
#define CY_RSLT_CREATE(type, module, code)
Create a new cy_rslt_t value that encodes the specified type, module, and result code.
Definition: cy_result.h:126
#define CYHAL_SDIO_CLOCK_ERROR
Definition: cyhal_sdio.h:63

Clock initialization error define

◆ CYHAL_SDIO_RSLT_ERR_SEMA_NOT_INITED

#define CYHAL_SDIO_RSLT_ERR_SEMA_NOT_INITED
Value:
Module identifier for the SDIO module.
Definition: cyhal_modules.h:59
#define CY_RSLT_TYPE_ERROR
The result code is an error.
Definition: cy_result.h:143
#define CYHAL_SDIO_SEMA_NOT_INITED
Definition: cyhal_sdio.h:65
#define CY_RSLT_CREATE(type, module, code)
Create a new cy_rslt_t value that encodes the specified type, module, and result code.
Definition: cy_result.h:126

Semaphore not initiated error define

◆ CYHAL_SDIO_RSLT_ERR_FUNC_RET

#define CYHAL_SDIO_RSLT_ERR_FUNC_RET (   retVal)
Value:
Module identifier for the SDIO module.
Definition: cyhal_modules.h:59
#define CY_RSLT_TYPE_ERROR
The result code is an error.
Definition: cy_result.h:143
#define CY_RSLT_CREATE(type, module, code)
Create a new cy_rslt_t value that encodes the specified type, module, and result code.
Definition: cy_result.h:126

Error define based on SDIO lower function return value

◆ CYHAL_SDIO_RSLT_CANCELED

#define CYHAL_SDIO_RSLT_CANCELED
Value:
Module identifier for the SDIO module.
Definition: cyhal_modules.h:59
#define CY_RSLT_TYPE_ERROR
The result code is an error.
Definition: cy_result.h:143
#define CYHAL_SDIO_CANCELED
Definition: cyhal_sdio.h:67
#define CY_RSLT_CREATE(type, module, code)
Create a new cy_rslt_t value that encodes the specified type, module, and result code.
Definition: cy_result.h:126

Define to indicate canceled operation

Typedef Documentation

◆ cyhal_sdio_event_callback_t

typedef void(* cyhal_sdio_event_callback_t) (void *callback_arg, cyhal_sdio_event_t event)

Callback for SDIO events

Enumeration Type Documentation

◆ cyhal_sdio_command_t

Commands that can be issued

Enumerator
CYHAL_SDIO_CMD_SEND_RELATIVE_ADDR 

Go to idle state

CYHAL_SDIO_CMD_IO_SEND_OP_COND 

Send a relative address

CYHAL_SDIO_CMD_SELECT_CARD 

Send an OP IO

CYHAL_SDIO_CMD_GO_INACTIVE_STATE 

Send a card select

CYHAL_SDIO_CMD_IO_RW_DIRECT 

Go to inactive state

CYHAL_SDIO_CMD_IO_RW_EXTENDED 

Perform a direct read/write

◆ cyhal_transfer_t

Types of transfer that can be performed

Enumerator
CYHAL_WRITE 

Read from the card

Write to the card

◆ cyhal_sdio_event_t

Types of events that could be asserted by SDIO

Enumerator
CYHAL_SDIO_XFER_COMPLETE 

Command Complete

CYHAL_SDIO_BGAP_EVENT 

Host read/write transfer is complete

CYHAL_SDIO_DMA_INTERRUPT 

This bit is set when both read/write transaction is stopped

CYHAL_SDIO_BUF_WR_READY 

Host controller detects an SDMA Buffer Boundary during transfer

CYHAL_SDIO_BUF_RD_READY 

This bit is set if the Buffer Write Enable changes from 0 to 1

CYHAL_SDIO_CARD_INSERTION 

This bit is set if the Buffer Read Enable changes from 0 to 1

CYHAL_SDIO_CARD_REMOVAL 

This bit is set if the Card Inserted in the Present State

CYHAL_SDIO_CARD_INTERRUPT 

This bit is set if the Card Inserted in the Present State

CYHAL_SDIO_INT_A 

The synchronized value of the DAT[1] interrupt input for SD mode

CYHAL_SDIO_INT_B 

Reserved: set to 0

CYHAL_SDIO_INT_C 

Reserved: set to 0

CYHAL_SDIO_RE_TUNE_EVENT 

Reserved: set to 0

CYHAL_SDIO_FX_EVENT 

Reserved: set to 0

CYHAL_SDIO_CQE_EVENT 

This status is set when R[14] of response register is set to 1

CYHAL_SDIO_ERR_INTERRUPT 

This status is set if Command Queuing/Crypto event has occurred

CYHAL_SDIO_GOING_DOWN 

If any of the bits in the Error Interrupt Status register are set

CYHAL_SDIO_COMING_UP 

The interface is going away (eg: powering down for some period of time)

CYHAL_SDIO_ALL_INTERRUPTS 

The interface is back up (eg: came back from a low power state)

Function Documentation

◆ cyhal_sdio_init()

cy_rslt_t cyhal_sdio_init ( cyhal_sdio_t *  obj,
cyhal_gpio_t  cmd,
cyhal_gpio_t  clk,
cyhal_gpio_t  data0,
cyhal_gpio_t  data1,
cyhal_gpio_t  data2,
cyhal_gpio_t  data3 
)

Initialize the SDIO peripheral

Parameters
[out]objThe SDIO object
[out]clkThe pin connected to the clk signal
[in]cmdThe pin connected to the command signal
[in]data0The pin connected to the data0 signal
[in]data1The pin connected to the data1 signal
[in]data2The pin connected to the data2 signal
[in]data3The pin connected to the data3 signal
Returns
The status of the init request

◆ cyhal_sdio_free()

void cyhal_sdio_free ( cyhal_sdio_t *  obj)

Release the SDIO peripheral, not currently invoked. It requires further resource management.

Parameters
[in,out]objThe SDIO object

◆ cyhal_sdio_configure()

cy_rslt_t cyhal_sdio_configure ( cyhal_sdio_t *  obj,
const cyhal_sdio_cfg_t *  config 
)

Configure the SDIO block.

Parameters
[in,out]objThe SDIO object
[in]configThe SDIO configuration to apply
Returns
The status of the configure request

◆ cyhal_sdio_send_cmd()

cy_rslt_t cyhal_sdio_send_cmd ( const cyhal_sdio_t *  obj,
cyhal_transfer_t  direction,
cyhal_sdio_command_t  command,
uint32_t  argument,
uint32_t *  response 
)

Sends a command to the SDIO block.

Parameters
[in,out]objThe SDIO object
[in]directionThe direction of transfer (read/write)
[in]commandThe SDIO command to send
[in]argumentThe argument to the command
[out]responseThe response from the SDIO device
Returns
The status of the configure request

◆ cyhal_sdio_bulk_transfer()

cy_rslt_t cyhal_sdio_bulk_transfer ( cyhal_sdio_t *  obj,
cyhal_transfer_t  direction,
uint32_t  argument,
const uint32_t *  data,
uint16_t  length,
uint32_t *  response 
)

Performs a bulk data transfer (CMD=53) to the SDIO block.

Parameters
[in,out]objThe SDIO object
[in]directionThe direction of transfer (read/write)
[in]argumentThe argument to the command
[in]dataThe data to send to the SDIO device. The data buffer should be aligned to the block size (64 bytes) if data size is greater that block size (64 bytes).
[in]lengthThe number of bytes to send
[out]responseThe response from the SDIO device
Returns
The status of the configure request

◆ cyhal_sdio_transfer_async()

cy_rslt_t cyhal_sdio_transfer_async ( cyhal_sdio_t *  obj,
cyhal_transfer_t  direction,
uint32_t  argument,
const uint32_t *  data,
uint16_t  length 
)

Performs a bulk asynchronus data transfer (CMD=53) to the SDIO block.

Parameters
[in,out]objThe SDIO object
[in]directionThe direction of transfer (read/write)
[in]argumentThe argument to the command
[in]dataThe data to send to the SDIO device
[in]lengthThe number of bytes to send
Returns
The status of the configure request

◆ cyhal_sdio_is_busy()

bool cyhal_sdio_is_busy ( const cyhal_sdio_t *  obj)

Checks if the specified SDIO is in use

Parameters
[in]objThe SDIO peripheral to check
Returns
Indication of whether the SDIO is still transmitting

◆ cyhal_sdio_abort_async()

cy_rslt_t cyhal_sdio_abort_async ( const cyhal_sdio_t *  obj)

Abort an SDIO transfer

Parameters
[in]objThe SDIO peripheral to stop
Returns
The status of the abort_async request

◆ cyhal_sdio_register_callback()

void cyhal_sdio_register_callback ( cyhal_sdio_t *  obj,
cyhal_sdio_event_callback_t  callback,
void *  callback_arg 
)

The SDIO event callback registration

Parameters
[in]objThe SDIO object
[in]callbackThe callback function which will be invoked when the event triggers
[in]callback_argGeneric argument that will be provided to the callback when executed

◆ cyhal_sdio_enable_event()

void cyhal_sdio_enable_event ( cyhal_sdio_t *  obj,
cyhal_sdio_event_t  event,
uint8_t  intrPriority,
bool  enable 
)

Configure which SDIO events trigger callbacks.

Parameters
[in]objThe SDIO object
[in]eventThe SDIO event type
[in]intrPriorityThe priority for NVIC interrupt events
[in]enableSet to true to enable events, or false to disable them