PSoC 6 Hardware Abstraction Layer (HAL)
SDHC (SD Host Controller)

General Description

High level interface for interacting with the Cypress SDHC.

The SD Host Controller allows data to be read from and written to several types of memory cards, including SD and eMMC (see cyhal_sdhc_card_type_t for a full list).

Data Structures

struct  cyhal_sdhc_config_t
 Defines configuration options for the SDHC block. More...
 

Macros

#define CYHAL_SDHC_RSLT_ERR_PIN   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_SDHC, 0))
 
#define CYHAL_SDHC_RSLT_ERR_PIN   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_SDHC, 0))
 

Typedefs

typedef void(* cyhal_sdhc_event_callback_t) (void *callback_arg, cyhal_sdhc_event_t event)
 

Enumerations

enum  cyhal_sdhc_card_type_t {
  CYHAL_SDHC_SD, CYHAL_SDHC_SDIO, CYHAL_SDHC_EMMC, CYHAL_SDHC_COMBO,
  CYHAL_SDHC_UNUSABLE, CYHAL_SDHC_NOT_EMMC
}
 
enum  cyhal_sdhc_event_t {
  CYHAL_SDHC_CMD_COMPLETE = 0x0001, CYHAL_SDHC_XFER_COMPLETE = 0x0002, CYHAL_SDHC_BGAP_EVENT = 0x0004, CYHAL_SDHC_DMA_INTERRUPT = 0x0008,
  CYHAL_SDHC_BUF_WR_READY = 0x0010, CYHAL_SDHC_BUF_RD_READY = 0x0020, CYHAL_SDHC_CARD_INSERTION = 0x0040, CYHAL_SDHC_CARD_REMOVAL = 0x0080,
  CYHAL_SDHC_CARD_INTERRUPT = 0x0100, CYHAL_SDHC_INT_A = 0x0200, CYHAL_SDHC_INT_B = 0x0400, CYHAL_SDHC_INT_C = 0x0800,
  CYHAL_SDHC_RE_TUNE_EVENT = 0x1000, CYHAL_SDHC_FX_EVENT = 0x2000, CYHAL_SDHC_CQE_EVENT = 0x4000, CYHAL_SDHC_ERR_INTERRUPT = 0x8000,
  CYHAL_SDHC_ALL_INTERRUPTS = 0xFFFF
}
 

Functions

cy_rslt_t cyhal_sdhc_init (cyhal_sdhc_t *obj, const cyhal_sdhc_config_t *config, cyhal_gpio_t cmd, cyhal_gpio_t clk, cyhal_gpio_t data0, cyhal_gpio_t data1, cyhal_gpio_t data2, cyhal_gpio_t data3, cyhal_gpio_t data4, cyhal_gpio_t data5, cyhal_gpio_t data6, cyhal_gpio_t data7, cyhal_gpio_t cardDetect, cyhal_gpio_t ioVoltSel, cyhal_gpio_t cardIfPwrEn, cyhal_gpio_t cardMechWriteProt, cyhal_gpio_t ledCtrl, cyhal_gpio_t cardEmmcReset)
 
void cyhal_sdhc_free (cyhal_sdhc_t *obj)
 
cy_rslt_t cyhal_sdhc_read (const cyhal_sdhc_t *obj, uint32_t address, uint8_t *data, size_t *length)
 
cy_rslt_t cyhal_sdhc_write (const cyhal_sdhc_t *obj, uint32_t address, const uint8_t *data, size_t *length)
 
cy_rslt_t cyhal_sdhc_erase (const cyhal_sdhc_t *obj, uint32_t startAddr, size_t length)
 
cy_rslt_t cyhal_sdhc_read_async (const cyhal_sdhc_t *obj, uint32_t address, uint8_t *data, size_t *length)
 
cy_rslt_t cyhal_sdhc_write_async (const cyhal_sdhc_t *obj, uint32_t address, const uint8_t *data, size_t *length)
 
bool cyhal_sdhc_is_busy (const cyhal_sdhc_t *obj)
 
cy_rslt_t cyhal_sdhc_abort_async (const cyhal_sdhc_t *obj)
 
void cyhal_sdhc_register_callback (cyhal_sdhc_t *obj, cyhal_sdhc_event_callback_t callback, void *callback_arg)
 
void cyhal_sdhc_enable_event (cyhal_sdhc_t *obj, cyhal_sdhc_event_t event, uint8_t intrPriority, bool enable)
 

Data Structure Documentation

◆ cyhal_sdhc_config_t

struct cyhal_sdhc_config_t
Data Fields
bool enableLedControl Drive one IO to indicate when the card is being accessed.
bool lowVoltageSignaling Whether 1.8V signaling is supported.
bool isEmmc true if eMMC card, otherwise false
uint8_t busWidth The desired bus width.

Macro Definition Documentation

◆ CYHAL_SDHC_RSLT_ERR_PIN [1/2]

#define CYHAL_SDHC_RSLT_ERR_PIN   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_SDHC, 0))

Pin related Error. >

◆ CYHAL_SDHC_RSLT_ERR_PIN [2/2]

#define CYHAL_SDHC_RSLT_ERR_PIN   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_SDHC, 0))

Pin related Error. >

Typedef Documentation

◆ cyhal_sdhc_event_callback_t

typedef void(* cyhal_sdhc_event_callback_t) (void *callback_arg, cyhal_sdhc_event_t event)

Handler for SDHC interrupts

Enumeration Type Documentation

◆ cyhal_sdhc_card_type_t

Card types

Enumerator
CYHAL_SDHC_SD 

Secure Digital card.

CYHAL_SDHC_SDIO 

SD Input Output card.

CYHAL_SDHC_EMMC 

Embedded Multimedia card.

CYHAL_SDHC_COMBO 

Combo Card (SD + SDIO)

CYHAL_SDHC_UNUSABLE 

Unusable card or unsupported type.

CYHAL_SDHC_NOT_EMMC 

Not an eMMC card.

◆ cyhal_sdhc_event_t

SDHC interrupt triggers

Enumerator
CYHAL_SDHC_XFER_COMPLETE 

Command Complete

CYHAL_SDHC_BGAP_EVENT 

Host read/write transfer is complete

CYHAL_SDHC_DMA_INTERRUPT 

This bit is set when both read/write transaction is stopped at the block gap

CYHAL_SDHC_BUF_WR_READY 

Host controller detects an SDMA Buffer Boundary during transfer

CYHAL_SDHC_BUF_RD_READY 

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

CYHAL_SDHC_CARD_INSERTION 

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

CYHAL_SDHC_CARD_REMOVAL 

This bit is set if the Card Inserted in the Present State register changes from 0 to 1.

CYHAL_SDHC_CARD_INTERRUPT 

This bit is set if the Card Inserted in the Present State register changes from 1 to 0.

CYHAL_SDHC_INT_A 

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

CYHAL_SDHC_FX_EVENT 

This bit is set if the Re-Tuning Request changes from 0 to 1

CYHAL_SDHC_CQE_EVENT 

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

CYHAL_SDHC_ERR_INTERRUPT 

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

CYHAL_SDHC_ALL_INTERRUPTS 

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

Function Documentation

◆ cyhal_sdhc_init()

cy_rslt_t cyhal_sdhc_init ( cyhal_sdhc_t *  obj,
const cyhal_sdhc_config_t *  config,
cyhal_gpio_t  cmd,
cyhal_gpio_t  clk,
cyhal_gpio_t  data0,
cyhal_gpio_t  data1,
cyhal_gpio_t  data2,
cyhal_gpio_t  data3,
cyhal_gpio_t  data4,
cyhal_gpio_t  data5,
cyhal_gpio_t  data6,
cyhal_gpio_t  data7,
cyhal_gpio_t  cardDetect,
cyhal_gpio_t  ioVoltSel,
cyhal_gpio_t  cardIfPwrEn,
cyhal_gpio_t  cardMechWriteProt,
cyhal_gpio_t  ledCtrl,
cyhal_gpio_t  cardEmmcReset 
)

Initialize the SDHC peripheral

Parameters
[out]objThe SDHC object
[in]configThe card configuration 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
[in]data4The pin connected to the data4 signal
[in]data5The pin connected to the data5 signal
[in]data6The pin connected to the data6 signal
[in]data7The pin connected to the data7 signal
[in]cardDetectThe pin connected to the cardDetect signal
[out]ioVoltSelThe pin connected to the ioVoltSel signal
[out]cardIfPwrEnThe pin connected to the cardIfPwrEn signal
[in]cardMechWriteProtThe pin connected to the cardMechWriteProt signal
[in]ledCtrlThe pin connected to the ledCtrl signal
[in]cardEmmcResetThe pin connected to the cardEmmcReset signal
Returns
The status of the init request

◆ cyhal_sdhc_free()

void cyhal_sdhc_free ( cyhal_sdhc_t *  obj)

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

Parameters
[in,out]objThe SDHC object

◆ cyhal_sdhc_read()

cy_rslt_t cyhal_sdhc_read ( const cyhal_sdhc_t *  obj,
uint32_t  address,
uint8_t *  data,
size_t *  length 
)

Attempts to read data over the SDHC peripheral.

Parameters
[in]objThe SDHC object
[in]addressThe address to read data from
[out]dataPointer to the byte-array of data to read from the device
[in,out]lengthNumber of 512 byte blocks to read, updated with the number actually read
Returns
The status of the read request

◆ cyhal_sdhc_write()

cy_rslt_t cyhal_sdhc_write ( const cyhal_sdhc_t *  obj,
uint32_t  address,
const uint8_t *  data,
size_t *  length 
)

Attempts to write data over SDHC peripheral

Parameters
[in]objThe SDHC object
[in]addressThe address to write data to
[in]dataPointer to the byte-array of data to write to the device
[in,out]lengthNumber of 512 byte blocks to write, updated with the number actually written
Returns
The status of the write request

◆ cyhal_sdhc_erase()

cy_rslt_t cyhal_sdhc_erase ( const cyhal_sdhc_t *  obj,
uint32_t  startAddr,
size_t  length 
)

Attempts to erase a block of data over the SDHC peripheral

Parameters
[in]objThe SDHC object
[in]startAddrIs the address of the first byte to erase
[in]lengthNumber of 512 byte blocks (starting at startAddr) to erase
Returns
The status of the erase request

◆ cyhal_sdhc_read_async()

cy_rslt_t cyhal_sdhc_read_async ( const cyhal_sdhc_t *  obj,
uint32_t  address,
uint8_t *  data,
size_t *  length 
)

Begin the SDHC read

Parameters
[in]objThe SDHC object that holds the transfer information
[in]addressThe address to read data from
[out]dataThe receive buffer
[in,out]lengthNumber of 512 byte blocks to read, updated with the number actually read
Returns
The status of the read_async request

◆ cyhal_sdhc_write_async()

cy_rslt_t cyhal_sdhc_write_async ( const cyhal_sdhc_t *  obj,
uint32_t  address,
const uint8_t *  data,
size_t *  length 
)

Begin the SDHC write

Parameters
[in]objThe SDHC object that holds the transfer information
[in]addressThe address to write data to
[in]dataThe transmit buffer
[in,out]lengthThe number of 512 byte blocks to write, updated with the number actually written
Returns
The status of the write_async request

◆ cyhal_sdhc_is_busy()

bool cyhal_sdhc_is_busy ( const cyhal_sdhc_t *  obj)

Checks if the specified SDHC peripheral is in use

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

◆ cyhal_sdhc_abort_async()

cy_rslt_t cyhal_sdhc_abort_async ( const cyhal_sdhc_t *  obj)

Abort an SDHC transfer

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

◆ cyhal_sdhc_register_callback()

void cyhal_sdhc_register_callback ( cyhal_sdhc_t *  obj,
cyhal_sdhc_event_callback_t  callback,
void *  callback_arg 
)

The SDHC callback handler registration

Parameters
[in]objThe SDHC object
[in]callbackThe callback handler which will be invoked when the interrupt fires
[in]callback_argGeneric argument that will be provided to the callback when called

◆ cyhal_sdhc_enable_event()

void cyhal_sdhc_enable_event ( cyhal_sdhc_t *  obj,
cyhal_sdhc_event_t  event,
uint8_t  intrPriority,
bool  enable 
)

Configure SDHC event enablement.

Parameters
[in]objThe SDHC object
[in]eventThe SDHC event type
[in]intrPriorityThe priority for NVIC interrupt events
[in]enableTrue to turn on interrupts, False to turn off