]> sigrok.org Git - libsigrokdecode.git/blob - decoders/sdcard_spi/__init__.py
GPL headers: Use correct project name.
[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 SD card (SPI mode) low-level protocol decoder.
23
24 TODO: Description.
25
26 Most SD cards can be accessed via two different protocols/modes: SD mode
27 or SPI mode.
28
29 All SD cards are in SD mode upon powerup. They can be switched to SPI mode
30 using a special method involving CMD0 (see spec). Once in SPI mode, the mode
31 can no longer be changed without a power-cycle of the card.
32
33 SPI mode properties (differences to SD mode):
34  * The 'sdcard_spi' PD stacks on top of the 'spi' PD. This is not possible
35    for the 'sdcard_sd' PD, as that protocol is not SPI related at all.
36    Hence 'sdcard_spi' and 'sdcard_sd' are two separate PDs.
37  * The state machines for SPI mode and SD mode are different.
38  * In SPI mode, data transfers are byte-oriented (commands/data are multiples
39    of 8 bits, with the CS# pin asserted respectively), unlike SD mode where
40    commands/data are bit-oriented with parallel transmission of 1 or 4 bits.
41  * While the SPI mode command set has some commands in common with the
42    SD mode command set, they are not the same and also not a subset/superset.
43    Some commands are only available in SD mode (e.g. CMD2), some only
44    in SPI mode (e.g. CMD1).
45  * Response types of commands also differ between SD mode and SPI mode.
46    E.g. CMD9 has an R2 response in SD mode, but R1 in SPI mode.
47  * The commands and functions in SD mode defined after version 2.00 of the
48    spec are NOT supported in SPI mode.
49  * SPI mode: The selected SD card ALWAYS responds to commands (unlike SD mode).
50  * Upon data retrieval problems (read operations) the card will respond with
51    an error response (and no data), as opposed to a timeout in SD mode.
52  * SPI mode: For every data block sent to the card (write operations) the host
53    gets a data response token from the card.
54  * SDSC: A data block can be max. one card write block, min. 1 byte.
55  * SDHC/SDXC: Block length is fixed to 512. The block length set by CMD16
56    is only used for CDM42 (not for memory data transfers). Thus, partial
57    read/write operations are disabled in SPI mode.
58  * SPI mode: Write protected commands (CMD28, CMD29, CMD30) are not supported.
59  * The SD mode state machine is NOT used. All commands that are supported
60    in SPI mode are always available.
61  * Per default the card is in CRC OFF mode. Exception: CMD0 (which is used to
62    switch to SPI mode) needs a valid CRC.
63  * The APP_CMD status bit is not available in SPI mode.
64  * TODO: Switch function command differences.
65  * In SPI mode cards cannot guarantee their speed class (the host should
66    assume class 0, no matter what the card indicates).
67  * The RCA register is not accessible in SPI mode.
68
69 Details:
70 TODO
71 '''
72
73 from .pd import *
74