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