How to Use MMC/SDC

Started by tha, May 28, 2022, 09:34:51 AM

Previous topic - Next topic

tha

Initialization

In idle state, the card ยอมรับเฉพาะ CMD0, CMD1, CMD8, ACMD41, CMD58 and CMD59. Any other commands จะถูกปฏิเสธ. ในเวลานี้, OCR register ควรถูกอ่านด้วย CMD58 เพื่อเช็ค the working voltage range of the card. ในกรณีที่ the system sypply voltage อยู่นอกช่วง working voltage range, the card ต้องถูกปฏิเสธ. โปรดทราบว่า all cards ทำงานที่ supply voltage ในช่วง 2.7 ถึง 3.6 volts เป็นอย่างน้อย, ดังนั้น the host contoller ไม่จำเป็นต้องเช็ค the OCR ถ้า supply voltage อยู่ในช่วงนี้. The card เริ่มต้น the initialization process เมื่อ a CMD1 ถูกรับ. เพื่อตรวจหา end of the initialization process, the host controller จำเป็นต้องส่ง CMD1 และเช็ค the response จนกระทั่ง end of the initialization. เมื่อ the card ถูกเริ่มต้นเรียบร้อยแล้ว, In Idle State bit ใน the R1 response จะถูกเคลียร์ (R1 resp เปลี่ยน 0x01 เป็น 0x00). The initialization process อาจใช้เวลาหลายร้อยมิลลิวินาที (การ์ดขนาดใหญ่มักจะนานกว่านั้น) ดังนั้นนี่คือการพิจารณาเพื่อกำหนด the time out value. หลังจาก the In Idle State bit ถูกเคลียร์, the card ก็พร้อมที่จะยอมรับ the generic read/write commands.

เนื่องจาก ACMD41 แทน CMD1 ถูกแนะนำสำหรับ SDC, ให้ลองใช้ ACMD41 ก่อนและลองอีกครั้งด้วย CMD1 หากถูกปฏิเสธ เหมาะอย่างยิ่งที่จะรองรับการ์ดทั้งสองประเภท.

The SCLK frequency ควรถูกเปลี่ยนให้เร็วที่สุดเท่าที่เป็นได้เพื่อให้สูงสุด the read/write performance. The TRAN_SPEED field ใน the CSD register แสดงให้เห็น the maximum clock frequency of the card. มันเป็น 20MHz สำหรับ MMC, 25MHz สำหรับ SDC ในกรณีส่วนใหญ่. โปรดทราบว่า the clock freqency จะสามารถที่จะถูกคงที่เป็น 20/25MHz ใน SPI mode เนื่องจากไม่มี open-drain condition ที่จำกัด the clock frequency.

The initial read/write block length อาจถูกเซ็ต 1024 บน 2 GB cards, ดังนั้น the block size ควรถูกเริ่มต้นใหม่เป็น 512 ด้วย CMD16 เพื่อทำงานกับ FAT file system.

tha

High-capacity SDC and Initialization

SDSC card รองรับ 8MB ถึง 2GB. นี้คือจาก the maximum capacity of regular file system, FAT. (FAT รองรับสูงถึง 4GB ตามทฤษฎี แต่ MS-DOS รองรับสูงถึง 2GB.)

SDHC card รองรับ 4GB ถึง 32GB. นี้คือจาก the maximum capacity of regular file system, FAT32. (FAT32 รองรับสูงถึง 2TB ตามทฤษฎี แต่ดูเหมือนว่าจะได้รับผลกระทบจากความต้องการของ Microsoft ที่พวกเขาแนะนำให้ใช้ FAT32 สำหรับไดรฟ์ข้อมูลขนาด 32GB หรือเล็กกว่า)

SDXC card รองรับ 64GB ถึง 2TB. นี้คือจาก the addressing mode ใน read/write commands, 32-bit LBA. (The regular file system, exFAT, รองรับมากกว่า 2TB.)

SDUC card รองรับ 4TB ถึง 128TB. The addressing mode ถูกขยายถึง 38-bit LBA. อย่างไรก็ตาม the SDUC card อาจไม่รองรับ SPI mode เนื่องจาก the 38-bit LBA เป็น a new feature ที่กำหนดหลังจาก SDC Ver.2.

ตอนนี้, the initialization process สำหรับ high-capacity SDCs แตกต่างจาก the process ที่อธิบายข้างบน. หลังจาก the card อยู่ใน idle state ด้วย a CMD0, host controller ส่ง a CMD8 ที่มี an argument 0x000001AA และ correct CRC ก่อนถึง initialization process. ถ้ามันถูกปฏิเสธด้วย illigal command error (0x05), the card คือ SDC Ver.1 หรือ MMC Ver.3. The card จะถูกเริ่มต้นตามที่อธิบายไว้ข้างบน. ถ้า the CMD8 ถูกยอมรับ, R7 response (R1(0x01) + 32-bit return value) จะถูกส่งคืนกลับ. The lower 12-bit ใน the return value 0x1AA หมายความว่า the card เป็น SDC Ver.2+ และมันสามารถทำงานที่ supply voltage ในช่วง 2.7 ถึง 3.6 volts. หากไม่เป็นเช่นนั้น, the card ควรถูกปฏิเสธ. และจากนั้นเริ่มต้น initialization ด้วย ACMD41 ที่มี HCS[bit30] flag ใน the argument. หลังจาก the initialization เสร็จสมบูรณ์, อ่าน OCR register ด้วย CMD58 และเช็ค CCS[bit30] flag. เมื่อมันถูกเซ็ต, the card คือ a high-capacity card ที่เรียกว่า SDHC/SDXC. The data read/write operations ที่อธิบายไว้ด้านล่างได้รับคำสั่งใน block addressing (LBA) แทน byte addressing. The size of data block ที่ block addressing mode ถูกคงที่เป็น 512 bytes.

tha

Data Transfer

Data Packet and Data Response

ใน a transaction ที่มี data transfer, อย่างน้อยหนึ่ง data blocks จะถูกส่ง/รับหลังจาก command response. The data block ถูกส่งถ่ายเป็น a data packet ที่ประกอบด้วย Token, Data Block and CRC. The format of the data packet ถูกแสดงในรูปทางด้านขวาและมี three data tokens. Stop Tran token คือการยุติ a multiple block write transaction, มันถูกใช้เป็น single byte packet โดยไม่มี data block และ CRC.



tha

Single Block Read



The argument ระบุ the address เพื่อเริ่มการอ่านในหน่วยของ BYTE หรือ BLOCK. The sector address ใน LBA ที่ระบุโดย upper layer จะต้องถูกปรับขนาดให้เหมาะสมขึ้นอยู่กับ the card's addressing mode. เมื่อ a CMD17 ถูกยอมรับ, a read operation ถูกเริ่มต้นและ the read data block จะถูกส่งไปยัง the host. หลังจาก a valid data token ถูกตรวจพบ, the host controller จะรับ data field and CRC ที่ตามมา. The CRC bytes ต้องถูกรับแม้ว่ามันไม่ถูกต้องการ. ถ้า any error เกิดขึ้นในระหว่าง the read operation, an error token จะถูกส่งคืนกลับแทน data packet.

tha

Multiple Block Read



The CMD18 คือการอ่าน data blocks ตามลำดับโดยเริ่มที่ the specified address. The read operation ต่อเนื่องเป็นแบบปลายเปิด. เพื่อยุติ the read transaciton, a CMD12 จำเป็นต้องถูกส่งไปยัง the card. The received byte ที่ตาม CMD12 ทันทีคือ a stuff byte, มันควรถูกทิ้งก่อนที่จะรับ the response of the CMD12. สำหรับ MMC, ถ้า number of transfer blocks ถูกระบุแล้วโดย a CMD23 ก่อน CMD18, the read transaction ถูกเริ่มต้นเป็น a pre-defined multiple block transfer และ the read operation ถูกยุติลงที่ last block transfer.

tha

Single Block Write



The Single Block Write เขียน a block ไปยัง the card. หลังจาก a CMD24 ถูกยอมรับ, the host controller ส่ง a data packet ไปยัง the card. The packet format เป็นเหมือนกันกับ block read operations. cards ส่วนใหญ่ไม่สามารถเปลี่ยน write block size และมันถูกคงที่เป็น 512. The CRC field สามารถมี any fixed value เว้นแต่ the CRC function ถูกเปิดใช้งาน. The card ตอบสนอง a Data Response ตามติด the data packet จาก the host ทันที. The Data Response พ่วง a busy flag และ host controller ต้องค้าง the next command หรือ data transmission จนกว่า the card จะพร้อม.

ตามหลักการของ the SPI mode, the CS signal ต้องถูกยืนยันในระหว่าง a transaction. อย่างไรก็ตาม มีข้อยกเว้นสำหรับกฎนี้. เมื่อ the card ยุ่งอยู่, the host controller สามารถถอนการยืนยัน CS เพื่อปลดปล่อย SPI bus สำหรับ data transfer ไปยัง SPI devices อื่นบน the bus. The card จะขับ DO low อีกครั้งเมื่อถูกเลือกซ้ำในระหว่าง internal process ยังคงอยู่ในระหว่างดำเนินการ. ดังนั้น a preceding busy check, เช็คว่า card ยุ่งอยู่หรือไม่ก่อนแต่ละ command and data packet, แทน post wait สามารถขจัด the busy wait time. นอกจากนี้, the internal write process ถูกเริ่มต้น a byte หลังจาก the data response, นี้หมายถึง 8 SCLK clocks ถูกต้องการเพื่อเริ่มต้น internal write operation. The state of CS signal ในระหว่าง the post clocks สามารถเป็นอย่างใดอย่างหนึ่ง low หรือ high, ดังนั้นมันสามารถถูกทำด้วย bus release process ตามที่อธิบายไว้ข้างล่าง.

tha

Multiple Block Write



The Multiple Block Write command เขียน data blocks ตามลำดับโดยเริ่มที่ the specified address. หลังจาก a CMD25 ถูกยอมรับ, the host controller ส่งอย่างน้อยหนึ่ง data packets ไปยัง the card. The packet format เป็นเหมือนกันกับ block read operations ยกเว้นสำหรับ Data Token. The write transaction ต่อเนื่องจนกระทั่งมันถูกยุติลงด้วย a Stop Tran token. The busy flag จะถูก output หลังจากทุกๆ data block และ Stop Tran token. สำหรับ MMC, the number of blocks ที่จะเขียนสามารถถูกกำหนดไว้ล่วงหน้าโดย CMD23 ก่อน CMD25 และ the write transaction จะถูกยุติที่ last data block. สำหรับ SDC, a Stop Tran token ถูกต้องการเสมอเพื่อยุติ the multiple block write transaction.  จำนวนของ sectors ที่จะลบล่วงหน้าเมื่อเริ่ม the write transaction สามารถถูกระบุโดย an ACMD23 ก่อน CMD25. มันอาจสามารถปรับกลยุทธ์การเขียนใน the card ให้เหมาะสมและมันสามารถถูกยุติไม่ใช่ที่ the pre-erased blocks แต่ the content of the pre-erased area ที่ไม่ได้เขียนไว้จะไม่ได้กำหนดไว้.

Reading CSD and CID

สิ่งเหล่านี้เป็นเหมือนกันกับ Single Block Read ยกเว้น the data block length. The CSD and CID จะถูกส่งถึง the host เป็น 16 byte data block. สำหรับรายละเอียดของ the CMD, CID and OCR, โปรดดูที่ the MMC/SDC specs.

tha

Cosideration to Bus Floating and Hot Insertion

SPI signals ที่สามารถถูกลอยได้ควรถูกดึง low หรือ high อย่างเหมาะสมโดยทาง a resister. สิ่งนี้เป็น a generic design rule เกี่ยวกับ CMOS device. เนื่องจาก DI and DO ปกติเป็น high, พวกมันควรถูก pulled-up. เป็นไปตาม SDC/MMC specs, จาก 50k ถึง 100k ohms ถูกแนะนำเป็นค่าของ pull-up registers. อย่างไรก็ตาม the clock signal ไม่ได้ถูกกล่าวใน the SDC/MMC specs เนื่องจากมันถูกขับโดย host controller เสมอ. เมื่อมีความเป็นไปได้ของการลอย, มันควรถูกดึงเป็น the normal state, low.

The MMC/SDC สามารถ hot insertion/removal. แต่บางการพิจารณาถึง the host circuit ถูกจำเป็นเพื่อหลีกเลี่ยงการทำงานที่ไม่ถูกต้อง. ตัวอย่างเช่น, ถ้า the system power supply (Vcc) ถูกผูกติดกับ the card socket โดยตรง, the Vcc จะ dip ทันทีที่ใส่การ์ดเนื่องจาก a charge current ไปยัง the built-in capacitor ของ the card.  'A' ในรูปขวาเป็น the scope view และมันแสดงถึงการเกิดขึ้น a voltage dip ประมาณ 600 mV. นี้เป็นระดับที่เพียงพอที่จะทริก a brown out detector. 'B' ในรูปขวาแสดงว่า an inductor ถูกใส่เพื่อบล็อก the surge current, the voltage dip ถูกลดลงเหลือ 200 mV. A low ESR capacitor, อย่างเช่น OS-CON, สามารถขจัด the voltage dip ได้อย่างมากดังที่แสดงใน 'C'. อย่างไรก็ตาม the low ESR capacitor อาจเป็นเหตุทำให้เกิดการสั่นของ LDO regulator.