MG32F157 Standard Peripherals Firmware Library
|
This file provides all the RCC firmware functions. More...
#include "bsp_sdio_sdcard.h"
#include "mg32f157.h"
Macros | |
#define | NULL 0 |
SDIO Static flags, TimeOut, FIFO Address. | |
#define | SDIO_CMD0TIMEOUT ((uint32_t)0x00010000) |
#define | SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000) |
Mask for errors Card Status R1 (OCR Register) | |
#define | SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000) |
#define | SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000) |
#define | SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000) |
#define | SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000) |
#define | SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000) |
#define | SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000) |
#define | SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000) |
#define | SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000) |
#define | SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000) |
#define | SD_OCR_CC_ERROR ((uint32_t)0x00100000) |
#define | SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000) |
#define | SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000) |
#define | SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000) |
#define | SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000) |
#define | SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000) |
#define | SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000) |
#define | SD_OCR_ERASE_RESET ((uint32_t)0x00002000) |
#define | SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008) |
#define | SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008) |
#define | SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000) |
Masks for R6 Response. | |
#define | SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000) |
#define | SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000) |
#define | SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000) |
#define | SD_HIGH_CAPACITY ((uint32_t)0x40000000) |
#define | SD_STD_CAPACITY ((uint32_t)0x00000000) |
#define | SD_CHECK_PATTERN ((uint32_t)0x000001AA) |
#define | SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF) |
#define | SD_ALLZERO ((uint32_t)0x00000000) |
#define | SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000) |
#define | SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000) |
#define | SD_CARD_LOCKED ((uint32_t)0x02000000) |
#define | SD_DATATIMEOUT ((uint32_t)0xFFFFFFFF) |
#define | SD_0TO7BITS ((uint32_t)0x000000FF) |
#define | SD_8TO15BITS ((uint32_t)0x0000FF00) |
#define | SD_16TO23BITS ((uint32_t)0x00FF0000) |
#define | SD_24TO31BITS ((uint32_t)0xFF000000) |
#define | SD_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFF) |
#define | SD_HALFFIFO ((uint32_t)0x00000008) |
#define | SD_HALFFIFOBYTES ((uint32_t)0x00000020) |
#define | SD_CCCC_LOCK_UNLOCK ((uint32_t)0x00000080) |
Command Class Supported. | |
#define | SD_CCCC_WRITE_PROT ((uint32_t)0x00000040) |
#define | SD_CCCC_ERASE ((uint32_t)0x00000020) |
#define | SDIO_SEND_IF_COND ((uint32_t)0x00000008) |
Following commands are SD Card Specific commands. SDIO_APP_CMD should be sent before sending these commands. | |
Functions | |
void | SD_DeInit (void) |
SD_Error | SD_Init (void) |
Initializes the SD according to the specified parameters in the SD_HandleTypeDef and create the associated handle. More... | |
SDCardState | SD_GetState (void) |
Returns the current card's state. More... | |
SDTransferState | SD_GetStatus (void) |
Gets the cuurent sd card data transfer status. More... | |
SD_Error | SD_PowerON (void) |
Enquires cards about their operating voltage and configures clock controls and stores SD information that will be needed in future in the SD handle. More... | |
SD_Error | SD_PowerOFF (void) |
Disable the SDIO card clock output. More... | |
SD_Error | SD_InitializeCards (void) |
Initializes the SD Card. More... | |
SD_Error | SD_GetCardInfo (SD_CardInfo *cardinfo) |
SD_Error | SD_GetCardStatus (SD_CardStatus *cardstatus) |
Enables wide bus opeartion for the requeseted card if supported by card. More... | |
SD_Error | SD_EnableWideBusOperation (uint32_t WideMode) |
SD_Error | SD_SelectDeselect (uint32_t Addr) |
Send the Select Deselect command and check the response. More... | |
SD_Error | SD_ReadBlock (uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize) |
Allows to read one block from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode. More... | |
SD_Error | SD_ReadMultiBlocks (uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks) |
Allows to read blocks from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode. More... | |
SD_Error | SD_WriteBlock (uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize) |
Allows to write one block starting from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode. More... | |
SD_Error | SD_WriteMultiBlocks (uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks) |
SD_Error | SD_StopTransfer (void) |
Aborts an ongoing data transfer. More... | |
SD_Error | SD_Erase (uint32_t startaddr, uint32_t endaddr) |
Allows to erase memory area specified for the given card. More... | |
SD_Error | SD_SendSDStatus (uint32_t *psdstatus) |
Returns the current SD card's status. More... | |
Variables | |
__IO uint32_t | StopCondition = 0 |
__IO uint32_t | TransferEnd = 0 |
__IO SD_Error | TransferError = SD_OK |
SD_CardInfo | SDCardInfo |
SDIO_InitTypeDef | SDIO_InitStructure |
SDIO_CmdInitTypeDef | SDIO_CmdInitStructure |
SDIO_DataInitTypeDef | SDIO_DataInitStructure |
This file provides all the RCC firmware functions.
void SD_DeInit | ( | void | ) |
< Disable SDIO Clock
< Set Power State to OFF
< Disable the SDIO AHB Clock
< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin
< Configure PD.02 CMD line
SD_Error SD_EnableWideBusOperation | ( | uint32_t | WideMode | ) |
< MMC Card doesn't support this feature
SD_Error SD_Erase | ( | uint32_t | startaddr, |
uint32_t | endaddr | ||
) |
Allows to erase memory area specified for the given card.
startaddr | the start address. |
endaddr | the end address. |
SD_Error | SD Card Error code. |
< Check if the card coomnd class supports erase command
< Send CMD32 SD_ERASE_GRP_START with argument as addr
SD_Error SD_GetCardInfo | ( | SD_CardInfo * | cardinfo | ) |
< 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
SD_Error SD_GetCardStatus | ( | SD_CardStatus * | cardstatus | ) |
Enables wide bus opeartion for the requeseted card if supported by card.
WideMode | Specifies the SD card wide bus mode. This parameter can be one of the following values:
|
SD_Error | SD Card Error code. |
< Byte 0
< 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 13
SDCardState SD_GetState | ( | void | ) |
Returns the current card's state.
None |
SDCardState | SD Card Error or SD Card Current State. |
SDTransferState SD_GetStatus | ( | void | ) |
Gets the cuurent sd card data transfer status.
None |
SDTransferState | Data Transfer state. This value can be:
|
SD_Error SD_Init | ( | void | ) |
Initializes the SD according to the specified parameters in the SD_HandleTypeDef and create the associated handle.
None |
HAL | status |
< Enable the SDIO AHB Clock
< CMD Response TimeOut (wait for CMDSENT flag)
SD_Error SD_InitializeCards | ( | void | ) |
Initializes the SD Card.
None. |
HAL | status |
SD_Error SD_PowerOFF | ( | void | ) |
Disable the SDIO card clock output.
None |
error | state |
SD_Error SD_PowerON | ( | void | ) |
Enquires cards about their operating voltage and configures clock controls and stores SD information that will be needed in future in the SD handle.
None |
error | state |
SD_Error SD_ReadBlock | ( | uint8_t * | readbuff, |
uint64_t | ReadAddr, | ||
uint16_t | BlockSize | ||
) |
Allows to read one block from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode.
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. The Block size should be 512. |
SD_Error | SD Card Error code. |
< Send CMD17 READ_SINGLE_BLOCK
< Polling mode
SD_Error SD_ReadMultiBlocks | ( | uint8_t * | readbuff, |
uint64_t | ReadAddr, | ||
uint16_t | BlockSize, | ||
uint32_t | NumberOfBlocks | ||
) |
Allows to read blocks from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode.
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. The Block size should be 512. |
NumberOfBlocks | number of blocks to be read. |
SD_Error | SD Card Error code. |
< Send CMD18 READ_MULT_BLOCK with argument data address
< Polling mode
SD_Error SD_SelectDeselect | ( | uint32_t | Addr | ) |
Send the Select Deselect command and check the response.
SDIOx | Pointer to SDIO register base |
addr | Address of the card to be selected |
HAL | status |
SD_Error SD_SendSDStatus | ( | uint32_t * | psdstatus | ) |
Returns the current SD card's status.
psdstatus | pointer to the buffer that will contain the SD card status (SD Status register). |
SD_Error | SD Card Error code. |
< Send ACMD13 SD_APP_STAUS with argument as card's RCA.
SD_Error SD_StopTransfer | ( | void | ) |
Aborts an ongoing data transfer.
None |
SD_Error | SD Card Error code. |
SD_Error SD_WriteBlock | ( | uint8_t * | writebuff, |
uint64_t | WriteAddr, | ||
uint16_t | BlockSize | ||
) |
Allows to write one block starting from a specified address in a card. The Data transfer can be managed by DMA mode or Polling mode.
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. The Block size should be 512. |
SD_Error | SD Card Error code. |
SD_Error SD_WriteMultiBlocks | ( | uint8_t * | writebuff, |
uint64_t | WriteAddr, | ||
uint16_t | BlockSize, | ||
uint32_t | NumberOfBlocks | ||
) |
< To improve performance