]> sigrok.org Git - libsigrokdecode.git/blame - decoders/sdcard_spi/__init__.py
All PDs: Bump api_version to 2.
[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
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'''
4c3b1846
UH
22This decoder stacks on top of the 'spi' PD and decodes the SD card
23(SPI mode) low-level protocol.
47ec18f5
UH
24
25Most SD cards can be accessed via two different protocols/modes: SD mode
26or SPI mode.
27
28All SD cards are in SD mode upon powerup. They can be switched to SPI mode
29using a special method involving CMD0 (see spec). Once in SPI mode, the mode
30can no longer be changed without a power-cycle of the card.
31
32SPI 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.
47ec18f5
UH
67'''
68
69from .pd import *
70