SdFat
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions | Variables
SdCardInfo.h File Reference

Definitions for SD cards. More...

#include <stdint.h>
#include "../common/SysCall.h"
Include dependency graph for SdCardInfo.h:
This graph shows which files directly or indirectly include this file:

Classes

class  cid_t
 Card Identification (CID) register. More...
 
class  csd_t
 Union of old and new style CSD register. More...
 
class  scr_t
 SCR register. More...
 
class  sds_t
 SD Status. More...
 

Macros

#define SD_CARD_ERROR(e, m)   SD_CARD_ERROR_##e,
 
#define SD_ERROR_CODE_LIST
 

Enumerations

enum  {
  SD_CARD_ERROR_NONE , SD_CARD_ERROR_CMD0 , SD_CARD_ERROR_CMD2 , SD_CARD_ERROR_CMD3 ,
  SD_CARD_ERROR_CMD6 , SD_CARD_ERROR_CMD7 , SD_CARD_ERROR_CMD8 , SD_CARD_ERROR_CMD9 ,
  SD_CARD_ERROR_CMD10 , SD_CARD_ERROR_CMD12 , SD_CARD_ERROR_CMD13 , SD_CARD_ERROR_CMD17 ,
  SD_CARD_ERROR_CMD18 , SD_CARD_ERROR_CMD24 , SD_CARD_ERROR_CMD25 , SD_CARD_ERROR_CMD32 ,
  SD_CARD_ERROR_CMD33 , SD_CARD_ERROR_CMD38 , SD_CARD_ERROR_CMD58 , SD_CARD_ERROR_CMD59 ,
  SD_CARD_ERROR_ACMD6 , SD_CARD_ERROR_ACMD13 , SD_CARD_ERROR_ACMD23 , SD_CARD_ERROR_ACMD41 ,
  SD_CARD_ERROR_ACMD51 , SD_CARD_ERROR_READ_TOKEN , SD_CARD_ERROR_READ_CRC , SD_CARD_ERROR_READ_FIFO ,
  SD_CARD_ERROR_READ_REG , SD_CARD_ERROR_READ_START , SD_CARD_ERROR_READ_TIMEOUT , SD_CARD_ERROR_STOP_TRAN ,
  SD_CARD_ERROR_TRANSFER_COMPLETE , SD_CARD_ERROR_WRITE_DATA , SD_CARD_ERROR_WRITE_FIFO , SD_CARD_ERROR_WRITE_START ,
  SD_CARD_ERROR_WRITE_PROGRAMMING , SD_CARD_ERROR_WRITE_TIMEOUT , SD_CARD_ERROR_DMA , SD_CARD_ERROR_ERASE ,
  SD_CARD_ERROR_ERASE_SINGLE_SECTOR , SD_CARD_ERROR_ERASE_TIMEOUT , SD_CARD_ERROR_INIT_NOT_CALLED , SD_CARD_ERROR_INVALID_CARD_CONFIG ,
  SD_CARD_ERROR_FUNCTION_NOT_SUPPORTED , SD_CARD_ERROR_UNKNOWN
}
 

Functions

void printSdErrorSymbol (print_t *pr, uint8_t code)
 
void printSdErrorText (print_t *pr, uint8_t code)
 

Variables

const uint8_t ACMD13 = 0X0D
 
const uint8_t ACMD23 = 0X17
 
const uint8_t ACMD41 = 0X29
 
const uint8_t ACMD51 = 0X33
 
const uint8_t ACMD6 = 0X06
 
const uint32_t CARD_STATUS_ADDRESS_ERROR = 1UL << 30
 
const uint32_t CARD_STATUS_AKE_SEQ_ERROR = 1UL << 3
 
const uint32_t CARD_STATUS_APP_CMD = 1UL << 5
 
const uint32_t CARD_STATUS_CARD_ECC_DISABLED = 1UL << 14
 
const uint32_t CARD_STATUS_CARD_ECC_FAILED = 1UL << 21
 
const uint32_t CARD_STATUS_CARD_IS_LOCKED = 1UL << 25
 
const uint32_t CARD_STATUS_CC_ERROR = 1UL << 20
 
const uint32_t CARD_STATUS_COM_CRC_ERROR = 1UL << 23
 
const uint32_t CARD_STATUS_CSD_OVERWRITE = 1UL << 16
 
const uint32_t CARD_STATUS_CURRENT_STATE = 0XF << 9
 
const uint32_t CARD_STATUS_CURRENT_STATE_SHIFT = 9
 
const uint32_t CARD_STATUS_ERASE_PARAM = 1UL << 27
 
const uint32_t CARD_STATUS_ERASE_RESET = 1UL << 13
 
const uint32_t CARD_STATUS_ERASE_SEQ_ERROR = 1UL << 28
 
const uint32_t CARD_STATUS_ERROR = 1UL << 19
 
const uint32_t CARD_STATUS_FX_EVENT = 1UL << 6
 
const uint32_t CARD_STATUS_ILLEGAL_COMMAND = 1UL << 22
 
const uint32_t CARD_STATUS_LOCK_UNLOCK_FAILED = 1UL << 24
 
const uint32_t CARD_STATUS_OUT_OF_RANGE = 1UL << 31
 
const uint32_t CARD_STATUS_READY_FOR_DATA = 1UL << 8
 
const uint32_t CARD_STATUS_SECTOR_LEN_ERROR = 1UL << 29
 
const uint32_t CARD_STATUS_WP_ERASE_SKIP = 1UL << 15
 
const uint32_t CARD_STATUS_WP_VIOLATION = 1UL << 26
 
const uint8_t CMD0 = 0X00
 
const uint8_t CMD10 = 0X0A
 
const uint8_t CMD11 = 0X0B
 
const uint8_t CMD12 = 0X0C
 
const uint8_t CMD13 = 0X0D
 
const uint8_t CMD17 = 0X11
 
const uint8_t CMD18 = 0X12
 
const uint8_t CMD2 = 0X02
 
const uint8_t CMD24 = 0X18
 
const uint8_t CMD25 = 0X19
 
const uint8_t CMD3 = 0X03
 
const uint8_t CMD32 = 0X20
 
const uint8_t CMD33 = 0X21
 
const uint8_t CMD38 = 0X26
 
const uint8_t CMD55 = 0X37
 
const uint8_t CMD58 = 0X3A
 
const uint8_t CMD59 = 0X3B
 
const uint8_t CMD6 = 0X06
 
const uint8_t CMD7 = 0X07
 
const uint8_t CMD8 = 0X08
 
const uint8_t CMD9 = 0X09
 
const uint8_t DATA_RES_ACCEPTED = 0X05
 
const uint8_t DATA_RES_MASK = 0X1F
 
const uint8_t DATA_START_SECTOR = 0XFE
 
const uint8_t R1_IDLE_STATE = 0X01
 
const uint8_t R1_ILLEGAL_COMMAND = 0X04
 
const uint8_t R1_READY_STATE = 0X00
 
const uint8_t SD_CARD_TYPE_SD1 = 1
 
const uint8_t SD_CARD_TYPE_SD2 = 2
 
const uint8_t SD_CARD_TYPE_SDHC = 3
 
const uint16_t SD_CMD_TIMEOUT = 300
 
const uint16_t SD_ERASE_TIMEOUT = 10000
 
const uint16_t SD_INIT_TIMEOUT = 2000
 
const uint16_t SD_READ_TIMEOUT = 300
 
const uint16_t SD_WRITE_TIMEOUT = 600
 
const uint8_t STOP_TRAN_TOKEN = 0XFD
 
const uint8_t WRITE_MULTIPLE_TOKEN = 0XFC
 

Detailed Description

Definitions for SD cards.

Copyright (c) 2011-2022 Bill Greiman This file is part of the SdFat library for SD memory cards.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ SD_CARD_ERROR

#define SD_CARD_ERROR (   e,
 
)    SD_CARD_ERROR_##e,

Macro for generation of error codes using an enum.

◆ SD_ERROR_CODE_LIST

#define SD_ERROR_CODE_LIST

Define error codes and brief description.

Function Documentation

◆ printSdErrorSymbol()

void printSdErrorSymbol ( print_t pr,
uint8_t  code 
)

Print the enum symbol for an error code.

Parameters
[in]prPrint stream.
[in]codeenum value for error.

◆ printSdErrorText()

void printSdErrorText ( print_t pr,
uint8_t  code 
)

Print text for an error code.

Parameters
[in]prPrint stream.
[in]codeenum value for error.

Variable Documentation

◆ ACMD13

const uint8_t ACMD13 = 0X0D

SD_STATUS - Send the SD Status.

◆ ACMD23

const uint8_t ACMD23 = 0X17

SET_WR_BLK_ERASE_COUNT - Set the number of write sectors to be pre-erased before writing

◆ ACMD41

const uint8_t ACMD41 = 0X29

SD_SEND_OP_COMD - Sends host capacity support information and activates the card's initialization process

◆ ACMD51

const uint8_t ACMD51 = 0X33

Reads the SD Configuration Register (SCR).

◆ ACMD6

const uint8_t ACMD6 = 0X06

SET_BUS_WIDTH - Defines the data bus width for data transfer.

◆ CARD_STATUS_ADDRESS_ERROR

const uint32_t CARD_STATUS_ADDRESS_ERROR = 1UL << 30

A misaligned address which did not match the sector length.

◆ CARD_STATUS_AKE_SEQ_ERROR

const uint32_t CARD_STATUS_AKE_SEQ_ERROR = 1UL << 3

Error in the sequence of the authentication process.

◆ CARD_STATUS_APP_CMD

const uint32_t CARD_STATUS_APP_CMD = 1UL << 5

The card will expect ACMD, or the command has been interpreted as ACMD

◆ CARD_STATUS_CARD_ECC_DISABLED

const uint32_t CARD_STATUS_CARD_ECC_DISABLED = 1UL << 14

The command has been executed without using the internal ECC.

◆ CARD_STATUS_CARD_ECC_FAILED

const uint32_t CARD_STATUS_CARD_ECC_FAILED = 1UL << 21

Card internal ECC was applied but failed to correct the data.

◆ CARD_STATUS_CARD_IS_LOCKED

const uint32_t CARD_STATUS_CARD_IS_LOCKED = 1UL << 25

When set, signals that the card is locked by the host.

◆ CARD_STATUS_CC_ERROR

const uint32_t CARD_STATUS_CC_ERROR = 1UL << 20

Internal card controller error

◆ CARD_STATUS_COM_CRC_ERROR

const uint32_t CARD_STATUS_COM_CRC_ERROR = 1UL << 23

The CRC check of the previous command failed.

◆ CARD_STATUS_CSD_OVERWRITE

const uint32_t CARD_STATUS_CSD_OVERWRITE = 1UL << 16

Permanent WP set or attempt to change read only values of CSD.

◆ CARD_STATUS_CURRENT_STATE

const uint32_t CARD_STATUS_CURRENT_STATE = 0XF << 9

The state of the card when receiving the command. 0 = idle 1 = ready 2 = ident 3 = stby 4 = tran 5 = data 6 = rcv 7 = prg 8 = dis 9-14 = reserved 15 = reserved for I/O mode

◆ CARD_STATUS_CURRENT_STATE_SHIFT

const uint32_t CARD_STATUS_CURRENT_STATE_SHIFT = 9

Shift for current state.

◆ CARD_STATUS_ERASE_PARAM

const uint32_t CARD_STATUS_ERASE_PARAM = 1UL << 27

An invalid selection of write-sectors for erase occurred.

◆ CARD_STATUS_ERASE_RESET

const uint32_t CARD_STATUS_ERASE_RESET = 1UL << 13

out of erase sequence command was received.

◆ CARD_STATUS_ERASE_SEQ_ERROR

const uint32_t CARD_STATUS_ERASE_SEQ_ERROR = 1UL << 28

An error in the sequence of erase commands occurred.

◆ CARD_STATUS_ERROR

const uint32_t CARD_STATUS_ERROR = 1UL << 19

A general or an unknown error occurred during the operation.

◆ CARD_STATUS_FX_EVENT

const uint32_t CARD_STATUS_FX_EVENT = 1UL << 6

Extension Functions may set this bit to get host to deal with events.

◆ CARD_STATUS_ILLEGAL_COMMAND

const uint32_t CARD_STATUS_ILLEGAL_COMMAND = 1UL << 22

Command not legal for the card state.

◆ CARD_STATUS_LOCK_UNLOCK_FAILED

const uint32_t CARD_STATUS_LOCK_UNLOCK_FAILED = 1UL << 24

Set when a sequence or password error has been detected.

◆ CARD_STATUS_OUT_OF_RANGE

const uint32_t CARD_STATUS_OUT_OF_RANGE = 1UL << 31

The command's argument was out of the allowed range for this card.

◆ CARD_STATUS_READY_FOR_DATA

const uint32_t CARD_STATUS_READY_FOR_DATA = 1UL << 8

Corresponds to buffer empty signaling on the bus.

◆ CARD_STATUS_SECTOR_LEN_ERROR

const uint32_t CARD_STATUS_SECTOR_LEN_ERROR = 1UL << 29

The transferred sector length is not allowed for this card.

◆ CARD_STATUS_WP_ERASE_SKIP

const uint32_t CARD_STATUS_WP_ERASE_SKIP = 1UL << 15

partial address space was erased due to write protect.

◆ CARD_STATUS_WP_VIOLATION

const uint32_t CARD_STATUS_WP_VIOLATION = 1UL << 26

Set when the host attempts to write to a protected sector.

◆ CMD0

const uint8_t CMD0 = 0X00

GO_IDLE_STATE - init card in spi mode if CS low

◆ CMD10

const uint8_t CMD10 = 0X0A

SEND_CID - read the card identification information (CID register)

◆ CMD11

const uint8_t CMD11 = 0X0B

VOLTAGE_SWITCH -Switch to 1.8V bus signaling level.

◆ CMD12

const uint8_t CMD12 = 0X0C

STOP_TRANSMISSION - end multiple sector read sequence

◆ CMD13

const uint8_t CMD13 = 0X0D

SEND_STATUS - read the card status register

◆ CMD17

const uint8_t CMD17 = 0X11

READ_SINGLE_SECTOR - read a single data sector from the card

◆ CMD18

const uint8_t CMD18 = 0X12

READ_MULTIPLE_SECTOR - read multiple data sectors from the card

◆ CMD2

const uint8_t CMD2 = 0X02

ALL_SEND_CID - Asks any card to send the CID.

◆ CMD24

const uint8_t CMD24 = 0X18

WRITE_SECTOR - write a single data sector to the card

◆ CMD25

const uint8_t CMD25 = 0X19

WRITE_MULTIPLE_SECTOR - write sectors of data until a STOP_TRANSMISSION

◆ CMD3

const uint8_t CMD3 = 0X03

SEND_RELATIVE_ADDR - Ask the card to publish a new RCA.

◆ CMD32

const uint8_t CMD32 = 0X20

ERASE_WR_BLK_START - sets the address of the first sector to be erased

◆ CMD33

const uint8_t CMD33 = 0X21

ERASE_WR_BLK_END - sets the address of the last sector of the continuous range to be erased

◆ CMD38

const uint8_t CMD38 = 0X26

ERASE - erase all previously selected sectors

◆ CMD55

const uint8_t CMD55 = 0X37

APP_CMD - escape for application specific command

◆ CMD58

const uint8_t CMD58 = 0X3A

READ_OCR - read the OCR register of a card

◆ CMD59

const uint8_t CMD59 = 0X3B

CRC_ON_OFF - enable or disable CRC checking

◆ CMD6

const uint8_t CMD6 = 0X06

SWITCH_FUNC - Switch Function Command

◆ CMD7

const uint8_t CMD7 = 0X07

SELECT/DESELECT_CARD - toggles between the stand-by and transfer states.

◆ CMD8

const uint8_t CMD8 = 0X08

SEND_IF_COND - verify SD Memory Card interface operating condition.

◆ CMD9

const uint8_t CMD9 = 0X09

SEND_CSD - read the Card Specific Data (CSD register)

◆ DATA_RES_ACCEPTED

const uint8_t DATA_RES_ACCEPTED = 0X05

write data accepted token

◆ DATA_RES_MASK

const uint8_t DATA_RES_MASK = 0X1F

mask for data response tokens after a write sector operation

◆ DATA_START_SECTOR

const uint8_t DATA_START_SECTOR = 0XFE

start data token for read or write single sector

◆ R1_IDLE_STATE

const uint8_t R1_IDLE_STATE = 0X01

status for card in the idle state

◆ R1_ILLEGAL_COMMAND

const uint8_t R1_ILLEGAL_COMMAND = 0X04

status bit for illegal command

◆ R1_READY_STATE

const uint8_t R1_READY_STATE = 0X00

status for card in the ready state

◆ SD_CARD_TYPE_SD1

const uint8_t SD_CARD_TYPE_SD1 = 1

Standard capacity V1 SD card

◆ SD_CARD_TYPE_SD2

const uint8_t SD_CARD_TYPE_SD2 = 2

Standard capacity V2 SD card

◆ SD_CARD_TYPE_SDHC

const uint8_t SD_CARD_TYPE_SDHC = 3

High Capacity SD card

◆ SD_CMD_TIMEOUT

const uint16_t SD_CMD_TIMEOUT = 300

command timeout ms

◆ SD_ERASE_TIMEOUT

const uint16_t SD_ERASE_TIMEOUT = 10000

erase timeout ms

◆ SD_INIT_TIMEOUT

const uint16_t SD_INIT_TIMEOUT = 2000

init timeout ms

◆ SD_READ_TIMEOUT

const uint16_t SD_READ_TIMEOUT = 300

read timeout ms

◆ SD_WRITE_TIMEOUT

const uint16_t SD_WRITE_TIMEOUT = 600

write time out ms

◆ STOP_TRAN_TOKEN

const uint8_t STOP_TRAN_TOKEN = 0XFD

stop token for write multiple sectors

◆ WRITE_MULTIPLE_TOKEN

const uint8_t WRITE_MULTIPLE_TOKEN = 0XFC

start data token for write multiple sectors