![]() |
MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
Data Structures | |
struct | sdspi_host_t |
SDSPI host state. More... | |
struct | sdspi_card_t |
SD Card Structure. More... | |
Macros | |
#define | FSL_SDSPI_DRIVER_VERSION (MAKE_VERSION(2U, 2U, 1U)) /*2.2.1*/ |
Driver version. More... | |
#define | FSL_SDSPI_DEFAULT_BLOCK_SIZE (512U) |
Default block size. | |
#define | DSPI_DUMMY_DATA (0xFFU) |
Dummy byte define, OxFF should be defined as the dummy data. More... | |
#define | SDSPI_CARD_CRC_PROTECTION_ENABLE 0U |
This macro is used to enable or disable the CRC protection for SD card command. More... | |
Enumerations | |
enum | { 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 | { kSDSPI_SupportHighCapacityFlag = (1U << 0U), kSDSPI_SupportSdhcFlag = (1U << 1U), kSDSPI_SupportSdxcFlag = (1U << 2U), kSDSPI_SupportSdscFlag = (1U << 3U) } |
SDSPI card flag. More... | |
enum | { kSDSPI_ResponseTypeR1 = 0U, kSDSPI_ResponseTypeR1b = 1U, kSDSPI_ResponseTypeR2 = 2U, kSDSPI_ResponseTypeR3 = 3U, kSDSPI_ResponseTypeR7 = 4U } |
SDSPI response type. More... | |
enum | { kSDSPI_CmdGoIdle = kSDMMC_GoIdleState << 8U | kSDSPI_ResponseTypeR1, kSDSPI_CmdCrc = kSDSPI_CommandCrc << 8U | kSDSPI_ResponseTypeR1, kSDSPI_CmdSendInterfaceCondition } |
SDSPI command type. More... | |
enum | sdspi_cs_active_polarity_t { kSDSPI_CsActivePolarityHigh = 0U, kSDSPI_CsActivePolarityLow } |
cs active polarity 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. | |
void(* | init )(void) |
SPI initialization. | |
void(* | deinit )(void) |
SPI de-initialization. | |
void(* | csActivePolarity )(sdspi_cs_active_polarity_t polarity) |
SPI CS active polarity. | |
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 | internalBuffer [16U] |
internal buffer for card raw register 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 |
#define FSL_SDSPI_DRIVER_VERSION (MAKE_VERSION(2U, 2U, 1U)) /*2.2.1*/ |
#define DSPI_DUMMY_DATA (0xFFU) |
Dummy data used for Tx if there is no txData.
#define SDSPI_CARD_CRC_PROTECTION_ENABLE 0U |
The SPI interface is intialized in the CRC off mode by default.However, the RESET command(cmd0) that is used to switch the card to SPI mode, is recieved by by the card while in SD mode and therefore, shall have a valid CRC filed, after the card put into SPI mode , CRC check for all command include CMD0 will be done according to CMD59 setting, host can turn CRC option on and off using the CMD59, this command should be call before ACMD41. CMD8 CRC verification is always enabled. The host shall set correct CRC in the argument of CMD8. If CRC check is enabled, then sdspi code size and read/write performance will be lower than CRC off. CRC check is off by default.
anonymous enum |
anonymous enum |
anonymous enum |
anonymous enum |
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. |