Low-Level

group group_sd_host_low_level_functions

Functions

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.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • config: The SD host module configuration.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

void Cy_SD_Host_DeInit(SDHC_Type *base)

Restores the SD Host block registers back to default.

Parameters
  • *base: The SD host registers structure pointer.

void Cy_SD_Host_Enable(SDHC_Type *base)

Enables the SD host block.

Parameters
  • *base: The SD host registers structure pointer.

void Cy_SD_Host_Disable(SDHC_Type *base)

Disables the SD host block.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE void Cy_SD_Host_EnableSdClk (SDHC_Type *base)

Enables the SD clock (SD host drives the SDCLK line).

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE void Cy_SD_Host_DisableSdClk (SDHC_Type *base)

Disables the SD clock (The SD Host doesn’t drive the SDCLK line).

Parameters
  • *base: The SD host registers structure pointer.

cy_en_sd_host_status_t Cy_SD_Host_SetSdClkDiv(SDHC_Type *base, uint16_t clkDiv)

Changes the speed of the SD bus.

This function should be called along with Cy_SD_Host_SetHostSpeedMode to configure the bus correctly.

note

The divider is clocked from the CLK_HF clock (100 MHz). To determine the SD bus speed divide the clock CLK_HF by the divider value passed in this function. The divider value is 2^clkDiv.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • clkDiv: The clock divider for the SD clock.

bool Cy_SD_Host_IsWpSet(SDHC_Type const *base)

Returns the state of the write protect switch on the SD card.

Return

bool true - the write protect is set, false - the write protect is not set.

Parameters
  • *base: The SD host registers structure pointer.

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.

It doesn’t change the bus width on the card side. To change the bus width on the card, call Cy_SD_Host_SetBusWidth().

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • width: The width of the data bus.

cy_en_sd_host_status_t Cy_SD_Host_SetBusWidth(SDHC_Type *base, cy_en_sd_host_bus_width_t width, cy_stc_sd_host_context_t const *context)

Sends out the SD bus width changing command.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • width: The width of the data bus.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

cy_en_sd_host_status_t Cy_SD_Host_SetHostSpeedMode(SDHC_Type *base, cy_en_sd_host_bus_speed_mode_t speedMode)

Only updates the host register to indicate bus speed mode.

This function doesn’t change the speed on the bus, or change anything in the card.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • speedMode: Bus Speed mode.

cy_en_sd_host_status_t Cy_SD_Host_SetBusSpeedMode(SDHC_Type *base, cy_en_sd_host_bus_speed_mode_t speedMode, cy_stc_sd_host_context_t const *context)

Negotiates with the card to change the bus speed mode of the card and the host.

It doesn’t change the SD clock frequency that must be done separately.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • speedMode: Bus speed mode.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

cy_en_sd_host_status_t Cy_SD_Host_SelBusVoltage(SDHC_Type *base, bool enable18VSignal, cy_stc_sd_host_context_t *context)

Negotiates with the SD card to change the bus signaling level to 1.8V.

After this function is called, the card is in the ready state.

note

The host needs to change the regulator supplying voltage to the VDDIO of the SD block in order to operate at 1.8V.

note

This function changes RCA to 0 in the context. RCA in the context should be updated (context.RCA = Cy_SD_Host_GetRca();) when the card is in the Identification state.

note

This function is applicable for SD cards only.

note

The SD card power supply should be disabled and initialized again when this function returns CY_SD_HOST_ERROR_UNUSABLE_CARD.

note

The dedicated io_volt_sel pin is used to change the regulator supplying voltage to the VDDIO of the SD block in order to operate at 1.8V. To configure the custom IO pin in order to control (using the GPIO driver) the regulator supplying voltage, the user must implement weak Cy_SD_Host_ChangeIoVoltage(). Also, this function must set the SIGNALING_EN bit of the SDHC_CORE_HOST_CTRL2_R register when ioVoltage = CY_SD_HOST_IO_VOLT_1_8V.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • enable18VSignal: If true, use the 1.8V signaling, false - use the 3.3V signaling.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

void Cy_SD_Host_EnableCardVoltage(SDHC_Type *base)

Sets the card_if_pwr_en pin high.

This pin can be used to enable a voltage regulator used to power the card.

Parameters
  • *base: The SD host registers structure pointer.

void Cy_SD_Host_DisableCardVoltage(SDHC_Type *base)

Sets the card_if_pwr_en pin low.

This pin can be used to disable a voltage regulator used to power the card.

Parameters
  • *base: The SD host registers structure pointer.

cy_en_sd_host_status_t Cy_SD_Host_GetResponse(SDHC_Type const *base, uint32_t *responsePtr, bool largeResponse)

This function reads the response register from the last completed command.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *responsePtr: The pointer to response data.

  • largeResponse: If true, the response is 136 bits, false - 32 bits.

cy_en_sd_host_status_t Cy_SD_Host_SendCommand(SDHC_Type *base, cy_stc_sd_host_cmd_config_t const *config)

Starts sending a command on the SD bus.

If the command uses the data lines Cy_SD_Host_InitDataTransfer() must be call first. This function returns before the command completes. To determine if the command is done, read the Normal Interrupt Status register and check the CMD_COMPLETE flag. To determine if the entire transfer is done check the XFER_COMPLETE flag. Also the interrupt is used and flags are set on these events in an ISR.

note

It is the user's responsibility to clear the CY_SD_HOST_CMD_COMPLETE flag after calling this function.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *config: The configuration structure for the command.

cy_en_sd_host_status_t Cy_SD_Host_InitDataTransfer(SDHC_Type *base, cy_stc_sd_host_data_config_t const *dataConfig)

Initializes the SD block for a data transfer.

It does not start a transfer. To start a transfer call Cy_SD_Host_SendCommand() after calling this function. If DMA is not used for data transfer, the buffer needs to be filled with data first if this is a write.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • dataConfig: The pointer to the data transfer configuration structure.

__STATIC_INLINE uint32_t Cy_SD_Host_BufferRead (SDHC_Type const *base)

Reads 32-bits of data from the read buffer.

Only use this function if not using SD block DMA to transfer data from buffer.

Return

uint32_t Data that is being read.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE cy_en_sd_host_status_t Cy_SD_Host_BufferWrite (SDHC_Type *base, uint32_t data)

Writes 32-bits of data into the write buffer.

Only use this function if not using SD block DMA to transfer data to buffer.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • data: Data to be written.

void Cy_SD_Host_ChangeIoVoltage(SDHC_Type *base, cy_en_sd_host_io_voltage_t ioVoltage)

Changes the logic level on the sd_io_volt_sel line.

It assumes that this line is used to control a regulator connected to the VDDIO of the PSoC. This regulator allows for switching between the 3.3V and 1.8V signaling.

note

The dedicated io_volt_sel pin is used to change the regulator supplying voltage to the VDDIO of the SD block in order to operate at 1.8V. To configure the custom IO pin in order to control (using the GPIO driver) the regulator supplying voltage, the user must implement weak Cy_SD_Host_ChangeIoVoltage(). Also, this function must set the SIGNALING_EN bit of the SDHC_CORE_HOST_CTRL2_R register when ioVoltage = CY_SD_HOST_IO_VOLT_1_8V.

Parameters
  • *base: The SD host registers structure pointer.

  • ioVoltage: The voltage for IO.

__STATIC_INLINE void Cy_SD_Host_StopAtBlockGap (SDHC_Type *base)

Commands SD host to stop transmitting at the next block gap.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE void Cy_SD_Host_ContinueFromBlockGap (SDHC_Type *base)

Commands SD host to continue transmitting after stopping at the block gap.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE uint32_t Cy_SD_Host_GetAutoCmdErrStatus (SDHC_Type const *base)

Gets the SD host error status of the auto command.

Return

uint32_t The bit mask of the Auto Command status.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE cy_en_sd_host_status_t Cy_SD_Host_EnableAutoCmd23 (SDHC_Type *base)

If the card supports AutoCmd23 call this function to enable it in the host.

Return

cy_en_sd_host_status_t.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE void Cy_SD_Host_DisableAutoCmd23 (SDHC_Type *base)

Removes support for AutoCmd23 if it was previously set.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE cy_en_sd_host_status_t Cy_SD_Host_EnableAsyncInterrupt (SDHC_Type *base)

Enables the Asynchronous Interrupt for SDIO cards.

Set this only if the card supports this feature.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE void Cy_SD_Host_DisableAsyncInterrupt (SDHC_Type *base)

Removes the support for the Asynchronous Interrupt if it was previously set.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE uint32_t Cy_SD_Host_GetAdmaErrorStatus (SDHC_Type const *base)

Returns the ADMA Error Status register.

Return

uint32_t The bit mask of ADMA Error Status.

Parameters
  • *base: The SD host registers structure pointer.

__STATIC_INLINE void Cy_SD_Host_EMMC_Reset (SDHC_Type *base)

Resets the eMMC card.

Parameters
  • *base: The SD host registers structure pointer.

cy_en_sd_host_status_t Cy_SD_Host_AbortTransfer(SDHC_Type *base, cy_stc_sd_host_context_t const *context)

Calling this function causes abortion of the currently executing command with data.

It doesn’t issue a reset, that is the users responsibility.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

cy_en_sd_host_status_t Cy_SD_Host_WriteProtect(SDHC_Type *base, cy_en_sd_host_write_protect_t writeProtect, cy_stc_sd_host_context_t *context)

Write protects the blocks of data from the SD card.

This function should only be called after Cy_SD_Host_SDCard_Init()/eMMC_Init().

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • writeProtect: cy_en_sd_host_write_protect_t.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

uint32_t Cy_SD_Host_GetCardStatus(SDHC_Type *base, cy_stc_sd_host_context_t const *context)

Returns the card status.

Return

uint32_t The card status (the result of the CMD13 command).

Parameters
  • *base: The SD host registers structure pointer.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

cy_en_sd_host_status_t Cy_SD_Host_GetSdStatus(SDHC_Type *base, uint32_t *sdStatus, cy_stc_sd_host_context_t const *context)

Returns the SD status from the card.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *sdStatus: The pointer to where to store the SD status array.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

uint32_t Cy_SD_Host_GetOcr(SDHC_Type *base, cy_stc_sd_host_context_t const *context)

Reads the Operating Condition Register (OCR) register from the card.

note

This function can be used only if the card is in the Idle state.

note

For combo cards, the function returns the OCR register for the IO portion only.

Return

uint32_t The OCR register.

Parameters
  • *base: The SD host registers structure pointer.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

cy_en_sd_host_status_t Cy_SD_Host_GetCid(SDHC_Type *base, uint32_t *cid)

Returns the Card Identification Register (CID) contents.

note

This function can be used only if the card is in the Ready state.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • cid: The pointer to where to store the CID register.

cy_en_sd_host_status_t Cy_SD_Host_GetCsd(SDHC_Type *base, uint32_t *csd, cy_stc_sd_host_context_t *context)

Returns the Card Specific Data (CSD) register contents.

note

This function can be used only if the card is in the Stand-by state.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *csd: The pointer to where to store the CSD register.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

cy_en_sd_host_status_t Cy_SD_Host_GetExtCsd(SDHC_Type *base, uint32_t *extCsd, cy_stc_sd_host_context_t *context)

Returns the EXTCSD Register contents.

This is only for EMMC cards. There are 512 bytes of data being read.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *extCsd: The pointer to where to store the EXTCSD register.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

uint32_t Cy_SD_Host_GetRca(SDHC_Type *base)

Reads the Relative Card Address (RCA) register from the card.

note

This function can be used only if the card is in the Identification or Stand-by state.

Return

uint32_t The RCA register.

Parameters
  • *base: The SD host registers structure pointer.

cy_en_sd_host_status_t Cy_SD_Host_GetScr(SDHC_Type *base, uint32_t *scr, cy_stc_sd_host_context_t const *context)

Returns the SD Card Configuration Register (SCR) Register contents.

note

This function can be used only if the card is in the Transition state.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *scr: The pointer to where to store the SCR register.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure. If only the SD host functions which do not require context will be used, pass NULL as the pointer to the context.

uint32_t Cy_SD_Host_GetPresentState(SDHC_Type const *base)

Returns the values of the present state register.

Return

The value of the present state register.

Parameters
  • *base: The SD host registers structure pointer.

bool Cy_SD_Host_IsCardConnected(SDHC_Type const *base)

Checks to see if a card is currently connected.

note

You can use any GPIO custom pin for Card Detect. Add the SD Host driver Cy_SD_Host_IsCardConnected() function with the __WEAK type to your code. This function could read the value from any GPIO pin and return true when the card is connected.

Return

bool true - the card is connected, false - the card is removed (not connected).

Parameters
  • *base: The SD host registers structure pointer.

void Cy_SD_Host_SoftwareReset(SDHC_Type *base, cy_en_sd_host_reset_t reset)

Issues the software reset command to the SD card.

Parameters
  • *base: The SD host registers structure pointer.

  • reset: The reset type.

cy_en_syspm_status_t Cy_SD_Host_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode)

This function handles the transition of the SD Host into and out of Deep Sleep mode.

It disables SD CLK before going to Deep Sleep mode and enables SD CLK after wake up from Deep Sleep mode. If the DAT line is active, or a read (write) transfer is being executed on the bus, the device cannot enter Deep Sleep mode.

This function must be called during execution of Cy_SysPm_CpuEnterDeepSleep. To do it, register this function as a callback before calling Cy_SysPm_CpuEnterDeepSleep : specify CY_SYSPM_DEEPSLEEP as the callback type and call Cy_SysPm_RegisterCallback.

note

When waking up from Deep Sleep, the SD Host driver requires up to 1 us for clock stabilization. By default the SD Host driver will wait this length of time on power up. The waiting loop is implemented in this function. If the application is time sensitive this delay can be overridden by the application by defining CY_SD_HOST_CLK_RAMP_UP_TIME_US_WAKEUP. This allows the application to perform other operations while the clock is stabilizing in the background. However, the application must still make sure that the SD Host clock has had time to stabilize before attempting to use the SD card. The recommended way to override the value is to specify this as a custom define on the compiler command line. This can be done by appending the entry to the DEFINES variable in the application Makefile. Eg: DEFINES+=CY_SD_HOST_CLK_RAMP_UP_TIME_US_WAKEUP=40.

Return

cy_en_syspm_status_t

Parameters

cy_en_sd_host_status_t Cy_SD_Host_GetBlockCount(SDHC_Type *base, uint32_t *block_count, cy_stc_sd_host_context_t *context)

Returns the Block count in SD/eMMC Card.

Return

cy_en_sd_host_status_t

Parameters
  • *base: The SD host registers structure pointer.

  • *block_count: The pointer to store the block_count.

  • context: The pointer to the context structure cy_stc_sd_host_context_t allocated by the user. The structure is used during the SD host operation for internal configuration and data retention. The user must not modify anything in this structure.