The MCUXpresso SDK provides a driver to access the Secure Digital Card based on the SPI driver.
Function groups
This function group implements the SD card functional API in the SPI mode.
Typical use case
{
return;
}
memset(g_testWriteBuffer, 0x17U, sizeof(g_testWriteBuffer));
while (true)
{
memset(g_testReadBuffer, 0U, sizeof(g_testReadBuffer));
if (memcmp(g_testReadBuffer, g_testReadBuffer, sizeof(g_testWriteBuffer)))
{
break;
}
}
|
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
} |
| 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_t {
kSDSPI_ResponseTypeR1 = 0U,
kSDSPI_ResponseTypeR1b = 1U,
kSDSPI_ResponseTypeR2 = 2U,
kSDSPI_ResponseTypeR3 = 3U,
kSDSPI_ResponseTypeR7 = 4U
} |
| SDSPI response type. More...
|
|
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.
|
|
uint32_t(* | getCurrentMilliseconds )(void) |
| Get current time in milliseconds.
|
|
Define the card structure including the necessary fields to identify and describe the card.
uint32_t sdspi_card_t::flags |
Enumerator |
---|
kStatus_SDSPI_SetFrequencyFailed |
Set frequency failed.
|
kStatus_SDSPI_ExchangeFailed |
Exchange data on SPI bus failed.
|
kStatus_SDSPI_WaitReadyFailed |
Wait card ready failed.
|
kStatus_SDSPI_ResponseError |
Response is error.
|
kStatus_SDSPI_WriteProtected |
Write protected.
|
kStatus_SDSPI_GoIdleFailed |
Go idle failed.
|
kStatus_SDSPI_SendCommandFailed |
Send command failed.
|
kStatus_SDSPI_ReadFailed |
Read data failed.
|
kStatus_SDSPI_WriteFailed |
Write data failed.
|
kStatus_SDSPI_SendInterfaceConditionFailed |
Send interface condition failed.
|
kStatus_SDSPI_SendOperationConditionFailed |
Send operation condition failed.
|
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_SDSPI_StopTransmissionFailed |
Stop transmission failed.
|
kStatus_SDSPI_SendApplicationCommandFailed |
Send application command failed.
|
Enumerator |
---|
kSDSPI_SupportHighCapacityFlag |
Card is high capacity.
|
kSDSPI_SupportSdhcFlag |
Card is SDHC.
|
kSDSPI_SupportSdxcFlag |
Card is SDXC.
|
kSDSPI_SupportSdscFlag |
Card is SDSC.
|
Enumerator |
---|
kSDSPI_ResponseTypeR1 |
Response 1.
|
kSDSPI_ResponseTypeR1b |
Response 1 with busy.
|
kSDSPI_ResponseTypeR2 |
Response 2.
|
kSDSPI_ResponseTypeR3 |
Response 3.
|
kSDSPI_ResponseTypeR7 |
Response 7.
|
This function initializes the card on a specific SPI instance.
- Parameters
-
- Return values
-
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. |
This function deinitializes the specific card.
- Parameters
-
This function checks if the card is write-protected via CSD register.
- Parameters
-
- Return values
-
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.
- Parameters
-
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 |
- Return values
-
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
- Parameters
-
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 |
- Return values
-
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. |