AnsweredAssumed Answered

SDK fatfs_usdcard not working with 2gb cards

Question asked by Mike Spenard on Apr 30, 2019
Latest reply on May 6, 2019 by Jorge Antonio Alcala Vazquez

Hi All,

 I'm using NXP's SDK example project fatfs_usdcard. It does not seem to be working with 2gb SD cards. Others have posted similar issues with the LPC's SDK but there is no reported solution: https://community.nxp.com/thread/416897


The issue is not with the card, as multiples have been tried new out of box. And they function correctly in Windows.

 

Specifically, when issuing a f_mount() command it fails with FR_NO_FILESYSTEM. Drilling down further it is find_volume() that is unable to find a partition. 

 

From find_volume():

/* Find an FAT partition on the drive. Supports only generic partitioning rules, FDISK and SFD. */
bsect = 0;
fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */
if (fmt == 2 || (fmt < 2 && LD2PT(vol) != 0)) { /* Not an FAT-VBR or forced partition number */
for (i = 0; i < 4; i++) { /* Get partition offset */
pt = fs->win + (MBR_Table + i * SZ_PTE);
br[i] = pt[PTE_System] ? ld_dword(pt + PTE_StLba) : 0;
}
i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */
if (i != 0) i--;
do { /* Find an FAT volume */
bsect = br[i];
fmt = bsect ? check_fs(fs, bsect) : 3; /* Check the partition */
} while (LD2PT(vol) == 0 && fmt >= 2 && ++i < 4);
}
if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */
if (fmt >= 2) return FR_NO_FILESYSTEM; /* No FAT volume is found */

 

Drilling down further it is check_fs() that returns 2. Meaning it found a BS, but not a FAT one, despite there really being a FAT filesystem.

 

from check_fs()

if (fs->win[BS_JmpBoot] == 0xE9 || fs->win[BS_JmpBoot] == 0xEB || fs->win[BS_JmpBoot] == 0xE8) { /* Valid JumpBoot code? */
if (!mem_cmp(fs->win + BS_FilSysType, "FAT", 3)) return 0; /* Is it an FAT VBR? */
if (!mem_cmp(fs->win + BS_FilSysType32, "FAT32", 5)) return 0; /* Is it an FAT32 VBR? */
}
return 2; /* Valid BS but not FAT */

 

The bytes associated with the filesystem types are the index positions as follows:

 

#define BS_FilSysType 54 /* Filesystem type string (8-byte) */

#define BS_FilSysType32 82 /* FAT32: Filesystem type string (8-byte) */

 

However, when inspecting what fs->win contains at runtime these positions are 0s.

This issue does not occur when I move up to a 4GB SD card. And every great once in a while a 2GB card will return with a valid FAT. Indicating, perhaps, the issue doesn't lie with ff.c but the lower level NXP driver fetching bits via SPI ... ???

Outcomes