Commit Graph

23 Commits

Author SHA1 Message Date
Damien George
ee9feacc00 drivers/sdcard: Fix address calculation on v2 SDSC cards.
For v2 cards that are standard capacity the read/write/erase commands take
byte address values.  Use the result of CMD58 to distinguish SDSC from
SDHC/SDXC.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-10 12:56:31 +10:00
Damien George
203b98c42b drivers/sdcard: Make ioctl(4), ioctl(5) return num blocks, block size.
For CSD v1.0 the computed size is in bytes, so convert it to number of
512-byte blocks, and then ioctl(4) will return the correct value.

Also implement ioctl(5) to return the block size, which is always 512.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-10 12:56:30 +10:00
Yukai Li
ab6ad86793 drivers/sdcard: Fix CSD version 1.0 device size calculation.
Signed-off-by: Yukai Li <yukaili.geek@gmail.com>
2022-06-10 12:56:15 +10:00
robert-hh
9c05f3aa1d drivers/sdcard: Allow setting the final SPI baudrate.
This baudrate is supplied in the constructor. The default is 1320000 as
before.

Example:

    sd = sdcard.SDCard(spi, cs, baudrate=20_000_000)
2022-02-18 14:37:44 +11:00
Damien George
a1bc32d8a8 drivers/sdcard: Add sleep_ms(1) delay in SDCard.readinto sync loop.
So this driver works on faster MCUs (that run this loop fast) with older,
slower SD cards.

Fixes issue #7129.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-23 23:44:37 +10:00
Damien George
69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Jeremy Herbert
4f0f3dfb41 drivers/sdcard: Raise exception on timeout of readinto.
Otherwise the code can get stuck in an infinite loop if the SD card fails
to respond to a read.
2019-11-06 11:34:02 +11:00
Peter Hinch
40a7e8c472 drivers/sdcard: Remove debugging print statement in ioctl method. 2018-09-20 16:54:58 +10:00
Mateusz Kijowski
1751f5ac7b drivers/sdcard: Do not release CS during the middle of read operations.
It seems that some cards do not tolerate releasing the card (by setting CS
high) after issuing CMD17 (and 18) and raising it again before reading
data. Somehow this causes the 0xfe data start marker not being read and
SDCard.readinto() is spinning forever (or until this byte is in the data).

This seems to fix weird behviour of SDCard.readblocks() returning different
data, also solved hanging os.mount() for my case with a 16GB Infineon card.

This stackexchange answer gives more context:
https://electronics.stackexchange.com/questions/307214/sd-card-spi-interface-issue-read-operation-returns-0x3f-0xff-instead-of-0x7f-0#307268
2018-07-05 19:39:06 +10:00
Damien George
1747d15c3a drivers/sdcard: Fix bug in computing number of sectors on SD Card.
This was a typo from the very first commit of this file.
2018-06-15 18:02:40 +10:00
Damien George
8b8c083625 drivers/sdcard: Change driver to use new block-device protocol. 2018-06-15 18:01:36 +10:00
Damien George
3759aa2cc9 drivers/sdcard: Update SD mounting example code for ESP8266. 2018-02-18 23:40:54 +11:00
Hemanth kumar
a44892dd0d drivers/sdcard: Update doc for ESP8266 to use correct SPI number.
machine.SPI(0) results in ValueError on ESP8266.  SPI(1) is the user
hardware SPI port (or use SPI(-1) for software SPI).
2018-01-31 21:25:58 +11:00
Ayke van Laethem
a275cb0f48 drivers/sdcard: Avoid allocation on the heap.
This commit fixes two things:
 1. Do not allocate on the heap in readblocks() - unless the block size
    is bigger than 512 bytes.
 2. Raise an error instead of returning 1 to indicate an error: the FAT
    block device layer does not check the return value. And other
    backends (e.g. esp32 blockdev) also raise an error instead of
    returning non-zero.
2018-01-10 19:14:46 +11:00
Ayke van Laethem
b90f51f86a drivers/sdcard: Support old SD cards (<=2GB). 2017-12-22 16:49:58 +11:00
Alexander Steffen
55f33240f3 all: Use the name MicroPython consistently in comments
There were several different spellings of MicroPython present in comments,
when there should be only one.
2017-07-31 18:35:40 +10:00
Paul Sokolovsky
1c9ee49756 drivers: Replace deprecated Pin.high()/low() methods with .__call__(1/0). 2017-05-21 17:44:58 +03:00
Mike Causer
c5310ee5b5 drivers: Fix some minor spelling mistakes.
respones -> response
succeses -> successes
2017-01-18 15:31:05 +11:00
Damien George
7bb0f7b0f6 drivers: Add "from micropython import const" when const is used.
Following best-practice use of the const feature, to make it compatible
with Python.
2016-11-03 12:41:11 +11:00
Radomir Dopieralski
ce1c786297 drivers/sdcard: Port the SDCard driver to new machine API.
With backwards compatibility for pyboard.
2016-09-01 17:44:07 +10:00
Peter Hinch
2bd758fe96 drivers/sdcard: Add support for multi-block read/write; add SD test. 2016-02-02 11:16:15 +00:00
Damien George
24652228af drivers/sdcard: Allow up to 5 retries to initialise SD card.
Apparently some cards need more than 2 retries.  See issue #1482.
2015-10-10 00:07:40 +01:00
Damien George
1570eaf0e3 drivers: Add SD card driver, controlled via SPI bus. 2014-12-27 20:23:14 +00:00