AN1045

Started by tha, May 05, 2022, 03:04:40 PM

Previous topic - Next topic

tha

https://ww1.microchip.com/downloads/en/AppNotes/01045a.pdf

AN1045

Implementing File I/O Functions Using Microchipís
Memory Disk Drive File System Library


INTRODUCTION

application note นี้ครอบคลุมการใช้ของ file I/O functions โดยใช้ Microchipís memory disk drive file system library. Microchipís memory disk drive file system คือ:

•    อิงตาม ISO/IEC 9293 specifications
•    รู้จักกันในชื่อ the FAT16 file system, ที่ใช้บน DOS operating systems ก่อนหน้านี้โดย Microsoft Corporation
•    ระบบไฟล์ยอดนิยมพร้อม SD card, CF card และ USB thumb drive

SD cards และ MMCs ส่วนใหญ่, โดยเฉพาะเหล่านั้นที่ขนาดต่ำกว่า 2 gigabytes (GB), ใช้มาตรฐานนี้. application note นี้แสดงวิธีการอ่านและ/หรือเขียนไปยัง storage devices เหล่านี้ผ่านทาง a microcontroller. data นี้สามารถถูกอ่านโดย a PC และ data ที่เขียนโดย a PC สามารถถูกอ่านโดย a microcontroller. operating systems ส่วนใหญ่ (เช่น, Windows XP) รองรับระบบไฟล์นี้.

tha

SD CARDS AND MMCS

SD cards and MMCs เป็นกรรมสิทธิ์, ถอดออกได้ , Flash technology-based media, ซึ่งถูกอนุญาติให้ใช้โดย the SD Card Association และ the MultiMediaCard Association (ดู "References"), ตามลำดับ.

ตามหน้าที่, the two card formats จะคล้ายกัน; อย่างไรก็ตาม, the SD card มีทางเลือก encryption security features ที่ไม่ถูกพบตามปกติบน the MMC. The specifications ของ devices เหล่านี้, และข้อกำหนดและเงื่อนไขสำหรับการใช้งานของพวกมัน, ที่ต่างกันไปและควรถูกตรวจสอบสำหรับ application licensing information เพิ่มเติม.

tha

INTERFACE

The PICtail™ Daughter Board สำหรับ SD and MMC cards, Microchip product number AC164122, จัดให้มี an interface ระหว่าง SD or MMC cards และ a PIC® microcontroller โดยทาง the SPI bus. The PICtail Daughter Board ถูกออกแบบให้ทำงานร่วมกับความหลากหลายของ demonstration boards, รวมทั้งเหล่านั้นทั้งหมดที่มี PICtail or PICtail Plus Daughter Board interfaces.

The SPI protocol ใช้ four basic pins สำหรับ communication: data in (SDI), data out (SDO), clock (SCK), and chip select (CS). นอกจากนี้, SD card sockets เกือบทั้งหมดมี two electrically determined signals, card detect และ write-protect, ที่ยอมให้ผู้ใช้ตรวจสอบว่าการ์ดถูกเสียบเข้าไปและ/หรือป้องกันการเขียน.

The MMC ไม่มี a physical write-protect signal, แต่ card connectors ส่วนใหญ่จะเริ่มต้นเป็น a non-write-protected state ในกรณีนี้.

ข้อมูลเพิ่มเติมเกี่ยวกับการอินเตอร์เฟซ PIC® microcontrollers ไปยัง SD cards or MMCs ถูกรวมใน AN1003, “USB Mass Storage Device Using a PIC® MCU” (DS01003), มีให้ใช้ประโยชน์จาก the Microchip web site.


tha

CARD FILE SYSTEM

สำคัญ: เป็นความรับผิดชอบของผู้ใช้ในการขอรับสำเนา, ทำความคุ้นเคยอย่างเต็มที่กับ, และปฏิบัติตาม the requirements and licensing obligations ใช้ได้กับ third party tools, รวมถึง systems และ/หรือ specifications, แต่ไม่จำกัดเพียง, Flash-based media and FAT file systems มีให้ใช้ประโยชน์จาก CompactFlash® Association, SD Card Association, MultiMediaCard Association and Microsoft® Corporation.

โปรดอ้างอิงถึง the license agreement สำหรับรายละเอียด.

tha

An ISO/IEC 9293 system จัดเก็บ data ใน sectors. A sector มีขนาด 512 bytes เป็นปกติ. เนื่องจากจำนวนของ available memory addresses ถูกครอบที่ FFFFh, sectors สามารถถูกจัดกลุ่มลงใน clusters ที่แชร์ an address เพื่อเพิ่มขนาดของ the card.

The first sector บน a card คือ the Master Boot Record (MBR). The MBR บรรจุข้อมูลเกี่ยวกับ different logical subdivisions บน a card, ที่เรียกว่า partitions. แต่ละ partitions เหล่านี้สามารถถูกฟอร์แมตด้วย a unique file system. โดยทั่วไปแล้ว, an SD card or MMC ที่เพียง one active partition, ซึ่งประกอบด้วยส่วนต่างๆ ดังต่อไปนี้ :

•   Boot sector
•   FAT regions
•   Root Directory region
•   Data region

tha

The boot sector เป็น the first sector of the partition และบรรจุข้อมูลพื้นฐานเกี่ยวกับ the file system type.

The FAT region จริงๆแล้วเป็นแผนที่ของ the card, แสดงให้เห็นวิธีที่ the clusters ถูกจัดสรรใน the data region อย่างไร. โดยทั่วไปจะมีสองสำเนาของ the FAT ใน the FAT region, เพื่อจัดให้มีสำรองในกรณีของ data corruption.

tha

The root directory region ตามติด the FAT region และถูกประกอบด้วย a directory table ที่บรรจุ an entry สำหรับทุกๆ directory and file บน the card.

รวม, the first three sections เป็น the system area. The remaining space เป็น the data region. Data ที่เก็บใน region นี้ยังคงไม่บุบสลาย แม้ว่าจะถูกลบไปแล้วก็ตาม จนกว่าจะถูกเขียนทับ.

tha

The FAT16 system ใช้ 16-bit FAT entries, ยอมให้ประมาณ 65,536 (2^16) clusters ถูกแสดง. A signed byte ใน the boot sector กำหนดจำนวนของ sectors ต่อหนึ่ง cluster สำหรับ a disk. byte นี้มีย่าน -128 ถึง 127. ค่าที่ใช้ได้เฉพาะใน the FAT16 file system นี้คือค่าบวก, ค่ากำลังสอง (1, 2, 4, 8, 16, 32, 64). นี้หมายความว่าด้วย the standard 512-byte sector size, the FAT16 file system สามารถรองรับได้มากสุด 2 GB ของ disk space.

The memory structure ของ an SD card or an MMC ถูกแสดงใน Figure 1.