Electronic – SD Card formatting in FAT 32 file system

fatnxpsd

I am using NXP Micro for interfacing microSD card with FAT32 file system.

for implementation I am using drivers located at below link.

https://embedded-code.com/source-code/memory/secure-digital-mmc-memory-cards/secure-digital-mmc-memory-card-fat16-fat32-driver

the original driver is not configured for HCS12X compiler. I have done those changes and I am able to read data from SD Card using SPI.

my issue is when I format the SD card using PC in FAT 32 mode I am unable to read THE BOOT RECORD from SD card.

I have successfully read MBR section of card, but after MBR check in SD card initialization- it checks THE BOOT RECORD and i am getting all zeros at that section.

thus the card init is failing as it is not receiving data from THE BOOT RECORD read..

  1. Do i need to follow some specific pattern while formatting card??
  2. Does all SD cards have THE BOOT RECORD section right next to MBR (as a 1st partition)

Best Answer

SD card is no more than a block device -- a collection of numerated sectors (blocks) from the sector numbered zero up to its capacity.

There are two types of SD cards -- simple SD and SDHC. They differ in the way the sectors are addressed. If you are able to read MBR, you're using the correct block driver for your card.

Everything else, including search for partitions and reading files within the partition, is purely a software task.

In your MCU, I can recommend using FatFS driver that is versatile in the meaning that it supports both MBRed cards and the ones without MBR, it supports several partitions at once and it auto-detects and supports any of FAT12, FAT16 or FAT32.

Regarding the way to format SDcard, I can recommend using gparted in linux to make MBR and create formatted partitions exactly with the cluster size you need. In linux, you can even easily create MBRless partition (whole device is a single partition).