MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides a driver to access the Secure Digital Card based on the SPI driver.
This function group implements the SD card functional API in the SPI mode.
Data Structures | |
struct | sdspi_host_t |
SDSPI host state. More... | |
struct | sdspi_card_t |
SD Card Structure. More... | |
Enumerations | |
enum | _sdspi_status { kStatus_SDSPI_SetFrequencyFailed = MAKE_STATUS(kStatusGroup_SDSPI, 0U), kStatus_SDSPI_ExchangeFailed = MAKE_STATUS(kStatusGroup_SDSPI, 1U), kStatus_SDSPI_WaitReadyFailed = MAKE_STATUS(kStatusGroup_SDSPI, 2U), kStatus_SDSPI_ResponseError = MAKE_STATUS(kStatusGroup_SDSPI, 3U), kStatus_SDSPI_WriteProtected = MAKE_STATUS(kStatusGroup_SDSPI, 4U), kStatus_SDSPI_GoIdleFailed = MAKE_STATUS(kStatusGroup_SDSPI, 5U), kStatus_SDSPI_SendCommandFailed = MAKE_STATUS(kStatusGroup_SDSPI, 6U), kStatus_SDSPI_ReadFailed = MAKE_STATUS(kStatusGroup_SDSPI, 7U), kStatus_SDSPI_WriteFailed = MAKE_STATUS(kStatusGroup_SDSPI, 8U), kStatus_SDSPI_SendInterfaceConditionFailed, kStatus_SDSPI_SendOperationConditionFailed, kStatus_SDSPI_ReadOcrFailed = MAKE_STATUS(kStatusGroup_SDSPI, 11U), kStatus_SDSPI_SetBlockSizeFailed = MAKE_STATUS(kStatusGroup_SDSPI, 12U), kStatus_SDSPI_SendCsdFailed = MAKE_STATUS(kStatusGroup_SDSPI, 13U), kStatus_SDSPI_SendCidFailed = MAKE_STATUS(kStatusGroup_SDSPI, 14U), kStatus_SDSPI_StopTransmissionFailed = MAKE_STATUS(kStatusGroup_SDSPI, 15U), kStatus_SDSPI_SendApplicationCommandFailed, kStatus_SDSPI_InvalidVoltage = MAKE_STATUS(kStatusGroup_SDSPI, 17U), kStatus_SDSPI_SwitchCmdFail = MAKE_STATUS(kStatusGroup_SDSPI, 18U), kStatus_SDSPI_NotSupportYet = MAKE_STATUS(kStatusGroup_SDSPI, 19U) } |
SDSPI API status. More... | |
enum | _sdspi_card_flag { kSDSPI_SupportHighCapacityFlag = (1U << 0U), kSDSPI_SupportSdhcFlag = (1U << 1U), kSDSPI_SupportSdxcFlag = (1U << 2U), kSDSPI_SupportSdscFlag = (1U << 3U) } |
SDSPI card flag. More... | |
enum | _sdspi_response_type { kSDSPI_ResponseTypeR1 = 0U, kSDSPI_ResponseTypeR1b = 1U, kSDSPI_ResponseTypeR2 = 2U, kSDSPI_ResponseTypeR3 = 3U, kSDSPI_ResponseTypeR7 = 4U } |
SDSPI response type. More... | |
enum | _sdspi_cmd { kSDSPI_CmdGoIdle = kSDMMC_GoIdleState << 8U | kSDSPI_ResponseTypeR1, kSDSPI_CmdCrc = kSDSPI_CommandCrc << 8U | kSDSPI_ResponseTypeR1, kSDSPI_CmdSendInterfaceCondition } |
SDSPI command type. More... | |
SDSPI Function | |
status_t | SDSPI_Init (sdspi_card_t *card) |
Initializes the card on a specific SPI instance. More... | |
void | SDSPI_Deinit (sdspi_card_t *card) |
Deinitializes the card. More... | |
bool | SDSPI_CheckReadOnly (sdspi_card_t *card) |
Checks whether the card is write-protected. More... | |
status_t | SDSPI_ReadBlocks (sdspi_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount) |
Reads blocks from the specific card. More... | |
status_t | SDSPI_WriteBlocks (sdspi_card_t *card, uint8_t *buffer, uint32_t startBlock, uint32_t blockCount) |
Writes blocks of data to the specific card. More... | |
status_t | SDSPI_SendCid (sdspi_card_t *card) |
Send GET-CID command In our sdspi init function, this function is removed for better code size, if id information is needed, you can call it after the init function directly. More... | |
status_t | SDSPI_SendPreErase (sdspi_card_t *card, uint32_t blockCount) |
Multiple blocks write pre-erase function. More... | |
status_t | SDSPI_EraseBlocks (sdspi_card_t *card, uint32_t startBlock, uint32_t blockCount) |
Block erase function. More... | |
status_t | SDSPI_SwitchToHighSpeed (sdspi_card_t *card) |
Switch to high speed function. More... | |
struct sdspi_host_t |
Data Fields | |
uint32_t | busBaudRate |
Bus baud rate. | |
status_t(* | setFrequency )(uint32_t frequency) |
Set frequency of SPI. | |
status_t(* | exchange )(uint8_t *in, uint8_t *out, uint32_t size) |
Exchange data over SPI. | |
struct sdspi_card_t |
Define the card structure including the necessary fields to identify and describe the card.
Data Fields | |
sdspi_host_t * | host |
Host state information. | |
uint32_t | relativeAddress |
Relative address of the card. | |
uint32_t | flags |
Flags defined in _sdspi_card_flag. More... | |
uint8_t | rawCid [16U] |
Raw CID content. | |
uint8_t | rawCsd [16U] |
Raw CSD content. | |
uint8_t | rawScr [8U] |
Raw SCR content. | |
uint32_t | ocr |
Raw OCR content. | |
sd_cid_t | cid |
CID. | |
sd_csd_t | csd |
CSD. | |
sd_scr_t | scr |
SCR. | |
uint32_t | blockCount |
Card total block number. | |
uint32_t | blockSize |
Card block size. | |
uint32_t sdspi_card_t::flags |
enum _sdspi_status |
enum _sdspi_card_flag |
enum _sdspi_response_type |
enum _sdspi_cmd |
status_t SDSPI_Init | ( | sdspi_card_t * | card | ) |
This function initializes the card on a specific SPI instance.
card | Card descriptor |
kStatus_SDSPI_SetFrequencyFailed | Set frequency failed. |
kStatus_SDSPI_GoIdleFailed | Go idle failed. |
kStatus_SDSPI_SendInterfaceConditionFailed | Send interface condition failed. |
kStatus_SDSPI_SendOperationConditionFailed | Send operation condition failed. |
kStatus_Timeout | Send command timeout. |
kStatus_SDSPI_NotSupportYet | Not support yet. |
kStatus_SDSPI_ReadOcrFailed | Read OCR failed. |
kStatus_SDSPI_SetBlockSizeFailed | Set block size failed. |
kStatus_SDSPI_SendCsdFailed | Send CSD failed. |
kStatus_SDSPI_SendCidFailed | Send CID failed. |
kStatus_Success | Operate successfully. |
void SDSPI_Deinit | ( | sdspi_card_t * | card | ) |
This function deinitializes the specific card.
card | Card descriptor |
bool SDSPI_CheckReadOnly | ( | sdspi_card_t * | card | ) |
This function checks if the card is write-protected via CSD register.
card | Card descriptor. |
true | Card is read only. |
false | Card isn't read only. |
status_t SDSPI_ReadBlocks | ( | sdspi_card_t * | card, |
uint8_t * | buffer, | ||
uint32_t | startBlock, | ||
uint32_t | blockCount | ||
) |
This function reads blocks from specific card.
card | Card descriptor. |
buffer | the buffer to hold the data read from card |
startBlock | the start block index |
blockCount | the number of blocks to read |
kStatus_SDSPI_SendCommandFailed | Send command failed. |
kStatus_SDSPI_ReadFailed | Read data failed. |
kStatus_SDSPI_StopTransmissionFailed | Stop transmission failed. |
kStatus_Success | Operate successfully. |
status_t SDSPI_WriteBlocks | ( | sdspi_card_t * | card, |
uint8_t * | buffer, | ||
uint32_t | startBlock, | ||
uint32_t | blockCount | ||
) |
This function writes blocks to specific card
card | Card descriptor. |
buffer | the buffer holding the data to be written to the card |
startBlock | the start block index |
blockCount | the number of blocks to write |
kStatus_SDSPI_WriteProtected | Card is write protected. |
kStatus_SDSPI_SendCommandFailed | Send command failed. |
kStatus_SDSPI_ResponseError | Response is error. |
kStatus_SDSPI_WriteFailed | Write data failed. |
kStatus_SDSPI_ExchangeFailed | Exchange data over SPI failed. |
kStatus_SDSPI_WaitReadyFailed | Wait card to be ready status failed. |
kStatus_Success | Operate successfully. |
status_t SDSPI_SendCid | ( | sdspi_card_t * | card | ) |
card | Card descriptor. |
kStatus_SDSPI_SendCommandFailed | Send command failed. |
kStatus_SDSPI_ReadFailed | Read data blocks failed. |
kStatus_Success | Operate successfully. |
status_t SDSPI_SendPreErase | ( | sdspi_card_t * | card, |
uint32_t | blockCount | ||
) |
This function should be called before SDSPI_WriteBlocks, it is used to set the number of the write blocks to be pre-erased before writing.
card | Card descriptor. |
blockCount | the block counts to be write. |
kStatus_SDSPI_SendCommandFailed | Send command failed. |
kStatus_SDSPI_SendApplicationCommandFailed | |
kStatus_SDSPI_ResponseError | |
kStatus_Success | Operate successfully. |
status_t SDSPI_EraseBlocks | ( | sdspi_card_t * | card, |
uint32_t | startBlock, | ||
uint32_t | blockCount | ||
) |
card | Card descriptor. |
startBlock | start block address to be erase. |
blockCount | the block counts to be erase. |
kStatus_SDSPI_WaitReadyFailed | Wait ready failed. |
kStatus_SDSPI_SendCommandFailed | Send command failed. |
kStatus_Success | Operate successfully. |
status_t SDSPI_SwitchToHighSpeed | ( | sdspi_card_t * | card | ) |
This function can be called after SDSPI_Init function if target board's layout support >25MHZ spi baudrate, otherwise this function is useless.Be careful with call this function, code size and stack usage will be enlarge.
card | Card descriptor. |
kStatus_Fail | switch failed. |
kStatus_Success | Operate successfully. |