STM32_EVAL_SPI_SD_Exported_Functions
[STM32_EVAL_SPI_SD]

Functions

void SD_DeInit (void)
 DeInitializes the SDIO interface.
uint8_t SD_Detect (void)
 Detect if SD card is correctly plugged in the memory slot.
SD_Error SD_GetCardInfo (SD_CardInfo *cardinfo)
 Returns information about specific card.
SD_Error SD_GetCIDRegister (SD_CID *SD_cid)
 Read the CID card register.
SD_Error SD_GetCSDRegister (SD_CSD *SD_csd)
 Read the CSD card register.
uint8_t SD_GetDataResponse (void)
 Get SD card data response.
SD_Error SD_GetResponse (uint8_t Response)
 Returns the SD response.
uint16_t SD_GetStatus (void)
 Gets the cuurent sd card data transfer status.
SD_Error SD_GoIdleState (void)
 Put SD in Idle state.
SD_Error SD_Init (void)
 Initializes the SD Card and put it into StandBy State (Ready for data transfer).
SD_Error SD_ReadBlock (uint8_t *pBuffer, uint32_t ReadAddr, uint16_t BlockSize)
 Allows to read one block from a specified address in a card.
uint8_t SD_ReadByte (void)
 Read a byte from the SD.
SD_Error SD_ReadMultiBlocks (uint8_t *pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
 Allows to read blocks from a specified address in a card.
void SD_SendCmd (uint8_t Cmd, uint32_t Arg, uint8_t Crc)
 Send 5 bytes command to the SD card.
SD_Error SD_WriteBlock (uint8_t *pBuffer, uint32_t WriteAddr, uint16_t BlockSize)
 Allows to write one block starting from a specified address in a card.
uint8_t SD_WriteByte (uint8_t byte)
 Write a byte on the SD.
SD_Error SD_WriteMultiBlocks (uint8_t *pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
 Allows to write blocks starting from a specified address in a card.

Function Documentation

void SD_DeInit ( void   ) 

DeInitializes the SDIO interface.

Parameters:
None 
Return values:
None DeInitializes the SDIO interface.
Parameters:
None 
Return values:
None 

Definition at line 211 of file stm32_eval_sdio_sd.c.

References SD_LowLevel_DeInit().

uint8_t SD_Detect ( void   ) 

Detect if SD card is correctly plugged in the memory slot.

Parameters:
None 
Return values:
Return if SD is detected or not

< Check GPIO to detect SD

< Check GPIO to detect SD

Definition at line 342 of file stm32_eval_sdio_sd.c.

References Bit_RESET, GPIO_ReadInputData(), GPIO_ReadInputDataBit(), SD_DETECT_GPIO_PORT, SD_DETECT_PIN, SD_NOT_PRESENT, SD_PRESENT, and status.

Referenced by SD_GetState().

SD_Error SD_GetCardInfo ( SD_CardInfo cardinfo  ) 

Returns information about specific card.

Parameters:
cardinfo,: pointer to a SD_CardInfo structure that contains all SD card information.
Return values:
SD_Error,: SD Card Error code.
Parameters:
cardinfo,: pointer to a SD_CardInfo structure that contains all SD card information.
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< Byte 0

< Byte 1

< Byte 2

< Byte 3

< Byte 4

< Byte 5

< Byte 6

< Reserved

< Byte 7

< Byte 8

< Byte 9

< Byte 10

< Byte 7

< Byte 8

< Byte 9

< Byte 10

< Byte 11

< Byte 12

< Byte 13

< Byte 14

< Byte 15

< Byte 0

< Byte 1

< Byte 2

< Byte 3

< Byte 4

< Byte 5

< Byte 6

< Byte 7

< Byte 8

< Byte 9

< Byte 10

< Byte 11

< Byte 12

< Byte 13

< Byte 14

< Byte 15

< Returns the reponse

Definition at line 608 of file stm32_eval_sdio_sd.c.

References SD_CardInfo::CardBlockSize, SD_CardInfo::CardCapacity, SD_CSD::CardComdClasses, CardType, SD_CardInfo::CardType, SD_CID::CID_CRC, CID_Tab, SD_CSD::ContentProtectAppli, SD_CSD::CopyFlag, SD_CSD::CSD_CRC, CSD_Tab, SD_CSD::CSDStruct, SD_CSD::DeviceSize, SD_CSD::DeviceSizeMul, SD_CSD::DSRImpl, SD_CSD::ECC, SD_CSD::EraseGrMul, SD_CSD::EraseGrSize, SD_CSD::FileFormat, SD_CSD::FileFormatGrouop, SD_CSD::ManDeflECC, SD_CID::ManufactDate, SD_CID::ManufacturerID, SD_CSD::MaxBusClkFrec, SD_CSD::MaxRdCurrentVDDMax, SD_CSD::MaxRdCurrentVDDMin, SD_CSD::MaxWrBlockLen, SD_CSD::MaxWrCurrentVDDMax, SD_CSD::MaxWrCurrentVDDMin, SD_CSD::NSAC, SD_CID::OEM_AppliID, SD_CSD::PartBlockRead, SD_CSD::PermWrProtect, SD_CID::ProdName1, SD_CID::ProdName2, SD_CID::ProdRev, SD_CID::ProdSN, RCA, SD_CardInfo::RCA, SD_CSD::RdBlockLen, SD_CSD::RdBlockMisalign, SD_CID::Reserved1, SD_CSD::Reserved1, SD_CID::Reserved2, SD_CSD::Reserved2, SD_CSD::Reserved3, SD_CSD::Reserved4, SD_CardInfo::SD_cid, SD_CardInfo::SD_csd, SD_GetCIDRegister(), SD_GetCSDRegister(), SD_OK, SD_RESPONSE_FAILURE, SDIO_HIGH_CAPACITY_SD_CARD, SDIO_STD_CAPACITY_SD_CARD_V1_1, SDIO_STD_CAPACITY_SD_CARD_V2_0, status, SD_CSD::SysSpecVersion, SD_CSD::TAAC, SD_CSD::TempWrProtect, SD_CSD::WrBlockMisalign, SD_CSD::WriteBlockPaPartial, SD_CSD::WrProtectGrEnable, SD_CSD::WrProtectGrSize, and SD_CSD::WrSpeedFact.

Referenced by SD_Init().

SD_Error SD_GetCIDRegister ( SD_CID SD_cid  ) 

Read the CID card register.

Reading the contents of the CID register in SPI mode is a simple read-block transaction.

Parameters:
SD_cid,: pointer on an CID register structure
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< SD chip select low

< Send CMD10 (CID register)

< Wait for response in the R1 format (0x00 is no errors)

< Store CID register value on CID_Tab

< Set response value to success

< Send dummy byte: 8 Clock pulses of delay

< Byte 0

< Byte 1

< Byte 2

< Byte 3

< Byte 4

< Byte 5

< Byte 6

< Byte 7

< Byte 8

< Byte 9

< Byte 10

< Byte 11

< Byte 12

< Byte 13

< Byte 14

< Byte 15

< Return the reponse

Definition at line 554 of file stm32_eval_spi_sd.c.

References SD_CID::CID_CRC, CID_Tab, SD_CID::ManufactDate, SD_CID::ManufacturerID, SD_CID::OEM_AppliID, SD_CID::ProdName1, SD_CID::ProdName2, SD_CID::ProdRev, SD_CID::ProdSN, SD_CID::Reserved1, SD_CID::Reserved2, SD_CMD_SEND_CID, SD_CS_HIGH, SD_CS_LOW, SD_DUMMY_BYTE, SD_GetResponse(), SD_ReadByte(), SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_SendCmd(), SD_START_DATA_SINGLE_BLOCK_READ, and SD_WriteByte().

Referenced by SD_GetCardInfo().

SD_Error SD_GetCSDRegister ( SD_CSD SD_csd  ) 

Read the CSD card register.

Reading the contents of the CSD register in SPI mode is a simple read-block transaction.

Parameters:
SD_csd,: pointer on an SCD register structure
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< SD chip select low

< Send CMD9 (CSD register) or CMD10(CSD register)

< Wait for response in the R1 format (0x00 is no errors)

< Store CSD register value on CSD_Tab

< Set response value to success

< Send dummy byte: 8 Clock pulses of delay

< Byte 0

< Byte 1

< Byte 2

< Byte 3

< Byte 4

< Byte 5

< Byte 6

< Reserved

< Byte 7

< Byte 8

< Byte 9

< Byte 10

< Byte 11

< Byte 12

< Byte 13

< Byte 14

< Byte 15

< Return the reponse

Definition at line 432 of file stm32_eval_spi_sd.c.

References SD_CSD::CardComdClasses, SD_CSD::ContentProtectAppli, SD_CSD::CopyFlag, SD_CSD::CSD_CRC, CSD_Tab, SD_CSD::CSDStruct, SD_CSD::DeviceSize, SD_CSD::DeviceSizeMul, SD_CSD::DSRImpl, SD_CSD::ECC, SD_CSD::EraseGrMul, SD_CSD::EraseGrSize, SD_CSD::FileFormat, SD_CSD::FileFormatGrouop, SD_CSD::ManDeflECC, SD_CSD::MaxBusClkFrec, SD_CSD::MaxRdCurrentVDDMax, SD_CSD::MaxRdCurrentVDDMin, SD_CSD::MaxWrBlockLen, SD_CSD::MaxWrCurrentVDDMax, SD_CSD::MaxWrCurrentVDDMin, SD_CSD::NSAC, SD_CSD::PartBlockRead, SD_CSD::PermWrProtect, SD_CSD::RdBlockLen, SD_CSD::RdBlockMisalign, SD_CSD::Reserved1, SD_CSD::Reserved2, SD_CSD::Reserved3, SD_CSD::Reserved4, SD_CMD_SEND_CSD, SD_CS_HIGH, SD_CS_LOW, SD_DUMMY_BYTE, SD_GetResponse(), SD_ReadByte(), SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_SendCmd(), SD_START_DATA_SINGLE_BLOCK_READ, SD_WriteByte(), SD_CSD::SysSpecVersion, SD_CSD::TAAC, SD_CSD::TempWrProtect, SD_CSD::WrBlockMisalign, SD_CSD::WriteBlockPaPartial, SD_CSD::WrProtectGrEnable, SD_CSD::WrProtectGrSize, and SD_CSD::WrSpeedFact.

Referenced by SD_GetCardInfo().

uint8_t SD_GetDataResponse ( void   ) 

Get SD card data response.

Parameters:
None 
Return values:
The SD status: Read data response xxx0<status>1

  • status 010: Data accecpted
  • status 101: Data rejected due to a crc error
  • status 110: Data rejected due to a Write error.
  • status 111: Data rejected due to other error.

< Read resonse

< Mask unused bits

< Increment loop counter

< Return response

Definition at line 682 of file stm32_eval_spi_sd.c.

References SD_DATA_CRC_ERROR, SD_DATA_OK, SD_DATA_OTHER_ERROR, SD_DATA_WRITE_ERROR, and SD_ReadByte().

Referenced by SD_WriteBlock(), and SD_WriteMultiBlocks().

SD_Error SD_GetResponse ( uint8_t  Response  ) 

Returns the SD response.

Parameters:
None 
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< Check if response is got or a timeout is happen

< After time out

< Right response got

Definition at line 731 of file stm32_eval_spi_sd.c.

References SD_ReadByte(), SD_RESPONSE_FAILURE, and SD_RESPONSE_NO_ERROR.

Referenced by SD_GetCIDRegister(), SD_GetCSDRegister(), SD_GoIdleState(), SD_ReadBlock(), SD_ReadMultiBlocks(), SD_WriteBlock(), and SD_WriteMultiBlocks().

uint16_t SD_GetStatus ( void   ) 

Gets the cuurent sd card data transfer status.

Parameters:
None 
Return values:
SDTransferState,: Data Transfer state. This value can be:

  • SD_TRANSFER_OK: No data transfer is acting
  • SD_TRANSFER_BUSY: Data transfer is acting

Gets the cuurent sd card data transfer status.

Parameters:
None 
Return values:
The SD status.

< SD chip select low

< Send CMD13 (SD_SEND_STATUS) to get SD status

< SD chip select high

< Send dummy byte 0xFF

Definition at line 291 of file stm32_eval_sdio_sd.c.

References SD_CARD_ERROR, SD_CARD_TRANSFER, SD_CMD_SEND_STATUS, SD_CS_HIGH, SD_CS_LOW, SD_DUMMY_BYTE, SD_GetState(), SD_ReadByte(), SD_SendCmd(), SD_TRANSFER_BUSY, SD_TRANSFER_ERROR, SD_TRANSFER_OK, SD_WriteByte(), and Status.

SD_Error SD_GoIdleState ( void   ) 

Put SD in Idle state.

Parameters:
None 
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< SD chip select low

< Send CMD0 (SD_CMD_GO_IDLE_STATE) to put SD in SPI mode

< Wait for In Idle State Response (R1 Format) equal to 0x01

< No Idle State Response: return response failue

< SD chip select high

< Send Dummy byte 0xFF

< SD chip select low

< Send CMD1 (Activates the card process) until response equal to 0x0

< Wait for no error Response (R1 Format) equal to 0x00

< SD chip select high

< Send dummy byte 0xFF

Definition at line 786 of file stm32_eval_spi_sd.c.

References SD_CMD_GO_IDLE_STATE, SD_CMD_SEND_OP_COND, SD_CS_HIGH, SD_CS_LOW, SD_DUMMY_BYTE, SD_GetResponse(), SD_IN_IDLE_STATE, SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_SendCmd(), and SD_WriteByte().

Referenced by SD_Init().

SD_Error SD_Init ( void   ) 

Initializes the SD Card and put it into StandBy State (Ready for data transfer).

Parameters:
None 
Return values:
SD_Error,: SD Card Error code.

Initializes the SD Card and put it into StandBy State (Ready for data transfer).

Parameters:
None 
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< CMD Response TimeOut (wait for CMDSENT flag)

< CMD Response TimeOut (wait for CMDSENT flag)

< SDIOCLK = HCLK, SDIO_CK = HCLK/(2 + SDIO_TRANSFER_CLK_DIV)

< Initialize SD_SPI

< SD chip select high

< Send dummy byte 0xFF, 10 times with CS high

< Rise CS and MOSI for 80 clocks cycles

< Send dummy byte 0xFF

< SD initialized and set to SPI mode properly

Definition at line 222 of file stm32_eval_sdio_sd.c.

References SD_CardInfo::RCA, SD_CS_HIGH, SD_DMA_MODE, SD_DUMMY_BYTE, SD_EnableWideBusOperation(), SD_GetCardInfo(), SD_GoIdleState(), SD_InitializeCards(), SD_LowLevel_Init(), SD_OK, SD_PowerON(), SD_SelectDeselect(), SD_SetDeviceMode(), SD_WriteByte(), SDIO_InitTypeDef::SDIO_BusWide, SDIO_BusWide_1b, SDIO_BusWide_4b, SDIO_InitTypeDef::SDIO_ClockBypass, SDIO_ClockBypass_Disable, SDIO_InitTypeDef::SDIO_ClockDiv, SDIO_InitTypeDef::SDIO_ClockEdge, SDIO_ClockEdge_Rising, SDIO_InitTypeDef::SDIO_ClockPowerSave, SDIO_ClockPowerSave_Disable, SDIO_DeInit(), SDIO_InitTypeDef::SDIO_HardwareFlowControl, SDIO_HardwareFlowControl_Disable, SDIO_Init(), and SDIO_TRANSFER_CLK_DIV.

Referenced by main().

SD_Error SD_ReadBlock ( uint8_t *  pBuffer,
uint32_t  ReadAddr,
uint16_t  BlockSize 
)

Allows to read one block from a specified address in a card.

Parameters:
readbuff,: pointer to the buffer that will contain the received data
ReadAddr,: Address from where data are to be read.
BlockSize,: the SD card Data block size.
Return values:
SD_Error,: SD Card Error code.

Allows to read one block from a specified address in a card.

Parameters:
pBuffer,: pointer to the buffer that receives the data read from the SD.
ReadAddr,: SD's internal address to read from.
BlockSize,: the SD card Data block size.
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< Clear all DPSM configuration

< Set Block Size for Card

< Send CMD17 READ_SINGLE_BLOCK

< Polling mode

< SD chip select low

< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block

< Check if the SD acknowledged the read block command: R1 response (0x00: no errors)

< Now look for the data token to signify the start of the data

< Read the SD block data : read NumByteToRead data

< Save the received data

< Point to the next location where the byte read will be saved

< Set response value to success

< Send dummy byte: 8 Clock pulses of delay

< Returns the reponse

Definition at line 928 of file stm32_eval_sdio_sd.c.

References CardType, CmdResp1Error(), convert_from_bytes_to_power_of_two(), DestBuffer, DeviceMode, DISABLE, ENABLE, NULL, RESET, SD_CARD_LOCKED, SD_CMD_READ_SINGLE_BLOCK, SD_CMD_SET_BLOCKLEN, SD_CS_HIGH, SD_CS_LOW, SD_DATA_CRC_FAIL, SD_DATA_TIMEOUT, SD_DATATIMEOUT, SD_DMA_MODE, SD_DMAEndOfTransferStatus(), SD_DUMMY_BYTE, SD_GetResponse(), SD_INTERRUPT_MODE, SD_INVALID_PARAMETER, SD_LOCK_UNLOCK_FAILED, SD_LowLevel_DMA_RxConfig(), SD_OK, SD_POLLING_MODE, SD_ReadByte(), SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_RX_OVERRUN, SD_SendCmd(), SD_START_BIT_ERR, SD_START_DATA_SINGLE_BLOCK_READ, SD_WriteByte(), SDIO, SDIO_CmdInitTypeDef::SDIO_Argument, SDIO_ClearFlag(), SDIO_CmdInitTypeDef::SDIO_CmdIndex, SDIO_CmdInitTypeDef::SDIO_CPSM, SDIO_CPSM_Enable, SDIO_DataInitTypeDef::SDIO_DataBlockSize, SDIO_DataBlockSize_1b, SDIO_DataConfig(), SDIO_DataInitTypeDef::SDIO_DataLength, SDIO_DataInitTypeDef::SDIO_DataTimeOut, SDIO_DMACmd(), SDIO_DataInitTypeDef::SDIO_DPSM, SDIO_DPSM_Disable, SDIO_DPSM_Enable, SDIO_FLAG_DBCKEND, SDIO_FLAG_DCRCFAIL, SDIO_FLAG_DTIMEOUT, SDIO_FLAG_RXDAVL, SDIO_FLAG_RXFIFOHF, SDIO_FLAG_RXOVERR, SDIO_FLAG_STBITERR, SDIO_GetFlagStatus(), SDIO_GetResponse(), SDIO_HIGH_CAPACITY_SD_CARD, SDIO_IT_DATAEND, SDIO_IT_DCRCFAIL, SDIO_IT_DTIMEOUT, SDIO_IT_RXFIFOHF, SDIO_IT_RXOVERR, SDIO_IT_STBITERR, SDIO_ITConfig(), SDIO_ReadData(), SDIO_RESP1, SDIO_CmdInitTypeDef::SDIO_Response, SDIO_Response_Short, SDIO_SendCommand(), SDIO_STATIC_FLAGS, SDIO_DataInitTypeDef::SDIO_TransferDir, SDIO_TransferDir_ToCard, SDIO_TransferDir_ToSDIO, SDIO_DataInitTypeDef::SDIO_TransferMode, SDIO_TransferMode_Block, SDIO_CmdInitTypeDef::SDIO_Wait, SDIO_Wait_No, StopCondition, TotalNumberOfBytes, TransferEnd, and TransferError.

Referenced by main().

uint8_t SD_ReadByte ( void   ) 

Read a byte from the SD.

Parameters:
None 
Return values:
The received byte.

< Wait until the transmit buffer is empty

< Wait until a data is received

< Return the shifted data

Definition at line 856 of file stm32_eval_spi_sd.c.

References Data, RESET, SD_DUMMY_BYTE, SD_SPI, SPI_I2S_FLAG_RXNE, SPI_I2S_FLAG_TXE, SPI_I2S_GetFlagStatus(), SPI_I2S_ReceiveData(), and SPI_I2S_SendData().

Referenced by SD_GetCIDRegister(), SD_GetCSDRegister(), SD_GetDataResponse(), SD_GetResponse(), SD_GetStatus(), SD_ReadBlock(), SD_ReadMultiBlocks(), SD_WriteBlock(), and SD_WriteMultiBlocks().

SD_Error SD_ReadMultiBlocks ( uint8_t *  pBuffer,
uint32_t  ReadAddr,
uint16_t  BlockSize,
uint32_t  NumberOfBlocks 
)

Allows to read blocks from a specified address in a card.

Parameters:
readbuff,: pointer to the buffer that will contain the received data.
ReadAddr,: Address from where data are to be read.
BlockSize,: the SD card Data block size.
NumberOfBlocks,: number of blocks to be read.
Return values:
SD_Error,: SD Card Error code.

Allows to read blocks from a specified address in a card.

Parameters:
pBuffer,: pointer to the buffer that receives the data read from the SD.
ReadAddr,: SD's internal address to read from.
BlockSize,: the SD card Data block size.
NumberOfBlocks,: number of blocks to be read.
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< Clear all DPSM configuration

< Set Block Size for Card

< Common to all modes

< Send CMD18 READ_MULT_BLOCK with argument data address

< Polling mode

< In Case Of SD-CARD Send Command STOP_TRANSMISSION

< Send CMD12 STOP_TRANSMISSION

< SD chip select low

< Data transfer

< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block

< Check if the SD acknowledged the read block command: R1 response (0x00: no errors)

< Read the SD block data : read NumByteToRead data

< Read the pointed data

< Point to the next location where the byte read will be saved

< get CRC bytes (not really needed by us, but required by SD)

< Set response value to success

< Set response value to failure

< Send dummy byte: 8 Clock pulses of delay

< Returns the reponse

Definition at line 1098 of file stm32_eval_sdio_sd.c.

References CardType, CmdResp1Error(), convert_from_bytes_to_power_of_two(), DestBuffer, DeviceMode, DISABLE, ENABLE, NULL, RESET, SD_CARD_LOCKED, SD_CMD_READ_MULT_BLOCK, SD_CMD_READ_SINGLE_BLOCK, SD_CMD_SET_BLOCKLEN, SD_CMD_STOP_TRANSMISSION, SD_CS_HIGH, SD_CS_LOW, SD_DATA_CRC_FAIL, SD_DATA_TIMEOUT, SD_DATATIMEOUT, SD_DMA_MODE, SD_DMAEndOfTransferStatus(), SD_DUMMY_BYTE, SD_GetResponse(), SD_HALFFIFO, SD_INTERRUPT_MODE, SD_INVALID_PARAMETER, SD_LOCK_UNLOCK_FAILED, SD_LowLevel_DMA_RxConfig(), SD_MAX_DATA_LENGTH, SD_OK, SD_POLLING_MODE, SD_ReadByte(), SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_RX_OVERRUN, SD_SendCmd(), SD_START_BIT_ERR, SD_START_DATA_SINGLE_BLOCK_READ, SD_WriteByte(), SDIO, SDIO_CmdInitTypeDef::SDIO_Argument, SDIO_ClearFlag(), SDIO_CmdInitTypeDef::SDIO_CmdIndex, SDIO_CmdInitTypeDef::SDIO_CPSM, SDIO_CPSM_Enable, SDIO_DataInitTypeDef::SDIO_DataBlockSize, SDIO_DataBlockSize_1b, SDIO_DataConfig(), SDIO_DataInitTypeDef::SDIO_DataLength, SDIO_DataInitTypeDef::SDIO_DataTimeOut, SDIO_DMACmd(), SDIO_DataInitTypeDef::SDIO_DPSM, SDIO_DPSM_Disable, SDIO_DPSM_Enable, SDIO_FLAG_DATAEND, SDIO_FLAG_DCRCFAIL, SDIO_FLAG_DTIMEOUT, SDIO_FLAG_RXDAVL, SDIO_FLAG_RXFIFOHF, SDIO_FLAG_RXOVERR, SDIO_FLAG_STBITERR, SDIO_GetFlagStatus(), SDIO_GetResponse(), SDIO_HIGH_CAPACITY_SD_CARD, SDIO_IT_DATAEND, SDIO_IT_DCRCFAIL, SDIO_IT_DTIMEOUT, SDIO_IT_RXFIFOHF, SDIO_IT_RXOVERR, SDIO_IT_STBITERR, SDIO_ITConfig(), SDIO_ReadData(), SDIO_RESP1, SDIO_CmdInitTypeDef::SDIO_Response, SDIO_Response_Short, SDIO_SendCommand(), SDIO_STATIC_FLAGS, SDIO_STD_CAPACITY_SD_CARD_V1_1, SDIO_STD_CAPACITY_SD_CARD_V2_0, SDIO_DataInitTypeDef::SDIO_TransferDir, SDIO_TransferDir_ToCard, SDIO_TransferDir_ToSDIO, SDIO_DataInitTypeDef::SDIO_TransferMode, SDIO_TransferMode_Block, SDIO_CmdInitTypeDef::SDIO_Wait, SDIO_Wait_No, StopCondition, TotalNumberOfBytes, TransferEnd, and TransferError.

Referenced by main().

void SD_SendCmd ( uint8_t  Cmd,
uint32_t  Arg,
uint8_t  Crc 
)

Send 5 bytes command to the SD card.

Parameters:
Cmd,: The user expected command to send to SD card.
Arg,: The command argument.
Crc,: The CRC.
Return values:
None 

< Construct byte 1

< Construct byte 2

< Construct byte 3

< Construct byte 4

< Construct byte 5

< Construct CRC: byte 6

< Send the Cmd bytes

Definition at line 649 of file stm32_eval_spi_sd.c.

References SD_WriteByte().

Referenced by SD_GetCIDRegister(), SD_GetCSDRegister(), SD_GetStatus(), SD_GoIdleState(), SD_ReadBlock(), SD_ReadMultiBlocks(), SD_WriteBlock(), and SD_WriteMultiBlocks().

SD_Error SD_WriteBlock ( uint8_t *  pBuffer,
uint32_t  WriteAddr,
uint16_t  BlockSize 
)

Allows to write one block starting from a specified address in a card.

Parameters:
writebuff,: pointer to the buffer that contain the data to be transferred.
WriteAddr,: Address from where data are to be read.
BlockSize,: the SD card Data block size.
Return values:
SD_Error,: SD Card Error code.

Allows to write one block starting from a specified address in a card.

Parameters:
pBuffer,: pointer to the buffer containing the data to be written on the SD.
WriteAddr,: address to write on.
BlockSize,: the SD card Data block size.
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< In case of single data block transfer no need of stop command at all

< Wait till the card is in programming state

< SD chip select low

< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write multiple block

< Check if the SD acknowledged the write block command: R1 response (0x00: no errors)

< Send a dummy byte

< Send the data token to signify the start of the data

< Write the block data to SD : write count data by block

< Send the pointed byte

< Point to the next location where the byte read will be saved

< Read data response

< Send dummy byte: 8 Clock pulses of delay

< Returns the reponse

Definition at line 1299 of file stm32_eval_sdio_sd.c.

References CardType, CmdResp1Error(), convert_from_bytes_to_power_of_two(), DeviceMode, DISABLE, ENABLE, IsCardProgramming(), NULL, RCA, RESET, SD_CARD_LOCKED, SD_CARD_PROGRAMMING, SD_CARD_RECEIVING, SD_CMD_SEND_STATUS, SD_CMD_SET_BLOCKLEN, SD_CMD_WRITE_SINGLE_BLOCK, SD_CS_HIGH, SD_CS_LOW, SD_DATA_CRC_FAIL, SD_DATA_OK, SD_DATA_TIMEOUT, SD_DATATIMEOUT, SD_DMA_MODE, SD_DMAEndOfTransferStatus(), SD_DUMMY_BYTE, SD_ERROR, SD_GetDataResponse(), SD_GetResponse(), SD_INTERRUPT_MODE, SD_INVALID_PARAMETER, SD_LOCK_UNLOCK_FAILED, SD_LowLevel_DMA_TxConfig(), SD_OK, SD_POLLING_MODE, SD_ReadByte(), SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_SendCmd(), SD_START_BIT_ERR, SD_TX_UNDERRUN, SD_WriteByte(), SDIO, SDIO_CmdInitTypeDef::SDIO_Argument, SDIO_ClearFlag(), SDIO_CmdInitTypeDef::SDIO_CmdIndex, SDIO_CmdInitTypeDef::SDIO_CPSM, SDIO_CPSM_Enable, SDIO_DataInitTypeDef::SDIO_DataBlockSize, SDIO_DataBlockSize_1b, SDIO_DataConfig(), SDIO_DataInitTypeDef::SDIO_DataLength, SDIO_DataInitTypeDef::SDIO_DataTimeOut, SDIO_DMACmd(), SDIO_DataInitTypeDef::SDIO_DPSM, SDIO_DPSM_Disable, SDIO_DPSM_Enable, SDIO_FLAG_DBCKEND, SDIO_FLAG_DCRCFAIL, SDIO_FLAG_DTIMEOUT, SDIO_FLAG_STBITERR, SDIO_FLAG_TXFIFOHE, SDIO_FLAG_TXUNDERR, SDIO_GetFlagStatus(), SDIO_GetResponse(), SDIO_HIGH_CAPACITY_SD_CARD, SDIO_IT_DATAEND, SDIO_IT_DCRCFAIL, SDIO_IT_DTIMEOUT, SDIO_IT_STBITERR, SDIO_IT_TXUNDERR, SDIO_ITConfig(), SDIO_RESP1, SDIO_CmdInitTypeDef::SDIO_Response, SDIO_Response_Short, SDIO_SendCommand(), SDIO_STATIC_FLAGS, SDIO_DataInitTypeDef::SDIO_TransferDir, SDIO_TransferDir_ToCard, SDIO_DataInitTypeDef::SDIO_TransferMode, SDIO_TransferMode_Block, SDIO_CmdInitTypeDef::SDIO_Wait, SDIO_Wait_No, SDIO_WriteData(), SrcBuffer, StopCondition, TotalNumberOfBytes, TransferEnd, and TransferError.

Referenced by main().

uint8_t SD_WriteByte ( uint8_t  Data  ) 

Write a byte on the SD.

Parameters:
Data,: byte to send.
Return values:
None 

< Wait until the transmit buffer is empty

< Wait to receive a byte

Definition at line 832 of file stm32_eval_spi_sd.c.

References RESET, SD_SPI, SPI_I2S_FLAG_RXNE, SPI_I2S_FLAG_TXE, SPI_I2S_GetFlagStatus(), SPI_I2S_ReceiveData(), and SPI_I2S_SendData().

Referenced by SD_GetCIDRegister(), SD_GetCSDRegister(), SD_GetStatus(), SD_GoIdleState(), SD_Init(), SD_ReadBlock(), SD_ReadMultiBlocks(), SD_SendCmd(), SD_WriteBlock(), and SD_WriteMultiBlocks().

SD_Error SD_WriteMultiBlocks ( uint8_t *  pBuffer,
uint32_t  WriteAddr,
uint16_t  BlockSize,
uint32_t  NumberOfBlocks 
)

Allows to write blocks starting from a specified address in a card.

Parameters:
WriteAddr,: Address from where data are to be read.
writebuff,: pointer to the buffer that contain the data to be transferred.
BlockSize,: the SD card Data block size.
NumberOfBlocks,: number of blocks to be written.
Return values:
SD_Error,: SD Card Error code.

Allows to write blocks starting from a specified address in a card.

Parameters:
pBuffer,: pointer to the buffer containing the data to be written on the SD.
WriteAddr,: address to write on.
BlockSize,: the SD card Data block size.
NumberOfBlocks,: number of blocks to be written.
Return values:
The SD Response:

  • SD_RESPONSE_FAILURE: Sequence failed
  • SD_RESPONSE_NO_ERROR: Sequence succeed

< Common to all modes

< To improve performance

< Send CMD12 STOP_TRANSMISSION

< Add some delay before checking the Card Status

< SD chip select low

< Data transfer

< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write blocks

< Check if the SD acknowledged the write block command: R1 response (0x00: no errors)

< Send the data token to signify the start of the data

< Write the block data to SD : write count data by block

< Send the pointed byte

< Point to the next location where the byte read will be saved

< Put CRC bytes (not really needed by us, but required by SD)

< Read data response

< Set response value to success

< Set response value to failure

< Send dummy byte: 8 Clock pulses of delay

< Returns the reponse

Definition at line 1530 of file stm32_eval_sdio_sd.c.

References CardType, CmdResp1Error(), convert_from_bytes_to_power_of_two(), DeviceMode, DISABLE, ENABLE, IsCardProgramming(), NULL, RCA, RESET, SD_CARD_LOCKED, SD_CARD_PROGRAMMING, SD_CARD_RECEIVING, SD_CMD_APP_CMD, SD_CMD_SEND_STATUS, SD_CMD_SET_BLOCK_COUNT, SD_CMD_SET_BLOCKLEN, SD_CMD_STOP_TRANSMISSION, SD_CMD_WRITE_MULT_BLOCK, SD_CMD_WRITE_SINGLE_BLOCK, SD_CS_HIGH, SD_CS_LOW, SD_DATA_CRC_FAIL, SD_DATA_OK, SD_DATA_TIMEOUT, SD_DATATIMEOUT, SD_DMA_MODE, SD_DMAEndOfTransferStatus(), SD_DUMMY_BYTE, SD_GetDataResponse(), SD_GetResponse(), SD_HALFFIFO, SD_HALFFIFOBYTES, SD_INTERRUPT_MODE, SD_INVALID_PARAMETER, SD_LOCK_UNLOCK_FAILED, SD_LowLevel_DMA_TxConfig(), SD_MAX_DATA_LENGTH, SD_OK, SD_POLLING_MODE, SD_ReadByte(), SD_RESPONSE_FAILURE, SD_RESPONSE_NO_ERROR, SD_SendCmd(), SD_START_BIT_ERR, SD_START_DATA_SINGLE_BLOCK_WRITE, SD_TX_UNDERRUN, SD_WriteByte(), SDIO, SDIO_CmdInitTypeDef::SDIO_Argument, SDIO_ClearFlag(), SDIO_CmdInitTypeDef::SDIO_CmdIndex, SDIO_CmdInitTypeDef::SDIO_CPSM, SDIO_CPSM_Enable, SDIO_DataInitTypeDef::SDIO_DataBlockSize, SDIO_DataBlockSize_1b, SDIO_DataConfig(), SDIO_DataInitTypeDef::SDIO_DataLength, SDIO_DataInitTypeDef::SDIO_DataTimeOut, SDIO_DMACmd(), SDIO_DataInitTypeDef::SDIO_DPSM, SDIO_DPSM_Disable, SDIO_DPSM_Enable, SDIO_FLAG_DATAEND, SDIO_FLAG_DCRCFAIL, SDIO_FLAG_DTIMEOUT, SDIO_FLAG_STBITERR, SDIO_FLAG_TXFIFOHE, SDIO_FLAG_TXUNDERR, SDIO_GetFlagStatus(), SDIO_GetResponse(), SDIO_HIGH_CAPACITY_SD_CARD, SDIO_IT_DATAEND, SDIO_IT_DCRCFAIL, SDIO_IT_DTIMEOUT, SDIO_IT_STBITERR, SDIO_IT_TXFIFOHE, SDIO_IT_TXUNDERR, SDIO_ITConfig(), SDIO_RESP1, SDIO_CmdInitTypeDef::SDIO_Response, SDIO_Response_Short, SDIO_SendCommand(), SDIO_STATIC_FLAGS, SDIO_STD_CAPACITY_SD_CARD_V1_1, SDIO_STD_CAPACITY_SD_CARD_V2_0, SDIO_DataInitTypeDef::SDIO_TransferDir, SDIO_TransferDir_ToCard, SDIO_DataInitTypeDef::SDIO_TransferMode, SDIO_TransferMode_Block, SDIO_CmdInitTypeDef::SDIO_Wait, SDIO_Wait_No, SDIO_WriteData(), SrcBuffer, StopCondition, TotalNumberOfBytes, TransferEnd, and TransferError.

Referenced by main().

STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32