Discussion:
Re: SD Card 16GB size is not reported correctly
(too old to reply)
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-12-14 18:24:31 UTC
Permalink
Greg,

According with this CSD decoder:
http://goughlui.com/static/csdecode2.htm the csize should be 0x0073a7
instead of 0x005b59 see:

Decoded Result:

CSD Structure: describes version of CSD structure

0b01 [Interpreted: Version 2.0 SDHC]
Data Read Access Time 1: defines Asynchronous part of the read access time

0x0e [Interpreted: 1.0 x 1ms]
Data Read Access Time 2: worst case clock dependent factor for data access time

0x00 [Decimal: 0 x 100 Clocks]
Max Data Transfer Rate: sometimes stated as Mhz

0x32 [Interpreted: 2.5 x 10Mbit/s]
Card Command Classes:

0x5b5 [Interpreted: Class 0: Yes. Class 1: No. Class 2: Yes. Class 3:
No. Class 4: Yes. Class 5: Yes. Class 6: No. Class 7: Yes. Class 8:
Yes. Class 9: No. Class 10: Yes. Class 11: No. ]
Max Read Data Block Length:

0x9 [Interpreted: 512 Bytes]
Partial Blocks for Read Allowed:

0b0 [Interpreted: No]
Write Block Misalignment:

0b0 [Interpreted: No]
Read Block Misalignment:

0b0 [Interpreted: No]
DSR Implemented: indicates configurable driver stage integrated on card

0b0 [Interpreted: No]
Device Size: to calculate the card capacity excl. security area
((device size + 1)* 512kbytes

0x0073a7 [Decimal: 29607]
Erase Single Block Enabled:

0x1 [Interpreted: Yes]
Erase Sector Size: size of erasable sector in write blocks

0x7f [Interpreted: 128 blocks]
Write Protect Group Size:

0x7f [Interpreted: 128 sectors]
Write Protect Group Enable:

0x0 [Interpreted: No]
Write Speed Factor: block program time as multiple of read access time

0x2 [Interpreted: x4]
Max Write Data Block Length:

0x9 [Interpreted: 512 Bytes]
Partial Blocks for Write Allowed:

0x0 [Interpreted: No]
File Format Group:

0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT
without Partition Table/Universal File Format/Other/Unknown]
Copy Flag:

0b0 [Interpreted: Original]
Permanent Write Protection:

0b0 [Interpreted: No]
Temporary Write Protection:

0b0 [Interpreted: No]
File Format:

0x0 [Interpreted: Hard Disk with Partition Table]
CRC7 Checksum + always 1 in LSB:0x01

(29607+1) * 512KB = 15523119104 => 15523119104 / 1024 = 15159296 KB

This is exactly the value reported by Linux.

I think it should consider the bit 0 as the MSB:

40 0e 00 32 5b 59 000073a7 7f 80 0a 40 00 01

Do you agree?

BR,

Alan
Hi Greg,
I'm trying to use a 16GB SD Card with the driver I'm writing, but I
noted that the default way to get the card size is not working for my
SDCard.
lpc43_recvlong: Entry!
lpc43_recvlong: rlong[0] = 0a4000eb
lpc43_recvlong: rlong[1] = 73a77f80
lpc43_recvlong: rlong[2] = 5b590000
lpc43_recvlong: rlong[3] = 400e0032
mmcsd_decodeCSD: CSD_STRUCTURE: 0 SPEC_VERS: 2 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 0 TIME_VALUE: 8} NSAC: 0
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 3 TIME_VALUE: 13}
mmcsd_decodeCSD: CCC: 1850
mmcsd_decodeCSD: READ_BL_LEN: 7 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 1 READ_BLK_MISALIGN: 1
mmcsd_decodeCSD: DSR_IMP: 1
mmcsd_decodeCSD: C_SIZE: 23385 SD_ER_BLK_EN: 0
mmcsd_decodeCSD: SD_SECTOR_SIZE: 0 SD_WP_GRP_SIZE: 0
mmcsd_decodeCSD: WP_GRP_EN: 0 MMC DFLT_ECC: 2 (MMC) R2W_FACTOR: 0
mmcsd_decodeCSD: WRITE_BL_LEN: 0 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 0
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 25
23947264 wrprotect: 0
(96:127)
rlong[0] = 0a400001
(64:95)
rlong[1] = 73a77f80
(32:63)
rlong[2] = 5b590000
(0:31)
rlong[3] = 400e0032
uint32_t csize = ((csd[1] & 0x3f) << 16) | (csd[2] >> 16);
priv->capacity = ((uint64_t)(csize + 1)) << 19;
csize = 0x5b59 = 23385
Calculating: (23385 + 1) * 512KB = 12260999168 => 12260999168 / 1024 =
11973632 KB !
Then I compared this CSD with the CSD returned by Linux for this card
$ cat /sys/class/mmc_host/mmc0/mmc0\:0007/csd
400e00325b59000073a77f800a400001
$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14,5 GiB, 15523119104 bytes, 30318592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 30318591 30310400 14,5G c W95 FAT32 (LBA)
I think Linux is using some other way to detect the card size.
What do you think?
BR,
Alan
Gregory Nutt spudarnia@yahoo.com [nuttx]
2016-12-14 18:40:05 UTC
Permalink
The logic needs to follow the specification. I sent you a reference.
Please read the spec, if the code is wrong, then it should be fixed. I
would not accept a specification changes based only on a comparison to
someone's code. It needs to be based on the content of the specification.
Post by Alan Carvalho de Assis ***@gmail.com [nuttx]
Greg,
http://goughlui.com/static/csdecode2.htm the csize should be 0x0073a7
CSD Structure: describes version of CSD structure
0b01 [Interpreted: Version 2.0 SDHC]
Data Read Access Time 1: defines Asynchronous part of the read access time
0x0e [Interpreted: 1.0 x 1ms]
Data Read Access Time 2: worst case clock dependent factor for data access time
0x00 [Decimal: 0 x 100 Clocks]
Max Data Transfer Rate: sometimes stated as Mhz
0x32 [Interpreted: 2.5 x 10Mbit/s]
Yes. Class 9: No. Class 10: Yes. Class 11: No. ]
0x9 [Interpreted: 512 Bytes]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
DSR Implemented: indicates configurable driver stage integrated on card
0b0 [Interpreted: No]
Device Size: to calculate the card capacity excl. security area
((device size + 1)* 512kbytes
0x0073a7 [Decimal: 29607]
0x1 [Interpreted: Yes]
Erase Sector Size: size of erasable sector in write blocks
0x7f [Interpreted: 128 blocks]
0x7f [Interpreted: 128 sectors]
0x0 [Interpreted: No]
Write Speed Factor: block program time as multiple of read access time
0x2 [Interpreted: x4]
0x9 [Interpreted: 512 Bytes]
0x0 [Interpreted: No]
0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT
without Partition Table/Universal File Format/Other/Unknown]
0b0 [Interpreted: Original]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
0x0 [Interpreted: Hard Disk with Partition Table]
CRC7 Checksum + always 1 in LSB:0x01
(29607+1) * 512KB = 15523119104 => 15523119104 / 1024 = 15159296 KB
This is exactly the value reported by Linux.
40 0e 00 32 5b 59 000073a7 7f 80 0a 40 00 01
Do you agree?
BR,
Alan
Hi Greg,
I'm trying to use a 16GB SD Card with the driver I'm writing, but I
noted that the default way to get the card size is not working for my
SDCard.
lpc43_recvlong: Entry!
lpc43_recvlong: rlong[0] = 0a4000eb
lpc43_recvlong: rlong[1] = 73a77f80
lpc43_recvlong: rlong[2] = 5b590000
lpc43_recvlong: rlong[3] = 400e0032
mmcsd_decodeCSD: CSD_STRUCTURE: 0 SPEC_VERS: 2 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 0 TIME_VALUE: 8} NSAC: 0
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 3 TIME_VALUE: 13}
mmcsd_decodeCSD: CCC: 1850
mmcsd_decodeCSD: READ_BL_LEN: 7 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 1 READ_BLK_MISALIGN: 1
mmcsd_decodeCSD: DSR_IMP: 1
mmcsd_decodeCSD: C_SIZE: 23385 SD_ER_BLK_EN: 0
mmcsd_decodeCSD: SD_SECTOR_SIZE: 0 SD_WP_GRP_SIZE: 0
mmcsd_decodeCSD: WP_GRP_EN: 0 MMC DFLT_ECC: 2 (MMC) R2W_FACTOR: 0
mmcsd_decodeCSD: WRITE_BL_LEN: 0 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 0
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 25
23947264 wrprotect: 0
(96:127)
rlong[0] = 0a400001
(64:95)
rlong[1] = 73a77f80
(32:63)
rlong[2] = 5b590000
(0:31)
rlong[3] = 400e0032
uint32_t csize = ((csd[1] & 0x3f) << 16) | (csd[2] >> 16);
priv->capacity = ((uint64_t)(csize + 1)) << 19;
csize = 0x5b59 = 23385
Calculating: (23385 + 1) * 512KB = 12260999168 => 12260999168 / 1024 =
11973632 KB !
Then I compared this CSD with the CSD returned by Linux for this card
$ cat /sys/class/mmc_host/mmc0/mmc0\:0007/csd
400e00325b59000073a77f800a400001
$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14,5 GiB, 15523119104 bytes, 30318592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 30318591 30310400 14,5G c W95 FAT32 (LBA)
I think Linux is using some other way to detect the card size.
What do you think?
BR,
Alan
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-12-14 19:02:30 UTC
Permalink
Yes, I think the mmcsd_sdio.c follows the specification, but use the
endianess in the inverse order.

I changed the order in the decodeCID too.

This is the old reported data:
mmcsd_decodeCID: mid: 93 oid: 9301 pnm: U0ᅵ] prv: 76 psn: 825640707
mdt: 54 crc: 29

This is the new reported data:
mmcsd_decodeCID: mid: 03 oid: 0350 pnm: SL16G prv: 48 psn: -636854893
mdt: 101 crc: 2a

I think it is correct now, because this is the same value reported by Linux:

$ cat /sys/class/mmc_host/mmc0/mmc0\:0007/manfid
0x000003
$ cat /sys/class/mmc_host/mmc0/mmc0\:0007/name
SL16G

I need to investigate why PSN is negative.

BR,

Alan
Post by Gregory Nutt ***@yahoo.com [nuttx]
The logic needs to follow the specification. I sent you a reference.
Please read the spec, if the code is wrong, then it should be fixed. I
would not accept a specification changes based only on a comparison to
someone's code. It needs to be based on the content of the specification.
Post by Alan Carvalho de Assis ***@gmail.com [nuttx]
Greg,
http://goughlui.com/static/csdecode2.htm the csize should be 0x0073a7
CSD Structure: describes version of CSD structure
0b01 [Interpreted: Version 2.0 SDHC]
Data Read Access Time 1: defines Asynchronous part of the read access time
0x0e [Interpreted: 1.0 x 1ms]
Data Read Access Time 2: worst case clock dependent factor for data access time
0x00 [Decimal: 0 x 100 Clocks]
Max Data Transfer Rate: sometimes stated as Mhz
0x32 [Interpreted: 2.5 x 10Mbit/s]
Yes. Class 9: No. Class 10: Yes. Class 11: No. ]
0x9 [Interpreted: 512 Bytes]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
DSR Implemented: indicates configurable driver stage integrated on card
0b0 [Interpreted: No]
Device Size: to calculate the card capacity excl. security area
((device size + 1)* 512kbytes
0x0073a7 [Decimal: 29607]
0x1 [Interpreted: Yes]
Erase Sector Size: size of erasable sector in write blocks
0x7f [Interpreted: 128 blocks]
0x7f [Interpreted: 128 sectors]
0x0 [Interpreted: No]
Write Speed Factor: block program time as multiple of read access time
0x2 [Interpreted: x4]
0x9 [Interpreted: 512 Bytes]
0x0 [Interpreted: No]
0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT
without Partition Table/Universal File Format/Other/Unknown]
0b0 [Interpreted: Original]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
0x0 [Interpreted: Hard Disk with Partition Table]
CRC7 Checksum + always 1 in LSB:0x01
(29607+1) * 512KB = 15523119104 => 15523119104 / 1024 = 15159296 KB
This is exactly the value reported by Linux.
40 0e 00 32 5b 59 000073a7 7f 80 0a 40 00 01
Do you agree?
BR,
Alan
Hi Greg,
I'm trying to use a 16GB SD Card with the driver I'm writing, but I
noted that the default way to get the card size is not working for my
SDCard.
lpc43_recvlong: Entry!
lpc43_recvlong: rlong[0] = 0a4000eb
lpc43_recvlong: rlong[1] = 73a77f80
lpc43_recvlong: rlong[2] = 5b590000
lpc43_recvlong: rlong[3] = 400e0032
mmcsd_decodeCSD: CSD_STRUCTURE: 0 SPEC_VERS: 2 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 0 TIME_VALUE: 8} NSAC: 0
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 3 TIME_VALUE: 13}
mmcsd_decodeCSD: CCC: 1850
mmcsd_decodeCSD: READ_BL_LEN: 7 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 1 READ_BLK_MISALIGN: 1
mmcsd_decodeCSD: DSR_IMP: 1
mmcsd_decodeCSD: C_SIZE: 23385 SD_ER_BLK_EN: 0
mmcsd_decodeCSD: SD_SECTOR_SIZE: 0 SD_WP_GRP_SIZE: 0
mmcsd_decodeCSD: WP_GRP_EN: 0 MMC DFLT_ECC: 2 (MMC) R2W_FACTOR: 0
mmcsd_decodeCSD: WRITE_BL_LEN: 0 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 0
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 25
23947264 wrprotect: 0
(96:127)
rlong[0] = 0a400001
(64:95)
rlong[1] = 73a77f80
(32:63)
rlong[2] = 5b590000
(0:31)
rlong[3] = 400e0032
uint32_t csize = ((csd[1] & 0x3f) << 16) | (csd[2] >> 16);
priv->capacity = ((uint64_t)(csize + 1)) << 19;
csize = 0x5b59 = 23385
Calculating: (23385 + 1) * 512KB = 12260999168 => 12260999168 / 1024 =
11973632 KB !
Then I compared this CSD with the CSD returned by Linux for this card
$ cat /sys/class/mmc_host/mmc0/mmc0\:0007/csd
400e00325b59000073a77f800a400001
$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14,5 GiB, 15523119104 bytes, 30318592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 30318591 30310400 14,5G c W95 FAT32 (LBA)
I think Linux is using some other way to detect the card size.
What do you think?
BR,
Alan
pn_bouteville@yahoo.fr [nuttx]
2017-02-27 22:02:08 UTC
Permalink
Hi Alan,

I have also a problem with 16Gb SDCARD (with STM32), I cannot format fat32.


ERR[ 31.420000]mkfatfs_tryfat32: ERROR: Too few or too many clusters for FAT32: 65524 < 62175 < 62205
ERR[ 31.430000]mkfatfs_clustersearch: ERROR: Cannot format FAT32 at 32 sectors/cluster
ERR[ 31.430000]mkfatfs_tryfat32: ERROR: Too few or too many clusters for FAT32: 65524 < 31094 < 31101
ERR[ 31.430000]mkfatfs_clustersearch: ERROR: Cannot format FAT32 at 64 sectors/cluster
ERR[ 31.430000]mkfatfs_tryfat32: ERROR: Too few or too many clusters for FAT32: 65524 < 15548 < 15613
ERR[ 31.430000]mkfatfs_clustersearch: ERROR: Cannot format FAT32 at 128 sectors/cluster
ERR[ 31.440000]mkfatfs_configfatfs: ERROR: Failed to set cluster size
ERR[ 31.440000]Error SDCARD : Formatage Impossible!. (errno:1:Operation not permitted)


pierre
pn_bouteville@yahoo.fr [nuttx]
2017-02-27 22:06:40 UTC
Permalink
Hi Alan,

sorry it not a 16GB but a 1GB.


pierre
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2017-02-27 23:54:14 UTC
Permalink
Hi Pierre,

I just tested an 1GB card on STM32F103 (spoiler alert: "next video
tutorial!") and it worked fine.

Use another card or try to format this card again.

BR,

Alan
Post by ***@yahoo.fr [nuttx]
Hi Alan,
sorry it not a 16GB but a 1GB.
pierre
pn_bouteville@yahoo.fr [nuttx]
2017-02-28 12:51:07 UTC
Permalink
Hi Alan,

I try both 4GB all is ok but both 1GB it failed.


And something is wring in message log : Too few or too many clusters for FAT32: 65524 < 62176 < 62205
this is impossible.


I continue investigation, but did you have some log ?


My Code:


struct fat_format_s fmt = FAT_FORMAT_INITIALIZER;
fmt.ff_fattype = 32;
strncpy((char*)fmt.ff_volumelabel,"PNBChrono",
sizeof(fmt.ff_volumelabel)/sizeof(fmt.ff_volumelabel[0])
); /* Volume label */
ret = mkfatfs("/dev/mmcsd0",&fmt);


And Log:


INF[ 17.130000]mmcsd_open: Entry
INF[ 17.140000]mmcsd_geometry: Entry
INF[ 17.140000]mmcsd_geometry: available: true mediachanged: false writeenabled: true
INF[ 17.140000]mmcsd_geometry: nsectors: 1990656 sectorsize: 512
INF[ 17.140000]mkfatfs_clustersearch: Configuring with 32 sectors/cluster...
INF[ 17.140000]mkfatfs_tryfat32: nfatsects=486 nclusters=62176 (max=62208)
ERR[ 17.140000]mkfatfs_tryfat32: ERROR: Too few or too many clusters for FAT32: 65524 < 62176 < 62205



Pierre


Ps I don't think that is important but:
4GB is MicroSDHC Class4
1GB is MicroSD
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2017-02-28 14:01:30 UTC
Permalink
Hi Pierre,

I don't have saved log, but I can create it for you.

A side note: I'm using SDCard over SPI (mmcsd_spi.c) with this 1GB, I
need to test it on LPC4330 with native SD/MMC controller to confirm.

BR,

Alan
Post by ***@yahoo.fr [nuttx]
Hi Alan,
I try both 4GB all is ok but both 1GB it failed.
And something is wring in message log : Too few or too many clusters for
FAT32: 65524 < 62176 < 62205
this is impossible.
I continue investigation, but did you have some log ?
struct fat_format_s fmt = FAT_FORMAT_INITIALIZER;
fmt.ff_fattype = 32;
strncpy((char*)fmt.ff_volumelabel,"PNBChrono",
sizeof(fmt.ff_volumelabel)/sizeof(fmt.ff_volumelabel[0])
); /* Volume label */
ret = mkfatfs("/dev/mmcsd0",&fmt);
INF[ 17.130000]mmcsd_open: Entry
INF[ 17.140000]mmcsd_geometry: Entry
INF[ 17.140000]mmcsd_geometry: available: true mediachanged: false writeenabled: true
INF[ 17.140000]mmcsd_geometry: nsectors: 1990656 sectorsize: 512
INF[ 17.140000]mkfatfs_clustersearch: Configuring with 32
sectors/cluster...
INF[ 17.140000]mkfatfs_tryfat32: nfatsects=486 nclusters=62176 (max=62208)
ERR[ 17.140000]mkfatfs_tryfat32: ERROR: Too few or too many clusters for
FAT32: 65524 < 62176 < 62205
Pierre
4GB is MicroSDHC Class4
1GB is MicroSD
pn_bouteville@yahoo.fr [nuttx]
2017-03-01 11:35:23 UTC
Permalink
Hi Alan,

I will be happy to have your log especially log when your SDcard is mounted like this:
INF[ 0.830000]fat_mount: FAT16:
INF[ 0.830000]fat_mount: HW sector size: 512
INF[ 0.830000]fat_mount: sectors: 1990656
INF[ 0.830000]fat_mount: FAT reserved: 32
INF[ 0.830000]fat_mount: sectors: 1990656
INF[ 0.840000]fat_mount: start sector: 32
INF[ 0.840000]fat_mount: root sector: 1004
INF[ 0.840000]fat_mount: root entries: 0
INF[ 0.840000]fat_mount: data sector: 1004
INF[ 0.840000]fat_mount: FSINFO sector: 0
INF[ 0.840000]fat_mount: Num FATs: 2
INF[ 0.840000]fat_mount: FAT sectors: 486
INF[ 0.840000]fat_mount: sectors/cluster: 32
INF[ 0.850000]fat_mount: max clusters: 62176
INF[ 0.850000]fat_mount: FSI free count -1
INF[ 0.850000]fat_mount: next free 0

Pierre
pn_bouteville@yahoo.fr [nuttx]
2017-03-01 12:41:59 UTC
Permalink
Hi Alan,

I solve my problem by changing:
fmt.ff_fattype = 32;

in
fmt.ff_fattype = 0;



So a supose that is not possible to format in FAT32 a 1GB SDCard but in FAT16.


Pierre
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2017-03-01 16:26:20 UTC
Permalink
Hi Pierre,

Thanks for report it!

Normally I format my SD Card in the Ubuntu and select the option to be
compatible with all windows versions. Then when it is plugged in the
Linux it is reported as type "msdos".

Hmm, maybe the type of FAT format could be auto-detected before
mounting the card...

BR,

Alan
Post by ***@yahoo.fr [nuttx]
Hi Alan,
fmt.ff_fattype = 32;
in
fmt.ff_fattype = 0;
So a supose that is not possible to format in FAT32 a 1GB SDCard but in FAT16.
Pierre
pn_bouteville@yahoo.fr [nuttx]
2017-02-27 22:22:49 UTC
Permalink
Hi Alan,

You can see in attachment log with 4 SDCARD 2 of 1GB and 2 with 4GB.


Pierre
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2016-12-14 18:41:05 UTC
Permalink
Just replacing:

- uint32_t csize = ((csd[1] & 0x3f) << 16) |
(csd[2] >> 16);
+ uint32_t csize = ((csd[2] & 0x3f) << 16) |
(csd[1] >> 16);

fixed the issue:

mmcsd_decodeCSD: Capacity: 15159296Kb, Block size: 512b, nblocks:
30318592 wrprotect: 0

BR,

Alan
Post by Alan Carvalho de Assis ***@gmail.com [nuttx]
Greg,
http://goughlui.com/static/csdecode2.htm the csize should be 0x0073a7
CSD Structure: describes version of CSD structure
0b01 [Interpreted: Version 2.0 SDHC]
Data Read Access Time 1: defines Asynchronous part of the read access time
0x0e [Interpreted: 1.0 x 1ms]
Data Read Access Time 2: worst case clock dependent factor for data access time
0x00 [Decimal: 0 x 100 Clocks]
Max Data Transfer Rate: sometimes stated as Mhz
0x32 [Interpreted: 2.5 x 10Mbit/s]
Yes. Class 9: No. Class 10: Yes. Class 11: No. ]
0x9 [Interpreted: 512 Bytes]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
DSR Implemented: indicates configurable driver stage integrated on card
0b0 [Interpreted: No]
Device Size: to calculate the card capacity excl. security area
((device size + 1)* 512kbytes
0x0073a7 [Decimal: 29607]
0x1 [Interpreted: Yes]
Erase Sector Size: size of erasable sector in write blocks
0x7f [Interpreted: 128 blocks]
0x7f [Interpreted: 128 sectors]
0x0 [Interpreted: No]
Write Speed Factor: block program time as multiple of read access time
0x2 [Interpreted: x4]
0x9 [Interpreted: 512 Bytes]
0x0 [Interpreted: No]
0b0 [Interpreted: is either Hard Disk with Partition Table/DOS FAT
without Partition Table/Universal File Format/Other/Unknown]
0b0 [Interpreted: Original]
0b0 [Interpreted: No]
0b0 [Interpreted: No]
0x0 [Interpreted: Hard Disk with Partition Table]
CRC7 Checksum + always 1 in LSB:0x01
(29607+1) * 512KB = 15523119104 => 15523119104 / 1024 = 15159296 KB
This is exactly the value reported by Linux.
40 0e 00 32 5b 59 000073a7 7f 80 0a 40 00 01
Do you agree?
BR,
Alan
Hi Greg,
I'm trying to use a 16GB SD Card with the driver I'm writing, but I
noted that the default way to get the card size is not working for my
SDCard.
lpc43_recvlong: Entry!
lpc43_recvlong: rlong[0] = 0a4000eb
lpc43_recvlong: rlong[1] = 73a77f80
lpc43_recvlong: rlong[2] = 5b590000
lpc43_recvlong: rlong[3] = 400e0032
mmcsd_decodeCSD: CSD_STRUCTURE: 0 SPEC_VERS: 2 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 0 TIME_VALUE: 8} NSAC: 0
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 3 TIME_VALUE: 13}
mmcsd_decodeCSD: CCC: 1850
mmcsd_decodeCSD: READ_BL_LEN: 7 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 1 READ_BLK_MISALIGN: 1
mmcsd_decodeCSD: DSR_IMP: 1
mmcsd_decodeCSD: C_SIZE: 23385 SD_ER_BLK_EN: 0
mmcsd_decodeCSD: SD_SECTOR_SIZE: 0 SD_WP_GRP_SIZE: 0
mmcsd_decodeCSD: WP_GRP_EN: 0 MMC DFLT_ECC: 2 (MMC) R2W_FACTOR: 0
mmcsd_decodeCSD: WRITE_BL_LEN: 0 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 0
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 25
23947264 wrprotect: 0
(96:127)
rlong[0] = 0a400001
(64:95)
rlong[1] = 73a77f80
(32:63)
rlong[2] = 5b590000
(0:31)
rlong[3] = 400e0032
uint32_t csize = ((csd[1] & 0x3f) << 16) | (csd[2] >> 16);
priv->capacity = ((uint64_t)(csize + 1)) << 19;
csize = 0x5b59 = 23385
Calculating: (23385 + 1) * 512KB = 12260999168 => 12260999168 / 1024 =
11973632 KB !
Then I compared this CSD with the CSD returned by Linux for this card
$ cat /sys/class/mmc_host/mmc0/mmc0\:0007/csd
400e00325b59000073a77f800a400001
$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14,5 GiB, 15523119104 bytes, 30318592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 30318591 30310400 14,5G c W95 FAT32 (LBA)
I think Linux is using some other way to detect the card size.
What do you think?
BR,
Alan
Loading...