Discussion:
wrong mmcsd_geometry reported for SD card > 4 GB
(too old to reply)
mrechte2@yahoo.com [nuttx]
2017-02-03 12:35:57 UTC
Permalink
Hello,

In the course of perapring a TWR-K64F120M config, I am facing what looks like an overflow problem with a 8 GB SD card:

mmcsd_decodeCSD: Capacity: 30720Kb, Block size: 512b, nblocks: 61440 wrprotect: 0

Digging code mmcsd_sdio.c:143 capacity is defined as an uint32_t.

.config (inherited from TWR-K60N512) does not have CONFIG_HAVE_LONG_LONG defined.

1) could we produce a warning when such overflow occurs ?
2) do we have to define CONFIG_HAVE_LONG_LONG ?

Thanks
spudarnia@yahoo.com [nuttx]
2017-02-03 13:10:05 UTC
Permalink
Yes, to use volumes larger than 4Gb, you must have CONFIG_HAVE_LONG_LONG defined.


That that is misnamed. It is not a configuration option. It is defined in include/nuttx/compiler.h depending upon the toolchain that you are using.


What toolchain are using? It is defined for GCC only.


Greg
mrechte2@yahoo.com [nuttx]
2017-02-03 13:50:08 UTC
Permalink
OK that is why I could not find it, actually it is defined (gcc toolchain). The problem is somewhere else.

csize is computed as 59 (x3b) which seems consistent with CSD reported (bits 48:69):

(gdb) p/x csd[0]
$3 = 0x400e00
(gdb) p/x csd[1]
$5 = 0x325b5900
(gdb) p/x csd[2]
$6 = 0x3b377f
(gdb) p/x csd[3]
$7 = 0x800a4040

This is the debug output:
mmcsd_decodeCSD: CSD:
mmcsd_decodeCSD: CSD_STRUCTURE: 0 SPEC_VERS: 0 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 0 TIME_VALUE: 8} NSAC: 14
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 0 TIME_VALUE: 0}
mmcsd_decodeCSD: CCC: 805
mmcsd_decodeCSD: READ_BL_LEN: 11 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 1 READ_BLK_MISALIGN: 0
mmcsd_decodeCSD: DSR_IMP: 1
mmcsd_decodeCSD: SD Block Addressing:
mmcsd_decodeCSD: C_SIZE: 59 SD_ER_BLK_EN: 0
mmcsd_decodeCSD: SD_SECTOR_SIZE: 110 SD_WP_GRP_SIZE: 127
mmcsd_decodeCSD: WP_GRP_EN: 1 MMC DFLT_ECC: 0 (MMC) R2W_FACTOR: 0
mmcsd_decodeCSD: WRITE_BL_LEN: 0 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 1
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 32
mmcsd_decodeCSD: Capacity: 30720Kb, Block size: 512b, nblocks: 61440 wrprotect: 0

Marc
spudarnia@yahoo.com [nuttx]
2017-02-03 14:19:14 UTC
Permalink
Post by ***@yahoo.com [nuttx]
mmcsd_decodeCSD: CSD_STRUCTURE: 0 SPEC_VERS: 0 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 0 TIME_VALUE: 8} NSAC: 14
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 0 TIME_VALUE: 0}
mmcsd_decodeCSD: CCC: 805
mmcsd_decodeCSD: READ_BL_LEN: 11 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 1 READ_BLK_MISALIGN: 0
mmcsd_decodeCSD: DSR_IMP: 1
This message means that the driver thinks this is SDv1, byte addressed card. The maximum capacity for a v1.00 SD card is 1Gb. See: https://en.wikipedia.org/wiki/Secure_Digital#SDSC_cards_above_1_GB

Notice that the block size is 11 meaning 2 << 11 or 2048. This is a fake block size and is used by v1.01 cards to handle increased capacity. The maximum capacity of a v1.01 card is 4Gb.

https://en.wikipedia.org/wiki/Secure_Digital#Storage_capacity_calculations

So something is wrong. Perhaps your 8Gb is v2 and being misidentified as v1. Or perhaps it is a v2 version not supported by the NuttX driver. SDXC is not supported, for example.
Post by ***@yahoo.com [nuttx]
mmcsd_decodeCSD: C_SIZE: 59 SD_ER_BLK_EN: 0
mmcsd_decodeCSD: SD_SECTOR_SIZE: 110 SD_WP_GRP_SIZE: 127
mmcsd_decodeCSD: WP_GRP_EN: 1 MMC DFLT_ECC: 0 (MMC) R2W_FACTOR: 0
mmcsd_decodeCSD: WRITE_BL_LEN: 0 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 1
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 32
mmcsd_decodeCSD: Capacity: 30720Kb, Block size: 512b, nblocks: 61440 wrprotect: 0
spudarnia@yahoo.com [nuttx]
2017-02-03 14:56:50 UTC
Permalink
This READLLY means SDv2 with byte addressing. I don't know why I saw this as byte addressing the first time I looked.

In this case, capacity should be:

Given c_size = 69:64 from Word 2 and 63:48 from Word 3
capacity = (csize + 1) << 19
Post by ***@yahoo.com [nuttx]
(gdb) p/x csd[1]
$5 = 0x325b5900
(gdb) p/x csd[2]
$6 = 0x3b377f
Should have:

uint32_t csize = ((csd[1] & 0x3f) << 16) | (csd[2] >> 16);
= 59
uint64_t capacity = 60 << 19 = about 30Mb

And that is what is reported.

My confusion, sorry.
Greg
mrechte2@yahoo.com [nuttx]
2017-02-04 19:06:33 UTC
Permalink
Thanks. I discovered a problem in the kinetis driver. After correcting it, the 8GB size is reported OK. Things get wrong again at a later stage in mmcsd_getSCR).

If I disable DMA mode, then I succeed to mount the SD :)

I'll have to investigate the issue with DMA (any clue is welcome !!!)

This is the console with CONFIG_SDIO_DMA set:

mmcsd_decodeCSD: CSD:
mmcsd_decodeCSD: CSD_STRUCTURE: 1 SPEC_VERS: 0 (MMC)
mmcsd_decodeCSD: TAAC {TIME_UNIT: 6 TIME_VALUE: 1} NSAC: 0
mmcsd_decodeCSD: TRAN_SPEED {TRANSFER_RATE_UNIT: 2 TIME_VALUE: 6}
mmcsd_decodeCSD: CCC: 1461
mmcsd_decodeCSD: READ_BL_LEN: 9 READ_BL_PARTIAL: 0
mmcsd_decodeCSD: WRITE_BLK_MISALIGN: 0 READ_BLK_MISALIGN: 0
mmcsd_decodeCSD: DSR_IMP: 0
mmcsd_decodeCSD: SD Block Addressing:
mmcsd_decodeCSD: C_SIZE: 15159 SD_ER_BLK_EN: 1
mmcsd_decodeCSD: SD_SECTOR_SIZE: 127 SD_WP_GRP_SIZE: 0
mmcsd_decodeCSD: WP_GRP_EN: 0 MMC DFLT_ECC: 0 (MMC) R2W_FACTOR: 2
mmcsd_decodeCSD: WRITE_BL_LEN: 9 WRITE_BL_PARTIAL: 0
mmcsd_decodeCSD: FILE_FORMAT_GROUP: 0 COPY: 1
mmcsd_decodeCSD: PERM_WRITE_PROTECT: 0 TMP_WRITE_PROTECT: 0
mmcsd_decodeCSD: FILE_FORMAT: 0 ECC: 0 (MMC) CRC: 0
mmcsd_decodeCSD: Capacity: 7761920Kb, Block size: 512b, nblocks: 15523840 wrprotect: 0
kinetis_sendcmd: cmd: 00000087 arg: e6240000 regval: 071b0001
kinetis_clockinetis_interrupt: IRQSTAT: 100000a8 IRQSIGEN 1070013a enabled: 10000028
kinetis_interrupt: IRQSTAT: 00000082 IRQSIGEN 1070013a enabled: 00000002
k: SYSCTRL: 00002047
kinetis_clock: SYSCTRL: 0000040f
kinetis_sendcmd: cmd: 00000050 arg: 00000008 regval: 101a0001
kinetis_sendcmd: cmd: 00000077 arg: e6240000 regval: 371a0001
kinetis_sendcmd: cmd: 00000473 arg: 00000000 regval: 333a0011
kinetis_eventtimeout: ERROR: Timeout: remaining: 8
mmcsd_eventwait: ERROR: Awakened with 08
mmcsd_getSCR: ERROR: mmcsd_eventwait for READ DATA failed: -110
mmcsd_sdinitialize: ERROR: Could not get SD SCR register(-110)
sdhc_wrprotect: cdstatus: 01

Marc
alpo.leinonen@yahoo.com [nuttx]
2018-01-23 08:47:46 UTC
Permalink
I have same problem in DMA mode. Same timeout error.

Marc, are you solving the problem ?
spudarnia@yahoo.com [nuttx]
2018-01-23 12:23:56 UTC
Permalink
With known, working SDIO drivers, the problem that you describe is usually to driving the SD card with a clock that is to fast to be supported by the board.


DMA begins after basic initialization and when the bus width is increased from 1- to 4-bits and when clocking is boosted to the level specified in your board.h header file. So often it is misleading that DMA fails; sometimes the real cause of the problem is the increased SD clock frequency.


Try dropping the clock frequency for the wide SD in the board.h header file. It is a long shot, but has fixed problems like that for me in the past.
Loading...