4
\$\begingroup\$

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)
\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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).

\$\endgroup\$
0
0
\$\begingroup\$

That sounds a lot like a bug in your code where you can actually only read the first sector.

On the SD card level flash memory, there is no difference between the MBR and the rest, it's just memory so the fact that you can only read the first sector is a sign that points to the code,assuming there is actually something to read on the other sectors.

  • Did you put some files in the SD?
  • Is the SD working properly? Note that there are a lot of fake SD cards on the market (something like 70% are fake) and those can have unexpected behavior.
  • Does your stack support FAT32? Some are FAT16 for example.

FAT32 isn't the best filesystem for embedded as it easily gets corrupted and is heavy, especially when you have a lot of files.

--- EDIT

I had a look at the code, and it seems to be the old Microchip MLA Filesystem code, that the guy just reposted while removing the Microchip header and put his instead.

I worked on this code a few years back and spent weeks refactoring a debugging it. This code is overall an example of coding bad practice (>1'000 lines function, imbricated loops, etc..)

Overall it has a lot of problems and I suggest you look for another stack.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.