S3C2440 reads and writes large capacity SD cards

Publisher:朝霞暮雨Latest update time:2016-11-27 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First understand the SD card protocol

1. SD Card Protocol Overview

Command: Sent by the host on the CMD line

Response: Sent on the CMD line by the addressed card.

Data: On the data line, use DAT0 or DAT0~DAT3.

The CRC status response and Busy indication can only be sent via DAT0

2. Command format:

High, 48th Low, 1st


0

1

contents

CRC7

1

Start bit, always 0

Transmission direction,

1: Host sends

0: The device sends

Content, determined by the specific command

Seven-bit CRC

Stop bit,

Total is 1


 

Response format: R1, R3, and R6 are the same as the command format, except that the 47th bit is 0; and R2 is 136 bits, but the contents has more bits than the above table.

Transmission format for four data lines: omitted

The order in which data passes through the bus: high bits first, low bits last.

 

SD Card Registers:

name

width

illustrate

CID

128

Card identification number; Card identification number

RCA

16

Relative card address; local address, determined by the host and card during initialization

DSR

16

Driver Stage Register; configure the output driver of the card

CSD

128

Card Specific Data; Information about card operations

SCR

64

SD Configuration Register; Card configuration information

OCR

32

Operation conditions register

SSR

512

SD Status; information about the card proprietary features

CSR

32

Card Status; information about the card status


The red ones are the registers added in V2.0. The green ones are for SPI and the blue ones are for V1.0.

 

3. Command types: broadcast command, point-to-point addressing command.

    Operation mode: identification card mode, data transmission mode.

Card identification process: 1. Reset. Power on or send CMD0 to put the card into idle state.

                       2. Send ACMD41, CMD2, and CMD3 to make it enter the waiting state of data transmission mode.

For large-capacity SD cards, after sending ACMD41, check whether CCS is 1 to determine whether it is a large-capacity SD card. In order to be able to identify various cards, the initial clock setting cannot be higher than 400kHz

 

data transmission:

Differences in operations for large-capacity SD cards

The memory access commands include a block read command (CMD17, CMD18), a block write command (CMD24, CMD25) and a block erase command (CMD32, CMD33).

The following are the functional differences between standard capacity SD cards and high capacity SD cards when accessing memory:

1. Command variables

For large capacity SD cards, the 32-bit variable of the memory access command is a memory access for block addressing (the block variable that determines the block). The fixed size of the block is 512 bytes. For standard capacity SD cards, the 32-bit variable is byte addressing, and the block length is determined by the CMD16 command.

Right now:

(a) For standard capacity SD cards, variable 0001h addresses the 0001h byte unit, while for large capacity SD cards, it addresses the 0001h block.

(b) For standard capacity SD cards, variable 0002h addresses the 0002h byte unit, while for large capacity SD cards, it addresses the 0002h block.

2. Local addressing and unaligned addressing. In large-capacity SD cards, local addressing and unaligned addressing (crossing block boundaries) as block addressing are not allowed, and only whole block addressing is allowed.

3. Set the block length

When using the memory read and write commands in block addressing mode, the block length is 512 bytes, regardless of the block length set by CMD16.

The memory access command is invalid. CMD42 does not belong to the memory access command. The data block size and block length specified by CMD16 are set to 512 bytes.

512 bytes will set BLOCK_LEN_ERROR and ignore the card capacity.

4. Write protection group

Large capacity SD cards are not supported. Sending commands CMD28, CMD29 and CMD30 will generate an ILLEGAL_COMMAND error

5. Read and write timeout check

Read: For standard capacity SD cards, the read timeout is set to be 100 times greater than the typical read time, or 100ms. The card parameter read time is: twice the TAACT NSAC parameter in CSD.

Write: For standard capacity SD cards, the write timeout is set to 100 times greater than the typical programming time, or 250mS. The write time of the card parameters is: R2W_FACTOR in CSD

For large capacity cards, the parameters in CSD are fixed values, so it is best to use >100mS as read timeout and >250mS as write timeout.

 

 

 

4. Command format

 


Sequence

47

46

[45:40]

[39:8]

[7:1]

0

width

1

1

6

32

7

1

Numeric

'0'

'1'

x

x

x

'1'

Remark

Start bit

1 sent, 0 received

Command Index

variable

CRC7

Stop bit


 

 

5. About command index

The "command index" is not clearly stated in the SD protocol, but after referring to Samsung programs and online articles, I believe that this statement is correct: the number in the "command index" is its "index value". For ACMD commands, they can be regarded as "compound commands", that is, when executing, CMD55 is executed first, and then the "command with 'A' removed from the front of ACMDn" is executed.

2. Instructions on SD card operation in the S3C2440 manual

 The serial clock shifts and synchronizes the information on the data line and samples it, setting SDIPRE to control the transmission frequency.

 

Basic programming process: 1. Set SDICON to select clock and interrupt.

2. Set SDIPRE to an appropriate value.

3. Wait for 74 SDCLKs to complete the SD card initialization

The process of sending a command: 1. Write a 32-bit command variable to SDICmdArg

2. Set the SDICmdCon register, select the command type and start the transmission

3. Check whether the specified bit of SDICmdSta is set to determine whether the command has been transmitted.

4. If there is a response, check the response register SDIRSPn

5. Write 1 to the corresponding bit of the SDICmdSta register to clear the flag bit

Data channel programming: 1. Write timeout register SDIDTimer

2. Write the block size to be operated to SDIBSize

3. Set block mode, bus width, DMA, etc., and set SDIDatCon. to start transmission

4. When sending data, when TCFIFO is valid, half full, or empty, write the data into SDIDAT.

5. When receiving data, when RXFIFO is valid, half full, or empty, write the data into SDIDAT.

6. Confirm whether the data has been transferred.

7. Clear the corresponding flag in SDIDatSta

 

1. Differences in initialization commands:

1. Add CMD8 command to identify whether it is a large-capacity card. If so, the response is R7, returning the acceptable power range and the verification code consistent with the one sent.

2. ACMD41 is slightly different from V1.0. Its response is generally rSDIRSP0=0xc0ff8000. For compatibility, an extra branch needs to be added.

3. Send CMD2, and the response is CID. For example, the values ​​of rSDIRSP0:rSDIRSP1:rSDIRSP2:rSDIRSP3 of a card are: 0x1b534d30:0x30303030:0x10b1846c:0xdc00879d, and the meanings are as follows:

127 0

Number of digits

8

16

40

8

32

4

12

7

1

value

1b

534d

3030303030

10

b1846cd

c

008

79d


significance

MID

“SM

00000”

PRV

PSN

RSV

MDT

CRC



 

2. Differences between reading and writing

V2.0 operates on blocks, with each block being 512 bytes. V1.0 can operate on bytes, using CMD16 to set the block size. CMD17 and CMD18 are used to operate on a single block or multiple blocks respectively.

It is worth noting that Samsung's routine is more classic, but it cannot read large-capacity SD cards because the SDI Data Control Register is not set. For large-capacity cards, this register must be set to 0x200, and it must be this value.

 

The following is the data read from the starting sector of a large capacity card:

0x 0: Rx-0xeb068005,0x2039ffff,0xe800005b,0xc1eb048c

0x 4: Rx-0xc801c38e,0xdb536a19,0xcbf60602,0x 4740f

0x 8: Rx-0x31c08ec0,0xbffc0566,0xb8445543,0x4566ab68

0x c: Rx-0x 2017bc,0x 9031c9,0x51ba8000,0x52b408f9

0x 10: Rx-0xcd135a58,0x16077217,0x80e13ff9,0x741191b4

0x 14: Rx-0x 289c531,0xdb4152f9,0xcd135a72,0x 2f6dc0e

0x 18: Rx-0x1f9c31f6,0x31ffb9df,0xfcf3a5,0xbbfc1966

0x 1c: Rx-0xb8475255,0xaaea7a00,0x 20161f,0x66390775

0x 20: Rx-0x549d723c,0x e1fad88,0xe6ad89c1,0x243f741f

0x 24: Rx-0x29e848f6,0xd8bf0300,0xb4026800,0xd0731db

0x 28: Rx-0x60cd1361,0x730a6031,0xc0cd1361,0x4f75e9f9

0x 2c: Rx-0xe8c50977,0x2883c60c,0x81fefe01,0x72c67715

0x 30: Rx-0xbeb231b4,0x 89952cd,0x13587209,0x9991243f

0x 34: Rx-0x740341eb,0xc0be5101,0xe86f00eb,0xfe1e0666

0x 38: Rx-0x608cc3fa,0x f011660,0x a0f20c0,0x c010f22

0x 3c: Rx-0xc0be0800,0x8ec66631,0xf66631ff,0x66b90024

0x 40: Rx-0x fcf3,0x66a5be10,0x 8ec624,0xfe0f22c0

0x 44: Rx-0x8ec3b900,0x 231f656,0xbf007c57,0x 61f5607

0x 48: Rx-0xfcf3a5bf,0x107ebe00,0xab91e00,0xfcf3662e

0x 4c: Rx-0xa5061ffb,0xcbfab800,0x208ed0bc,0xdc8ffb66

0x 50: Rx-0x61071fe9,0x6fffb40e,0xcd102eac,0x3c0075f6

0x 54: Rx-0xc30d0a4d,0x69737369,0x6e67204d,0x42522d68

0x 58: Rx-0x656c7065,0x722e0000,0x 0,0x 0

0x 5c: Rx-0x 0,0x 0,0x 0,0x 0

0x 60: Rx-0x 0,0x 0,0x 0,0x 0

0x 64: Rx-0x 0,0x 0,0x 0,0x 0

0x 68: Rx-0x 0,0x 0,0x 0,0x 0

0x 6c: Rx-0x 0,0x 0,0x9bb43b00,0x 8001

0x 70: Rx-0x 1000cfe,0x7ff23f00,0x c17f,0x7a000000

0x 74: Rx-0x 0,0x 0,0x 0,0x 0

0x 78: Rx-0x 0,0x 0,0x 0,0x 0

0x 7c: Rx-0x 0,0x 0,0x 0,0x 55aa


Keywords:S3C2440 Reference address:S3C2440 reads and writes large capacity SD cards

Previous article:STM32 Note SD card reading and writing and FatFS file system
Next article:ARM development step by step into the MMU first look

Recommended ReadingLatest update time:2024-11-17 00:46

《Linux driver: s3c2410/s3c2440 ts driver analysis 2》
I. Introduction In the previous section, we analyzed the loading process of the ts (touch) driver in combination with the "platform bus-device-driver" model. Now we will analyze the specific implementation of the driver program, which involves a detailed explanation of the input subsystem, analysis of the input
[Microcontroller]
S3C2440 timer and pwm programming analysis
The input clock of the timer is PCLK; T0 and T1 are a group, T0 and T1 share an 8-bit divider T2, T3, and T4 are a group and share an 8-bit divider. T4 has no output pin and can only be used as an internal clock. After 8-bit frequency division, there is also a 1/2 1/4 1/8 1/16 clock divider. The
[Microcontroller]
S3c2440 code relocation details 6---Relocation and clearing of BSS segment C function implementation
Previously, we used the assembler to implement relocation and clearing the bss segment. In this section, we will use C language to implement relocation and clearing the bss segment. 1. Open start.S and delete the original assembly code and call the C function instead     /* Relocate the entire program in text, rod
[Microcontroller]
S3c2440 code relocation details 6---Relocation and clearing of BSS segment C function implementation
1.10.2_I2C_S3C2440 I2C controller_P
The 2440 connects to devices (AT24Cxx) via the I2C bus, and there is an I2C controller inside the chip. When the master (2440) is a Transmitter, the slave is a Receiver. When the master is a Receiver, the slave is a Transmitter. The following figure is the I2C bus block diagram of 2440. From left to right, the fi
[Microcontroller]
1.10.2_I2C_S3C2440 I2C controller_P
Setting the pull-up resistor when the GPIO of S3C2440 is used as input
When using GPIO as output, a pull-up resistor must be added because the default is open drain, high impedance state, and cannot output a high level. When inputting, it is necessary to choose whether to set a pull-up resistor based on the peripheral circuit:   When the external circuit can provide high and low le
[Microcontroller]
Embedded driver learning GPIO driver
Development Environment Host development environment: Ubuntu 12.04 BootLoader:u-boot-1.1.6 kernel:linux-2.6.30.4 CPU:s3c2440 Development board: TQ2440 Development steps 1. Hardware Analysis In the development board provided by Tianqian Technology, the four LED lights (TQ2440) use the S3C2440 chip: GPB5, GPB6, GPB7 a
[Microcontroller]
Embedded driver learning GPIO driver
Using J-Link to debug S3C2440 bare metal code on Linux
tool: Segger's JLink emulator Segger's JLink for Linux arm-xx-linux-xx-gdb in the cross-compilation toolchain Initialization Script Tool Installation Segger's JLink for Linux Go to Segger official website --- Download --- J-Link/J-Trace --- J-Link Softwa
[Microcontroller]
Mini2440 or S3C2440 address allocation problem
This article is written to answer a question from a netizen, because I didn't understand it before, so I will briefly explain it. The source question is "How are the addresses of mini2440 allocated? What are the addresses of the internal rom ram, external ram and rom respectively? I saw three k4561632N chips and one S
[Microcontroller]
Mini2440 or S3C2440 address allocation problem
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号