]> sigrok.org Git - libsigrokdecode.git/blob - decoders/sdcard_spi/__init__.py
All PDs: Only import the 'Decoder' object.
[libsigrokdecode.git] / decoders / sdcard_spi / __init__.py
1 ##
2 ## This file is part of the libsigrokdecode project.
3 ##
4 ## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
10 ##
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ## GNU General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19 ##
20
21 '''
22 This decoder stacks on top of the 'spi' PD and decodes the SD card
23 (SPI mode) low-level protocol.
24
25 Most SD cards can be accessed via two different protocols/modes: SD mode
26 or SPI mode.
27
28 All SD cards are in SD mode upon powerup. They can be switched to SPI mode
29 using a special method involving CMD0 (see spec). Once in SPI mode, the mode
30 can no longer be changed without a power-cycle of the card.
31
32 SPI mode properties (differences to SD mode):
33  * The 'sdcard_spi' PD stacks on top of the 'spi' PD. This is not possible
34    for the 'sdcard_sd' PD, as that protocol is not SPI related at all.
35    Hence 'sdcard_spi' and 'sdcard_sd' are two separate PDs.
36  * The state machines for SPI mode and SD mode are different.
37  * In SPI mode, data transfers are byte-oriented (commands/data are multiples
38    of 8 bits, with the CS# pin asserted respectively), unlike SD mode where
39    commands/data are bit-oriented with parallel transmission of 1 or 4 bits.
40  * While the SPI mode command set has some commands in common with the
41    SD mode command set, they are not the same and also not a subset/superset.
42    Some commands are only available in SD mode (e.g. CMD2), some only
43    in SPI mode (e.g. CMD1).
44  * Response types of commands also differ between SD mode and SPI mode.
45    E.g. CMD9 has an R2 response in SD mode, but R1 in SPI mode.
46  * The commands and functions in SD mode defined after version 2.00 of the
47    spec are NOT supported in SPI mode.
48  * SPI mode: The selected SD card ALWAYS responds to commands (unlike SD mode).
49  * Upon data retrieval problems (read operations) the card will respond with
50    an error response (and no data), as opposed to a timeout in SD mode.
51  * SPI mode: For every data block sent to the card (write operations) the host
52    gets a data response token from the card.
53  * SDSC: A data block can be max. one card write block, min. 1 byte.
54  * SDHC/SDXC: Block length is fixed to 512. The block length set by CMD16
55    is only used for CDM42 (not for memory data transfers). Thus, partial
56    read/write operations are disabled in SPI mode.
57  * SPI mode: Write protected commands (CMD28, CMD29, CMD30) are not supported.
58  * The SD mode state machine is NOT used. All commands that are supported
59    in SPI mode are always available.
60  * Per default the card is in CRC OFF mode. Exception: CMD0 (which is used to
61    switch to SPI mode) needs a valid CRC.
62  * The APP_CMD status bit is not available in SPI mode.
63  * TODO: Switch function command differences.
64  * In SPI mode cards cannot guarantee their speed class (the host should
65    assume class 0, no matter what the card indicates).
66  * The RCA register is not accessible in SPI mode.
67 '''
68
69 from .pd import Decoder