stm32_eval_sdio_sd.c File Reference

This file provides a set of functions needed to manage the SDIO SD Card memory mounted on STM32xx-EVAL board (refer to stm32_eval.h to know about the boards supporting this memory). It implements a high level communication layer for read and write from/to this memory. The needed STM32 hardware resources (SDIO and GPIO) are defined in stm32xx_eval.h file, and the initialization is performed in SD_LowLevel_Init() function declared in stm32xx_eval.c file. You can easily tailor this driver to any other development board, by just adapting the defines for hardware resources and SD_LowLevel_Init() function. More...

#include "stm32_eval_sdio_sd.h"
#include "stm32_eval.h"

Go to the source code of this file.

Defines

#define NULL   0
 SDIO Static flags, TimeOut, FIFO Address.
#define SD_0TO7BITS   ((uint32_t)0x000000FF)
#define SD_16TO23BITS   ((uint32_t)0x00FF0000)
#define SD_24TO31BITS   ((uint32_t)0xFF000000)
#define SD_8TO15BITS   ((uint32_t)0x0000FF00)
#define SD_ALLZERO   ((uint32_t)0x00000000)
#define SD_CARD_LOCKED   ((uint32_t)0x02000000)
#define SD_CCCC_ERASE   ((uint32_t)0x00000020)
#define SD_CCCC_LOCK_UNLOCK   ((uint32_t)0x00000080)
 Command Class Supported.
#define SD_CCCC_WRITE_PROT   ((uint32_t)0x00000040)
#define SD_CHECK_PATTERN   ((uint32_t)0x000001AA)
#define SD_DATATIMEOUT   ((uint32_t)0x000FFFFF)
#define SD_HALFFIFO   ((uint32_t)0x00000008)
#define SD_HALFFIFOBYTES   ((uint32_t)0x00000020)
#define SD_HIGH_CAPACITY   ((uint32_t)0x40000000)
#define SD_MAX_DATA_LENGTH   ((uint32_t)0x01FFFFFF)
#define SD_MAX_VOLT_TRIAL   ((uint32_t)0x0000FFFF)
#define SD_OCR_ADDR_MISALIGNED   ((uint32_t)0x40000000)
#define SD_OCR_ADDR_OUT_OF_RANGE   ((uint32_t)0x80000000)
 Mask for errors Card Status R1 (OCR Register).
#define SD_OCR_AKE_SEQ_ERROR   ((uint32_t)0x00000008)
#define SD_OCR_BAD_ERASE_PARAM   ((uint32_t)0x08000000)
#define SD_OCR_BLOCK_LEN_ERR   ((uint32_t)0x20000000)
#define SD_OCR_CARD_ECC_DISABLED   ((uint32_t)0x00004000)
#define SD_OCR_CARD_ECC_FAILED   ((uint32_t)0x00200000)
#define SD_OCR_CC_ERROR   ((uint32_t)0x00100000)
#define SD_OCR_CID_CSD_OVERWRIETE   ((uint32_t)0x00010000)
#define SD_OCR_COM_CRC_FAILED   ((uint32_t)0x00800000)
#define SD_OCR_ERASE_RESET   ((uint32_t)0x00002000)
#define SD_OCR_ERASE_SEQ_ERR   ((uint32_t)0x10000000)
#define SD_OCR_ERRORBITS   ((uint32_t)0xFDFFE008)
#define SD_OCR_GENERAL_UNKNOWN_ERROR   ((uint32_t)0x00080000)
#define SD_OCR_ILLEGAL_CMD   ((uint32_t)0x00400000)
#define SD_OCR_LOCK_UNLOCK_FAILED   ((uint32_t)0x01000000)
#define SD_OCR_STREAM_READ_UNDERRUN   ((uint32_t)0x00040000)
#define SD_OCR_STREAM_WRITE_OVERRUN   ((uint32_t)0x00020000)
#define SD_OCR_WP_ERASE_SKIP   ((uint32_t)0x00008000)
#define SD_OCR_WRITE_PROT_VIOLATION   ((uint32_t)0x04000000)
#define SD_R6_COM_CRC_FAILED   ((uint32_t)0x00008000)
#define SD_R6_GENERAL_UNKNOWN_ERROR   ((uint32_t)0x00002000)
 Masks for R6 Response.
#define SD_R6_ILLEGAL_CMD   ((uint32_t)0x00004000)
#define SD_SINGLE_BUS_SUPPORT   ((uint32_t)0x00010000)
#define SD_STD_CAPACITY   ((uint32_t)0x00000000)
#define SD_VOLTAGE_WINDOW_SD   ((uint32_t)0x80100000)
#define SD_WIDE_BUS_SUPPORT   ((uint32_t)0x00040000)
#define SDIO_CMD0TIMEOUT   ((uint32_t)0x00010000)
#define SDIO_SEND_IF_COND   ((uint32_t)0x00000008)
 Following commands are SD Card Specific commands.
#define SDIO_STATIC_FLAGS   ((uint32_t)0x000005FF)

Functions

static SD_Error CmdError (void)
 Checks for error conditions for CMD0.
static SD_Error CmdResp1Error (uint8_t cmd)
 Checks for error conditions for R1 response.
static SD_Error CmdResp2Error (void)
 Checks for error conditions for R2 (CID or CSD) response.
static SD_Error CmdResp3Error (void)
 Checks for error conditions for R3 (OCR) response.
static SD_Error CmdResp6Error (uint8_t cmd, uint16_t *prca)
 Checks for error conditions for R6 (RCA) response.
static SD_Error CmdResp7Error (void)
 Checks for error conditions for R7 response.
static uint8_t convert_from_bytes_to_power_of_two (uint16_t NumberOfBytes)
 Converts the number of bytes in power of two and returns the power.
static SD_Error FindSCR (uint16_t rca, uint32_t *pscr)
 Find the SD card SCR register value.
static SD_Error IsCardProgramming (uint8_t *pstatus)
 Checks if the SD card is in programming state.
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_EnableWideBusOperation (uint32_t WideMode)
 Enables wide bus opeartion for the requeseted card if supported by card.
SD_Error SD_Erase (uint32_t startaddr, uint32_t endaddr)
 Allows to erase memory area specified for the given card.
SD_Error SD_GetCardInfo (SD_CardInfo *cardinfo)
 Returns information about specific card.
SDCardState SD_GetState (void)
 Returns the current card's state.
SDTransferState SD_GetStatus (void)
 Gets the cuurent sd card data transfer status.
SDTransferState SD_GetTransferState (void)
 Gets the cuurent data transfer state.
SD_Error SD_Init (void)
 Initializes the SD Card and put it into StandBy State (Ready for data transfer).
SD_Error SD_InitializeCards (void)
 Intialises all cards or single card as the case may be Card(s) come into standby state.
SD_Error SD_PowerOFF (void)
 Turns the SDIO output signals off.
SD_Error SD_PowerON (void)
 Enquires cards about their operating voltage and configures clock controls.
SD_Error SD_ProcessIRQSrc (void)
 Allows to process all the interrupts that are high.
SD_Error SD_ReadBlock (uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
 Allows to read one block from a specified address in a card.
SD_Error SD_ReadMultiBlocks (uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
 Allows to read blocks from a specified address in a card.
SD_Error SD_SelectDeselect (uint32_t addr)
 Selects od Deselects the corresponding card.
SD_Error SD_SendSDStatus (uint32_t *psdstatus)
 Returns the current SD card's status.
SD_Error SD_SendStatus (uint32_t *pcardstatus)
 Returns the current card's status.
SD_Error SD_SetDeviceMode (uint32_t Mode)
 Sets device mode whether to operate in Polling, Interrupt or DMA mode.
SD_Error SD_StopTransfer (void)
 Aborts an ongoing data transfer.
SD_Error SD_WriteBlock (uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize)
 Allows to write one block starting from a specified address in a card.
SD_Error SD_WriteMultiBlocks (uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
 Allows to write blocks starting from a specified address in a card.
static SD_Error SDEnWideBus (FunctionalState NewState)
 Enables or disables the SDIO wide bus mode.

Variables

static uint32_t CardType = SDIO_STD_CAPACITY_SD_CARD_V1_1
static uint32_t CID_Tab [4]
static uint32_t CSD_Tab [4]
uint32_t * DestBuffer
static uint32_t DeviceMode = SD_POLLING_MODE
__IO uint32_t NumberOfBytes = 0
static uint32_t RCA = 0
SD_CardInfo SDCardInfo
SDIO_CmdInitTypeDef SDIO_CmdInitStructure
SDIO_DataInitTypeDef SDIO_DataInitStructure
SDIO_InitTypeDef SDIO_InitStructure
uint32_t * SrcBuffer
static uint32_t StopCondition = 0
static uint32_t TotalNumberOfBytes = 0
__IO uint32_t TransferEnd = 0
__IO SD_Error TransferError = SD_OK

Detailed Description

This file provides a set of functions needed to manage the SDIO SD Card memory mounted on STM32xx-EVAL board (refer to stm32_eval.h to know about the boards supporting this memory). It implements a high level communication layer for read and write from/to this memory. The needed STM32 hardware resources (SDIO and GPIO) are defined in stm32xx_eval.h file, and the initialization is performed in SD_LowLevel_Init() function declared in stm32xx_eval.c file. You can easily tailor this driver to any other development board, by just adapting the defines for hardware resources and SD_LowLevel_Init() function.

Author:
MCD Application Team
Version:
V4.3.0
Date:
10/15/2010 +-----------------------------------------------------------+ | Pin assignment | +-----------------------------+---------------+-------------+ | STM32 SDIO Pins | SD | Pin | +-----------------------------+---------------+-------------+ | SDIO D2 | D2 | 1 | | SDIO D3 | D3 | 2 | | SDIO CMD | CMD | 3 | | | VCC | 4 (3.3 V)| | SDIO CLK | CLK | 5 | | | GND | 6 (0 V) | | SDIO D0 | D0 | 7 | | SDIO D1 | D1 | 8 | +-----------------------------+---------------+-------------+

THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.

© COPYRIGHT 2010 STMicroelectronics

Definition in file stm32_eval_sdio_sd.c.

STM32F10x Standard Peripherals Library: Footer

 

 

 

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