micropython/micropython — pull request #849 by tmbinc (2014-09-09 09:58:12+00:00)
Title: SDHC support

SDHC support is lacking in 3 different areas:

1.) the capacity reported by HAL_SD_Get_CardInfo is truncated to 32-bit
2.) sdcard_read_blocks/sdcard_write_blocks is truncating the byte address to 32-bit
3.) the msc usb class is truncating the read pointer to 32-bit

Unfortunately this naive fix requires 64-bit udivmod support, which I grabbed from libaeabi-cortexm0, which is thankfully published under a compatible license. I also added pyb.SD.write for completeness. (Not sure if absence was intentional)

A better fix may be replacing some of the multiplications within the MSC USB class with shifts, but I wanted to keep this patch as simple as possible.

Test:
1. Custom test to write a bunch of sectors with pseudo-random data over full capacity using pyb.SD.write, and then reading them back via pyb.SD.read, make sure that writes don't alias (when address is truncated); this is to test hal_sd etc.
2. Same test from PC via mass storage.
3. Same test (only read) from PC via commercial microSD reader.

Limitations:
1. Number of blocks may still be limited to 32-bit in a number of places; this creates a 2TB limit. Not an issue for SDHC.
2. Performance isn't optimal because of 64-bit multiplications; should not matter since limiting factor is very likely USB FS speed.