High-speed access version sd-driver.
Dependents: SDBlockDevice_GR_PEACH SDBlockDevice_GR_PEACH HagridOS5
This library has modified SDBlockDevice.h based on revision "14: c7dba87" of sd-driver.
https://github.com/ARMmbed/sd-driver
features/filesystem/sd/SDBlockDevice.cpp@0:b22a1df967cb, 2017-03-23 (annotated)
- Committer:
- dkato
- Date:
- Thu Mar 23 08:25:54 2017 +0000
- Revision:
- 0:b22a1df967cb
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:b22a1df967cb | 1 | /* mbed Microcontroller Library |
dkato | 0:b22a1df967cb | 2 | * Copyright (c) 2006-2012 ARM Limited |
dkato | 0:b22a1df967cb | 3 | * |
dkato | 0:b22a1df967cb | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
dkato | 0:b22a1df967cb | 5 | * of this software and associated documentation files (the "Software"), to deal |
dkato | 0:b22a1df967cb | 6 | * in the Software without restriction, including without limitation the rights |
dkato | 0:b22a1df967cb | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
dkato | 0:b22a1df967cb | 8 | * copies of the Software, and to permit persons to whom the Software is |
dkato | 0:b22a1df967cb | 9 | * furnished to do so, subject to the following conditions: |
dkato | 0:b22a1df967cb | 10 | * |
dkato | 0:b22a1df967cb | 11 | * The above copyright notice and this permission notice shall be included in |
dkato | 0:b22a1df967cb | 12 | * all copies or substantial portions of the Software. |
dkato | 0:b22a1df967cb | 13 | * |
dkato | 0:b22a1df967cb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dkato | 0:b22a1df967cb | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dkato | 0:b22a1df967cb | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dkato | 0:b22a1df967cb | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dkato | 0:b22a1df967cb | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dkato | 0:b22a1df967cb | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
dkato | 0:b22a1df967cb | 20 | * SOFTWARE. |
dkato | 0:b22a1df967cb | 21 | */ |
dkato | 0:b22a1df967cb | 22 | /* Introduction |
dkato | 0:b22a1df967cb | 23 | * ------------ |
dkato | 0:b22a1df967cb | 24 | * SD and MMC cards support a number of interfaces, but common to them all |
dkato | 0:b22a1df967cb | 25 | * is one based on SPI. This is the one I'm implmenting because it means |
dkato | 0:b22a1df967cb | 26 | * it is much more portable even though not so performant, and we already |
dkato | 0:b22a1df967cb | 27 | * have the mbed SPI Interface! |
dkato | 0:b22a1df967cb | 28 | * |
dkato | 0:b22a1df967cb | 29 | * The main reference I'm using is Chapter 7, "SPI Mode" of: |
dkato | 0:b22a1df967cb | 30 | * http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf |
dkato | 0:b22a1df967cb | 31 | * |
dkato | 0:b22a1df967cb | 32 | * SPI Startup |
dkato | 0:b22a1df967cb | 33 | * ----------- |
dkato | 0:b22a1df967cb | 34 | * The SD card powers up in SD mode. The SPI interface mode is selected by |
dkato | 0:b22a1df967cb | 35 | * asserting CS low and sending the reset command (CMD0). The card will |
dkato | 0:b22a1df967cb | 36 | * respond with a (R1) response. |
dkato | 0:b22a1df967cb | 37 | * |
dkato | 0:b22a1df967cb | 38 | * CMD8 is optionally sent to determine the voltage range supported, and |
dkato | 0:b22a1df967cb | 39 | * indirectly determine whether it is a version 1.x SD/non-SD card or |
dkato | 0:b22a1df967cb | 40 | * version 2.x. I'll just ignore this for now. |
dkato | 0:b22a1df967cb | 41 | * |
dkato | 0:b22a1df967cb | 42 | * ACMD41 is repeatedly issued to initialise the card, until "in idle" |
dkato | 0:b22a1df967cb | 43 | * (bit 0) of the R1 response goes to '0', indicating it is initialised. |
dkato | 0:b22a1df967cb | 44 | * |
dkato | 0:b22a1df967cb | 45 | * You should also indicate whether the host supports High Capicity cards, |
dkato | 0:b22a1df967cb | 46 | * and check whether the card is high capacity - i'll also ignore this |
dkato | 0:b22a1df967cb | 47 | * |
dkato | 0:b22a1df967cb | 48 | * SPI Protocol |
dkato | 0:b22a1df967cb | 49 | * ------------ |
dkato | 0:b22a1df967cb | 50 | * The SD SPI protocol is based on transactions made up of 8-bit words, with |
dkato | 0:b22a1df967cb | 51 | * the host starting every bus transaction by asserting the CS signal low. The |
dkato | 0:b22a1df967cb | 52 | * card always responds to commands, data blocks and errors. |
dkato | 0:b22a1df967cb | 53 | * |
dkato | 0:b22a1df967cb | 54 | * The protocol supports a CRC, but by default it is off (except for the |
dkato | 0:b22a1df967cb | 55 | * first reset CMD0, where the CRC can just be pre-calculated, and CMD8) |
dkato | 0:b22a1df967cb | 56 | * I'll leave the CRC off I think! |
dkato | 0:b22a1df967cb | 57 | * |
dkato | 0:b22a1df967cb | 58 | * Standard capacity cards have variable data block sizes, whereas High |
dkato | 0:b22a1df967cb | 59 | * Capacity cards fix the size of data block to 512 bytes. I'll therefore |
dkato | 0:b22a1df967cb | 60 | * just always use the Standard Capacity cards with a block size of 512 bytes. |
dkato | 0:b22a1df967cb | 61 | * This is set with CMD16. |
dkato | 0:b22a1df967cb | 62 | * |
dkato | 0:b22a1df967cb | 63 | * You can read and write single blocks (CMD17, CMD25) or multiple blocks |
dkato | 0:b22a1df967cb | 64 | * (CMD18, CMD25). For simplicity, I'll just use single block accesses. When |
dkato | 0:b22a1df967cb | 65 | * the card gets a read command, it responds with a response token, and then |
dkato | 0:b22a1df967cb | 66 | * a data token or an error. |
dkato | 0:b22a1df967cb | 67 | * |
dkato | 0:b22a1df967cb | 68 | * SPI Command Format |
dkato | 0:b22a1df967cb | 69 | * ------------------ |
dkato | 0:b22a1df967cb | 70 | * Commands are 6-bytes long, containing the command, 32-bit argument, and CRC. |
dkato | 0:b22a1df967cb | 71 | * |
dkato | 0:b22a1df967cb | 72 | * +---------------+------------+------------+-----------+----------+--------------+ |
dkato | 0:b22a1df967cb | 73 | * | 01 | cmd[5:0] | arg[31:24] | arg[23:16] | arg[15:8] | arg[7:0] | crc[6:0] | 1 | |
dkato | 0:b22a1df967cb | 74 | * +---------------+------------+------------+-----------+----------+--------------+ |
dkato | 0:b22a1df967cb | 75 | * |
dkato | 0:b22a1df967cb | 76 | * As I'm not using CRC, I can fix that byte to what is needed for CMD0 (0x95) |
dkato | 0:b22a1df967cb | 77 | * |
dkato | 0:b22a1df967cb | 78 | * All Application Specific commands shall be preceded with APP_CMD (CMD55). |
dkato | 0:b22a1df967cb | 79 | * |
dkato | 0:b22a1df967cb | 80 | * SPI Response Format |
dkato | 0:b22a1df967cb | 81 | * ------------------- |
dkato | 0:b22a1df967cb | 82 | * The main response format (R1) is a status byte (normally zero). Key flags: |
dkato | 0:b22a1df967cb | 83 | * idle - 1 if the card is in an idle state/initialising |
dkato | 0:b22a1df967cb | 84 | * cmd - 1 if an illegal command code was detected |
dkato | 0:b22a1df967cb | 85 | * |
dkato | 0:b22a1df967cb | 86 | * +-------------------------------------------------+ |
dkato | 0:b22a1df967cb | 87 | * R1 | 0 | arg | addr | seq | crc | cmd | erase | idle | |
dkato | 0:b22a1df967cb | 88 | * +-------------------------------------------------+ |
dkato | 0:b22a1df967cb | 89 | * |
dkato | 0:b22a1df967cb | 90 | * R1b is the same, except it is followed by a busy signal (zeros) until |
dkato | 0:b22a1df967cb | 91 | * the first non-zero byte when it is ready again. |
dkato | 0:b22a1df967cb | 92 | * |
dkato | 0:b22a1df967cb | 93 | * Data Response Token |
dkato | 0:b22a1df967cb | 94 | * ------------------- |
dkato | 0:b22a1df967cb | 95 | * Every data block written to the card is acknowledged by a byte |
dkato | 0:b22a1df967cb | 96 | * response token |
dkato | 0:b22a1df967cb | 97 | * |
dkato | 0:b22a1df967cb | 98 | * +----------------------+ |
dkato | 0:b22a1df967cb | 99 | * | xxx | 0 | status | 1 | |
dkato | 0:b22a1df967cb | 100 | * +----------------------+ |
dkato | 0:b22a1df967cb | 101 | * 010 - OK! |
dkato | 0:b22a1df967cb | 102 | * 101 - CRC Error |
dkato | 0:b22a1df967cb | 103 | * 110 - Write Error |
dkato | 0:b22a1df967cb | 104 | * |
dkato | 0:b22a1df967cb | 105 | * Single Block Read and Write |
dkato | 0:b22a1df967cb | 106 | * --------------------------- |
dkato | 0:b22a1df967cb | 107 | * |
dkato | 0:b22a1df967cb | 108 | * Block transfers have a byte header, followed by the data, followed |
dkato | 0:b22a1df967cb | 109 | * by a 16-bit CRC. In our case, the data will always be 512 bytes. |
dkato | 0:b22a1df967cb | 110 | * |
dkato | 0:b22a1df967cb | 111 | * +------+---------+---------+- - - -+---------+-----------+----------+ |
dkato | 0:b22a1df967cb | 112 | * | 0xFE | data[0] | data[1] | | data[n] | crc[15:8] | crc[7:0] | |
dkato | 0:b22a1df967cb | 113 | * +------+---------+---------+- - - -+---------+-----------+----------+ |
dkato | 0:b22a1df967cb | 114 | */ |
dkato | 0:b22a1df967cb | 115 | |
dkato | 0:b22a1df967cb | 116 | /* If the target has no SPI support then SDCard is not supported */ |
dkato | 0:b22a1df967cb | 117 | #ifdef DEVICE_SPI |
dkato | 0:b22a1df967cb | 118 | |
dkato | 0:b22a1df967cb | 119 | #include "SDBlockDevice.h" |
dkato | 0:b22a1df967cb | 120 | #include "mbed_debug.h" |
dkato | 0:b22a1df967cb | 121 | |
dkato | 0:b22a1df967cb | 122 | #define SD_COMMAND_TIMEOUT 5000 |
dkato | 0:b22a1df967cb | 123 | |
dkato | 0:b22a1df967cb | 124 | #define SD_DBG 0 |
dkato | 0:b22a1df967cb | 125 | |
dkato | 0:b22a1df967cb | 126 | #define SD_BLOCK_DEVICE_ERROR_WOULD_BLOCK -5001 /*!< operation would block */ |
dkato | 0:b22a1df967cb | 127 | #define SD_BLOCK_DEVICE_ERROR_UNSUPPORTED -5002 /*!< unsupported operation */ |
dkato | 0:b22a1df967cb | 128 | #define SD_BLOCK_DEVICE_ERROR_PARAMETER -5003 /*!< invalid parameter */ |
dkato | 0:b22a1df967cb | 129 | #define SD_BLOCK_DEVICE_ERROR_NO_INIT -5004 /*!< uninitialized */ |
dkato | 0:b22a1df967cb | 130 | #define SD_BLOCK_DEVICE_ERROR_NO_DEVICE -5005 /*!< device is missing or not connected */ |
dkato | 0:b22a1df967cb | 131 | #define SD_BLOCK_DEVICE_ERROR_WRITE_PROTECTED -5006 /*!< write protected */ |
dkato | 0:b22a1df967cb | 132 | |
dkato | 0:b22a1df967cb | 133 | SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs) |
dkato | 0:b22a1df967cb | 134 | : _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0) |
dkato | 0:b22a1df967cb | 135 | { |
dkato | 0:b22a1df967cb | 136 | _cs = 1; |
dkato | 0:b22a1df967cb | 137 | |
dkato | 0:b22a1df967cb | 138 | // Set default to 100kHz for initialisation and 1MHz for data transfer |
dkato | 0:b22a1df967cb | 139 | _init_sck = 100000; |
dkato | 0:b22a1df967cb | 140 | _transfer_sck = 1000000; |
dkato | 0:b22a1df967cb | 141 | } |
dkato | 0:b22a1df967cb | 142 | |
dkato | 0:b22a1df967cb | 143 | SDBlockDevice::~SDBlockDevice() |
dkato | 0:b22a1df967cb | 144 | { |
dkato | 0:b22a1df967cb | 145 | if (_is_initialized) { |
dkato | 0:b22a1df967cb | 146 | deinit(); |
dkato | 0:b22a1df967cb | 147 | } |
dkato | 0:b22a1df967cb | 148 | } |
dkato | 0:b22a1df967cb | 149 | |
dkato | 0:b22a1df967cb | 150 | #define R1_IDLE_STATE (1 << 0) |
dkato | 0:b22a1df967cb | 151 | #define R1_ERASE_RESET (1 << 1) |
dkato | 0:b22a1df967cb | 152 | #define R1_ILLEGAL_COMMAND (1 << 2) |
dkato | 0:b22a1df967cb | 153 | #define R1_COM_CRC_ERROR (1 << 3) |
dkato | 0:b22a1df967cb | 154 | #define R1_ERASE_SEQUENCE_ERROR (1 << 4) |
dkato | 0:b22a1df967cb | 155 | #define R1_ADDRESS_ERROR (1 << 5) |
dkato | 0:b22a1df967cb | 156 | #define R1_PARAMETER_ERROR (1 << 6) |
dkato | 0:b22a1df967cb | 157 | |
dkato | 0:b22a1df967cb | 158 | // Types |
dkato | 0:b22a1df967cb | 159 | // - v1.x Standard Capacity |
dkato | 0:b22a1df967cb | 160 | // - v2.x Standard Capacity |
dkato | 0:b22a1df967cb | 161 | // - v2.x High Capacity |
dkato | 0:b22a1df967cb | 162 | // - Not recognised as an SD Card |
dkato | 0:b22a1df967cb | 163 | #define SDCARD_FAIL 0 |
dkato | 0:b22a1df967cb | 164 | #define SDCARD_V1 1 |
dkato | 0:b22a1df967cb | 165 | #define SDCARD_V2 2 |
dkato | 0:b22a1df967cb | 166 | #define SDCARD_V2HC 3 |
dkato | 0:b22a1df967cb | 167 | |
dkato | 0:b22a1df967cb | 168 | int SDBlockDevice::_initialise_card() |
dkato | 0:b22a1df967cb | 169 | { |
dkato | 0:b22a1df967cb | 170 | _dbg = SD_DBG; |
dkato | 0:b22a1df967cb | 171 | // Set to SCK for initialisation, and clock card with cs = 1 |
dkato | 0:b22a1df967cb | 172 | _spi.lock(); |
dkato | 0:b22a1df967cb | 173 | _spi.frequency(_init_sck); |
dkato | 0:b22a1df967cb | 174 | _cs = 1; |
dkato | 0:b22a1df967cb | 175 | for (int i = 0; i < 16; i++) { |
dkato | 0:b22a1df967cb | 176 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 177 | } |
dkato | 0:b22a1df967cb | 178 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 179 | |
dkato | 0:b22a1df967cb | 180 | // send CMD0, should return with all zeros except IDLE STATE set (bit 0) |
dkato | 0:b22a1df967cb | 181 | if (_cmd(0, 0) != R1_IDLE_STATE) { |
dkato | 0:b22a1df967cb | 182 | debug_if(_dbg, "No disk, or could not put SD card in to SPI idle state\n"); |
dkato | 0:b22a1df967cb | 183 | return SD_BLOCK_DEVICE_ERROR_NO_DEVICE; |
dkato | 0:b22a1df967cb | 184 | } |
dkato | 0:b22a1df967cb | 185 | |
dkato | 0:b22a1df967cb | 186 | // send CMD8 to determine whther it is ver 2.x |
dkato | 0:b22a1df967cb | 187 | int r = _cmd8(); |
dkato | 0:b22a1df967cb | 188 | if (r == R1_IDLE_STATE) { |
dkato | 0:b22a1df967cb | 189 | return _initialise_card_v2(); |
dkato | 0:b22a1df967cb | 190 | } else if (r == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) { |
dkato | 0:b22a1df967cb | 191 | return _initialise_card_v1(); |
dkato | 0:b22a1df967cb | 192 | } else { |
dkato | 0:b22a1df967cb | 193 | debug_if(_dbg, "Not in idle state after sending CMD8 (not an SD card?)\n"); |
dkato | 0:b22a1df967cb | 194 | return BD_ERROR_DEVICE_ERROR; |
dkato | 0:b22a1df967cb | 195 | } |
dkato | 0:b22a1df967cb | 196 | } |
dkato | 0:b22a1df967cb | 197 | |
dkato | 0:b22a1df967cb | 198 | int SDBlockDevice::_initialise_card_v1() |
dkato | 0:b22a1df967cb | 199 | { |
dkato | 0:b22a1df967cb | 200 | for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { |
dkato | 0:b22a1df967cb | 201 | _cmd(55, 0); |
dkato | 0:b22a1df967cb | 202 | if (_cmd(41, 0) == 0) { |
dkato | 0:b22a1df967cb | 203 | _block_size = 512; |
dkato | 0:b22a1df967cb | 204 | debug_if(_dbg, "\n\rInit: SEDCARD_V1\n\r"); |
dkato | 0:b22a1df967cb | 205 | return BD_ERROR_OK; |
dkato | 0:b22a1df967cb | 206 | } |
dkato | 0:b22a1df967cb | 207 | } |
dkato | 0:b22a1df967cb | 208 | |
dkato | 0:b22a1df967cb | 209 | debug_if(_dbg, "Timeout waiting for v1.x card\n"); |
dkato | 0:b22a1df967cb | 210 | return BD_ERROR_DEVICE_ERROR; |
dkato | 0:b22a1df967cb | 211 | } |
dkato | 0:b22a1df967cb | 212 | |
dkato | 0:b22a1df967cb | 213 | int SDBlockDevice::_initialise_card_v2() |
dkato | 0:b22a1df967cb | 214 | { |
dkato | 0:b22a1df967cb | 215 | for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { |
dkato | 0:b22a1df967cb | 216 | wait_ms(50); |
dkato | 0:b22a1df967cb | 217 | _cmd58(); |
dkato | 0:b22a1df967cb | 218 | _cmd(55, 0); |
dkato | 0:b22a1df967cb | 219 | if (_cmd(41, 0x40000000) == 0) { |
dkato | 0:b22a1df967cb | 220 | _cmd58(); |
dkato | 0:b22a1df967cb | 221 | debug_if(_dbg, "\n\rInit: SDCARD_V2\n\r"); |
dkato | 0:b22a1df967cb | 222 | _block_size = 1; |
dkato | 0:b22a1df967cb | 223 | return BD_ERROR_OK; |
dkato | 0:b22a1df967cb | 224 | } |
dkato | 0:b22a1df967cb | 225 | } |
dkato | 0:b22a1df967cb | 226 | |
dkato | 0:b22a1df967cb | 227 | debug_if(_dbg, "Timeout waiting for v2.x card\n"); |
dkato | 0:b22a1df967cb | 228 | return BD_ERROR_DEVICE_ERROR; |
dkato | 0:b22a1df967cb | 229 | } |
dkato | 0:b22a1df967cb | 230 | |
dkato | 0:b22a1df967cb | 231 | int SDBlockDevice::init() |
dkato | 0:b22a1df967cb | 232 | { |
dkato | 0:b22a1df967cb | 233 | _lock.lock(); |
dkato | 0:b22a1df967cb | 234 | int err = _initialise_card(); |
dkato | 0:b22a1df967cb | 235 | _is_initialized = (err == BD_ERROR_OK); |
dkato | 0:b22a1df967cb | 236 | if (!_is_initialized) { |
dkato | 0:b22a1df967cb | 237 | debug_if(_dbg, "Fail to initialize card\n"); |
dkato | 0:b22a1df967cb | 238 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 239 | return err; |
dkato | 0:b22a1df967cb | 240 | } |
dkato | 0:b22a1df967cb | 241 | debug_if(_dbg, "init card = %d\n", _is_initialized); |
dkato | 0:b22a1df967cb | 242 | _sectors = _sd_sectors(); |
dkato | 0:b22a1df967cb | 243 | |
dkato | 0:b22a1df967cb | 244 | // Set block length to 512 (CMD16) |
dkato | 0:b22a1df967cb | 245 | if (_cmd(16, 512) != 0) { |
dkato | 0:b22a1df967cb | 246 | debug_if(_dbg, "Set 512-byte block timed out\n"); |
dkato | 0:b22a1df967cb | 247 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 248 | return BD_ERROR_DEVICE_ERROR; |
dkato | 0:b22a1df967cb | 249 | } |
dkato | 0:b22a1df967cb | 250 | |
dkato | 0:b22a1df967cb | 251 | // Set SCK for data transfer |
dkato | 0:b22a1df967cb | 252 | _spi.frequency(_transfer_sck); |
dkato | 0:b22a1df967cb | 253 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 254 | return BD_ERROR_OK; |
dkato | 0:b22a1df967cb | 255 | } |
dkato | 0:b22a1df967cb | 256 | |
dkato | 0:b22a1df967cb | 257 | int SDBlockDevice::deinit() |
dkato | 0:b22a1df967cb | 258 | { |
dkato | 0:b22a1df967cb | 259 | return 0; |
dkato | 0:b22a1df967cb | 260 | } |
dkato | 0:b22a1df967cb | 261 | |
dkato | 0:b22a1df967cb | 262 | int SDBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) |
dkato | 0:b22a1df967cb | 263 | { |
dkato | 0:b22a1df967cb | 264 | if (!is_valid_program(addr, size)) { |
dkato | 0:b22a1df967cb | 265 | return SD_BLOCK_DEVICE_ERROR_PARAMETER; |
dkato | 0:b22a1df967cb | 266 | } |
dkato | 0:b22a1df967cb | 267 | |
dkato | 0:b22a1df967cb | 268 | _lock.lock(); |
dkato | 0:b22a1df967cb | 269 | if (!_is_initialized) { |
dkato | 0:b22a1df967cb | 270 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 271 | return SD_BLOCK_DEVICE_ERROR_NO_INIT; |
dkato | 0:b22a1df967cb | 272 | } |
dkato | 0:b22a1df967cb | 273 | |
dkato | 0:b22a1df967cb | 274 | const uint8_t *buffer = static_cast<const uint8_t*>(b); |
dkato | 0:b22a1df967cb | 275 | while (size > 0) { |
dkato | 0:b22a1df967cb | 276 | bd_addr_t block = addr / 512; |
dkato | 0:b22a1df967cb | 277 | // set write address for single block (CMD24) |
dkato | 0:b22a1df967cb | 278 | if (_cmd(24, block * _block_size) != 0) { |
dkato | 0:b22a1df967cb | 279 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 280 | return BD_ERROR_DEVICE_ERROR; |
dkato | 0:b22a1df967cb | 281 | } |
dkato | 0:b22a1df967cb | 282 | |
dkato | 0:b22a1df967cb | 283 | // send the data block |
dkato | 0:b22a1df967cb | 284 | _write(buffer, 512); |
dkato | 0:b22a1df967cb | 285 | buffer += 512; |
dkato | 0:b22a1df967cb | 286 | addr += 512; |
dkato | 0:b22a1df967cb | 287 | size -= 512; |
dkato | 0:b22a1df967cb | 288 | } |
dkato | 0:b22a1df967cb | 289 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 290 | return 0; |
dkato | 0:b22a1df967cb | 291 | } |
dkato | 0:b22a1df967cb | 292 | |
dkato | 0:b22a1df967cb | 293 | int SDBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) |
dkato | 0:b22a1df967cb | 294 | { |
dkato | 0:b22a1df967cb | 295 | if (!is_valid_read(addr, size)) { |
dkato | 0:b22a1df967cb | 296 | return SD_BLOCK_DEVICE_ERROR_PARAMETER; |
dkato | 0:b22a1df967cb | 297 | } |
dkato | 0:b22a1df967cb | 298 | |
dkato | 0:b22a1df967cb | 299 | _lock.lock(); |
dkato | 0:b22a1df967cb | 300 | if (!_is_initialized) { |
dkato | 0:b22a1df967cb | 301 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 302 | return SD_BLOCK_DEVICE_ERROR_PARAMETER; |
dkato | 0:b22a1df967cb | 303 | } |
dkato | 0:b22a1df967cb | 304 | |
dkato | 0:b22a1df967cb | 305 | uint8_t *buffer = static_cast<uint8_t *>(b); |
dkato | 0:b22a1df967cb | 306 | while (size > 0) { |
dkato | 0:b22a1df967cb | 307 | bd_addr_t block = addr / 512; |
dkato | 0:b22a1df967cb | 308 | // set read address for single block (CMD17) |
dkato | 0:b22a1df967cb | 309 | if (_cmd(17, block * _block_size) != 0) { |
dkato | 0:b22a1df967cb | 310 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 311 | return BD_ERROR_DEVICE_ERROR; |
dkato | 0:b22a1df967cb | 312 | } |
dkato | 0:b22a1df967cb | 313 | |
dkato | 0:b22a1df967cb | 314 | // receive the data |
dkato | 0:b22a1df967cb | 315 | _read(buffer, 512); |
dkato | 0:b22a1df967cb | 316 | buffer += 512; |
dkato | 0:b22a1df967cb | 317 | addr += 512; |
dkato | 0:b22a1df967cb | 318 | size -= 512; |
dkato | 0:b22a1df967cb | 319 | } |
dkato | 0:b22a1df967cb | 320 | _lock.unlock(); |
dkato | 0:b22a1df967cb | 321 | return 0; |
dkato | 0:b22a1df967cb | 322 | } |
dkato | 0:b22a1df967cb | 323 | |
dkato | 0:b22a1df967cb | 324 | int SDBlockDevice::erase(bd_addr_t addr, bd_size_t size) |
dkato | 0:b22a1df967cb | 325 | { |
dkato | 0:b22a1df967cb | 326 | return 0; |
dkato | 0:b22a1df967cb | 327 | } |
dkato | 0:b22a1df967cb | 328 | |
dkato | 0:b22a1df967cb | 329 | bd_size_t SDBlockDevice::get_read_size() const |
dkato | 0:b22a1df967cb | 330 | { |
dkato | 0:b22a1df967cb | 331 | return 512; |
dkato | 0:b22a1df967cb | 332 | } |
dkato | 0:b22a1df967cb | 333 | |
dkato | 0:b22a1df967cb | 334 | bd_size_t SDBlockDevice::get_program_size() const |
dkato | 0:b22a1df967cb | 335 | { |
dkato | 0:b22a1df967cb | 336 | return 512; |
dkato | 0:b22a1df967cb | 337 | } |
dkato | 0:b22a1df967cb | 338 | |
dkato | 0:b22a1df967cb | 339 | bd_size_t SDBlockDevice::get_erase_size() const |
dkato | 0:b22a1df967cb | 340 | { |
dkato | 0:b22a1df967cb | 341 | return 512; |
dkato | 0:b22a1df967cb | 342 | } |
dkato | 0:b22a1df967cb | 343 | |
dkato | 0:b22a1df967cb | 344 | bd_size_t SDBlockDevice::size() const |
dkato | 0:b22a1df967cb | 345 | { |
dkato | 0:b22a1df967cb | 346 | bd_size_t sectors = 0; |
dkato | 0:b22a1df967cb | 347 | if(_is_initialized) { |
dkato | 0:b22a1df967cb | 348 | sectors = _sectors; |
dkato | 0:b22a1df967cb | 349 | } |
dkato | 0:b22a1df967cb | 350 | return 512*sectors; |
dkato | 0:b22a1df967cb | 351 | } |
dkato | 0:b22a1df967cb | 352 | |
dkato | 0:b22a1df967cb | 353 | void SDBlockDevice::debug(bool dbg) |
dkato | 0:b22a1df967cb | 354 | { |
dkato | 0:b22a1df967cb | 355 | _dbg = dbg; |
dkato | 0:b22a1df967cb | 356 | } |
dkato | 0:b22a1df967cb | 357 | |
dkato | 0:b22a1df967cb | 358 | |
dkato | 0:b22a1df967cb | 359 | // PRIVATE FUNCTIONS |
dkato | 0:b22a1df967cb | 360 | int SDBlockDevice::_cmd(int cmd, int arg) { |
dkato | 0:b22a1df967cb | 361 | _spi.lock(); |
dkato | 0:b22a1df967cb | 362 | _cs = 0; |
dkato | 0:b22a1df967cb | 363 | |
dkato | 0:b22a1df967cb | 364 | // send a command |
dkato | 0:b22a1df967cb | 365 | _spi.write(0x40 | cmd); |
dkato | 0:b22a1df967cb | 366 | _spi.write(arg >> 24); |
dkato | 0:b22a1df967cb | 367 | _spi.write(arg >> 16); |
dkato | 0:b22a1df967cb | 368 | _spi.write(arg >> 8); |
dkato | 0:b22a1df967cb | 369 | _spi.write(arg >> 0); |
dkato | 0:b22a1df967cb | 370 | _spi.write(0x95); |
dkato | 0:b22a1df967cb | 371 | |
dkato | 0:b22a1df967cb | 372 | // wait for the repsonse (response[7] == 0) |
dkato | 0:b22a1df967cb | 373 | for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { |
dkato | 0:b22a1df967cb | 374 | int response = _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 375 | if (!(response & 0x80)) { |
dkato | 0:b22a1df967cb | 376 | _cs = 1; |
dkato | 0:b22a1df967cb | 377 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 378 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 379 | return response; |
dkato | 0:b22a1df967cb | 380 | } |
dkato | 0:b22a1df967cb | 381 | } |
dkato | 0:b22a1df967cb | 382 | _cs = 1; |
dkato | 0:b22a1df967cb | 383 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 384 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 385 | return -1; // timeout |
dkato | 0:b22a1df967cb | 386 | } |
dkato | 0:b22a1df967cb | 387 | int SDBlockDevice::_cmdx(int cmd, int arg) { |
dkato | 0:b22a1df967cb | 388 | _spi.lock(); |
dkato | 0:b22a1df967cb | 389 | _cs = 0; |
dkato | 0:b22a1df967cb | 390 | |
dkato | 0:b22a1df967cb | 391 | // send a command |
dkato | 0:b22a1df967cb | 392 | _spi.write(0x40 | cmd); |
dkato | 0:b22a1df967cb | 393 | _spi.write(arg >> 24); |
dkato | 0:b22a1df967cb | 394 | _spi.write(arg >> 16); |
dkato | 0:b22a1df967cb | 395 | _spi.write(arg >> 8); |
dkato | 0:b22a1df967cb | 396 | _spi.write(arg >> 0); |
dkato | 0:b22a1df967cb | 397 | _spi.write(0x95); |
dkato | 0:b22a1df967cb | 398 | |
dkato | 0:b22a1df967cb | 399 | // wait for the repsonse (response[7] == 0) |
dkato | 0:b22a1df967cb | 400 | for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { |
dkato | 0:b22a1df967cb | 401 | int response = _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 402 | if (!(response & 0x80)) { |
dkato | 0:b22a1df967cb | 403 | _cs = 1; |
dkato | 0:b22a1df967cb | 404 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 405 | return response; |
dkato | 0:b22a1df967cb | 406 | } |
dkato | 0:b22a1df967cb | 407 | } |
dkato | 0:b22a1df967cb | 408 | _cs = 1; |
dkato | 0:b22a1df967cb | 409 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 410 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 411 | return -1; // timeout |
dkato | 0:b22a1df967cb | 412 | } |
dkato | 0:b22a1df967cb | 413 | |
dkato | 0:b22a1df967cb | 414 | |
dkato | 0:b22a1df967cb | 415 | int SDBlockDevice::_cmd58() { |
dkato | 0:b22a1df967cb | 416 | _spi.lock(); |
dkato | 0:b22a1df967cb | 417 | _cs = 0; |
dkato | 0:b22a1df967cb | 418 | int arg = 0; |
dkato | 0:b22a1df967cb | 419 | |
dkato | 0:b22a1df967cb | 420 | // send a command |
dkato | 0:b22a1df967cb | 421 | _spi.write(0x40 | 58); |
dkato | 0:b22a1df967cb | 422 | _spi.write(arg >> 24); |
dkato | 0:b22a1df967cb | 423 | _spi.write(arg >> 16); |
dkato | 0:b22a1df967cb | 424 | _spi.write(arg >> 8); |
dkato | 0:b22a1df967cb | 425 | _spi.write(arg >> 0); |
dkato | 0:b22a1df967cb | 426 | _spi.write(0x95); |
dkato | 0:b22a1df967cb | 427 | |
dkato | 0:b22a1df967cb | 428 | // wait for the repsonse (response[7] == 0) |
dkato | 0:b22a1df967cb | 429 | for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { |
dkato | 0:b22a1df967cb | 430 | int response = _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 431 | if (!(response & 0x80)) { |
dkato | 0:b22a1df967cb | 432 | int ocr = _spi.write(0xFF) << 24; |
dkato | 0:b22a1df967cb | 433 | ocr |= _spi.write(0xFF) << 16; |
dkato | 0:b22a1df967cb | 434 | ocr |= _spi.write(0xFF) << 8; |
dkato | 0:b22a1df967cb | 435 | ocr |= _spi.write(0xFF) << 0; |
dkato | 0:b22a1df967cb | 436 | _cs = 1; |
dkato | 0:b22a1df967cb | 437 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 438 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 439 | return response; |
dkato | 0:b22a1df967cb | 440 | } |
dkato | 0:b22a1df967cb | 441 | } |
dkato | 0:b22a1df967cb | 442 | _cs = 1; |
dkato | 0:b22a1df967cb | 443 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 444 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 445 | return -1; // timeout |
dkato | 0:b22a1df967cb | 446 | } |
dkato | 0:b22a1df967cb | 447 | |
dkato | 0:b22a1df967cb | 448 | int SDBlockDevice::_cmd8() { |
dkato | 0:b22a1df967cb | 449 | _spi.lock(); |
dkato | 0:b22a1df967cb | 450 | _cs = 0; |
dkato | 0:b22a1df967cb | 451 | |
dkato | 0:b22a1df967cb | 452 | // send a command |
dkato | 0:b22a1df967cb | 453 | _spi.write(0x40 | 8); // CMD8 |
dkato | 0:b22a1df967cb | 454 | _spi.write(0x00); // reserved |
dkato | 0:b22a1df967cb | 455 | _spi.write(0x00); // reserved |
dkato | 0:b22a1df967cb | 456 | _spi.write(0x01); // 3.3v |
dkato | 0:b22a1df967cb | 457 | _spi.write(0xAA); // check pattern |
dkato | 0:b22a1df967cb | 458 | _spi.write(0x87); // crc |
dkato | 0:b22a1df967cb | 459 | |
dkato | 0:b22a1df967cb | 460 | // wait for the repsonse (response[7] == 0) |
dkato | 0:b22a1df967cb | 461 | for (int i = 0; i < SD_COMMAND_TIMEOUT * 1000; i++) { |
dkato | 0:b22a1df967cb | 462 | char response[5]; |
dkato | 0:b22a1df967cb | 463 | response[0] = _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 464 | if (!(response[0] & 0x80)) { |
dkato | 0:b22a1df967cb | 465 | for (int j = 1; j < 5; j++) { |
dkato | 0:b22a1df967cb | 466 | response[i] = _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 467 | } |
dkato | 0:b22a1df967cb | 468 | _cs = 1; |
dkato | 0:b22a1df967cb | 469 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 470 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 471 | return response[0]; |
dkato | 0:b22a1df967cb | 472 | } |
dkato | 0:b22a1df967cb | 473 | } |
dkato | 0:b22a1df967cb | 474 | _cs = 1; |
dkato | 0:b22a1df967cb | 475 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 476 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 477 | return -1; // timeout |
dkato | 0:b22a1df967cb | 478 | } |
dkato | 0:b22a1df967cb | 479 | |
dkato | 0:b22a1df967cb | 480 | int SDBlockDevice::_read(uint8_t *buffer, uint32_t length) { |
dkato | 0:b22a1df967cb | 481 | _spi.lock(); |
dkato | 0:b22a1df967cb | 482 | _cs = 0; |
dkato | 0:b22a1df967cb | 483 | |
dkato | 0:b22a1df967cb | 484 | // read until start byte (0xFF) |
dkato | 0:b22a1df967cb | 485 | while (_spi.write(0xFF) != 0xFE); |
dkato | 0:b22a1df967cb | 486 | |
dkato | 0:b22a1df967cb | 487 | // read data |
dkato | 0:b22a1df967cb | 488 | for (uint32_t i = 0; i < length; i++) { |
dkato | 0:b22a1df967cb | 489 | buffer[i] = _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 490 | } |
dkato | 0:b22a1df967cb | 491 | _spi.write(0xFF); // checksum |
dkato | 0:b22a1df967cb | 492 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 493 | |
dkato | 0:b22a1df967cb | 494 | _cs = 1; |
dkato | 0:b22a1df967cb | 495 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 496 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 497 | return 0; |
dkato | 0:b22a1df967cb | 498 | } |
dkato | 0:b22a1df967cb | 499 | |
dkato | 0:b22a1df967cb | 500 | int SDBlockDevice::_write(const uint8_t*buffer, uint32_t length) { |
dkato | 0:b22a1df967cb | 501 | _spi.lock(); |
dkato | 0:b22a1df967cb | 502 | _cs = 0; |
dkato | 0:b22a1df967cb | 503 | |
dkato | 0:b22a1df967cb | 504 | // indicate start of block |
dkato | 0:b22a1df967cb | 505 | _spi.write(0xFE); |
dkato | 0:b22a1df967cb | 506 | |
dkato | 0:b22a1df967cb | 507 | // write the data |
dkato | 0:b22a1df967cb | 508 | for (uint32_t i = 0; i < length; i++) { |
dkato | 0:b22a1df967cb | 509 | _spi.write(buffer[i]); |
dkato | 0:b22a1df967cb | 510 | } |
dkato | 0:b22a1df967cb | 511 | |
dkato | 0:b22a1df967cb | 512 | // write the checksum |
dkato | 0:b22a1df967cb | 513 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 514 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 515 | |
dkato | 0:b22a1df967cb | 516 | // check the response token |
dkato | 0:b22a1df967cb | 517 | if ((_spi.write(0xFF) & 0x1F) != 0x05) { |
dkato | 0:b22a1df967cb | 518 | _cs = 1; |
dkato | 0:b22a1df967cb | 519 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 520 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 521 | return 1; |
dkato | 0:b22a1df967cb | 522 | } |
dkato | 0:b22a1df967cb | 523 | |
dkato | 0:b22a1df967cb | 524 | // wait for write to finish |
dkato | 0:b22a1df967cb | 525 | while (_spi.write(0xFF) == 0); |
dkato | 0:b22a1df967cb | 526 | |
dkato | 0:b22a1df967cb | 527 | _cs = 1; |
dkato | 0:b22a1df967cb | 528 | _spi.write(0xFF); |
dkato | 0:b22a1df967cb | 529 | _spi.unlock(); |
dkato | 0:b22a1df967cb | 530 | return 0; |
dkato | 0:b22a1df967cb | 531 | } |
dkato | 0:b22a1df967cb | 532 | |
dkato | 0:b22a1df967cb | 533 | static uint32_t ext_bits(unsigned char *data, int msb, int lsb) { |
dkato | 0:b22a1df967cb | 534 | uint32_t bits = 0; |
dkato | 0:b22a1df967cb | 535 | uint32_t size = 1 + msb - lsb; |
dkato | 0:b22a1df967cb | 536 | for (uint32_t i = 0; i < size; i++) { |
dkato | 0:b22a1df967cb | 537 | uint32_t position = lsb + i; |
dkato | 0:b22a1df967cb | 538 | uint32_t byte = 15 - (position >> 3); |
dkato | 0:b22a1df967cb | 539 | uint32_t bit = position & 0x7; |
dkato | 0:b22a1df967cb | 540 | uint32_t value = (data[byte] >> bit) & 1; |
dkato | 0:b22a1df967cb | 541 | bits |= value << i; |
dkato | 0:b22a1df967cb | 542 | } |
dkato | 0:b22a1df967cb | 543 | return bits; |
dkato | 0:b22a1df967cb | 544 | } |
dkato | 0:b22a1df967cb | 545 | |
dkato | 0:b22a1df967cb | 546 | uint32_t SDBlockDevice::_sd_sectors() { |
dkato | 0:b22a1df967cb | 547 | uint32_t c_size, c_size_mult, read_bl_len; |
dkato | 0:b22a1df967cb | 548 | uint32_t block_len, mult, blocknr, capacity; |
dkato | 0:b22a1df967cb | 549 | uint32_t hc_c_size; |
dkato | 0:b22a1df967cb | 550 | uint32_t blocks; |
dkato | 0:b22a1df967cb | 551 | |
dkato | 0:b22a1df967cb | 552 | // CMD9, Response R2 (R1 byte + 16-byte block read) |
dkato | 0:b22a1df967cb | 553 | if (_cmdx(9, 0) != 0) { |
dkato | 0:b22a1df967cb | 554 | debug_if(_dbg, "Didn't get a response from the disk\n"); |
dkato | 0:b22a1df967cb | 555 | return 0; |
dkato | 0:b22a1df967cb | 556 | } |
dkato | 0:b22a1df967cb | 557 | |
dkato | 0:b22a1df967cb | 558 | uint8_t csd[16]; |
dkato | 0:b22a1df967cb | 559 | if (_read(csd, 16) != 0) { |
dkato | 0:b22a1df967cb | 560 | debug_if(_dbg, "Couldn't read csd response from disk\n"); |
dkato | 0:b22a1df967cb | 561 | return 0; |
dkato | 0:b22a1df967cb | 562 | } |
dkato | 0:b22a1df967cb | 563 | |
dkato | 0:b22a1df967cb | 564 | // csd_structure : csd[127:126] |
dkato | 0:b22a1df967cb | 565 | // c_size : csd[73:62] |
dkato | 0:b22a1df967cb | 566 | // c_size_mult : csd[49:47] |
dkato | 0:b22a1df967cb | 567 | // read_bl_len : csd[83:80] - the *maximum* read block length |
dkato | 0:b22a1df967cb | 568 | |
dkato | 0:b22a1df967cb | 569 | int csd_structure = ext_bits(csd, 127, 126); |
dkato | 0:b22a1df967cb | 570 | |
dkato | 0:b22a1df967cb | 571 | switch (csd_structure) { |
dkato | 0:b22a1df967cb | 572 | case 0: |
dkato | 0:b22a1df967cb | 573 | _block_size = 512; |
dkato | 0:b22a1df967cb | 574 | c_size = ext_bits(csd, 73, 62); |
dkato | 0:b22a1df967cb | 575 | c_size_mult = ext_bits(csd, 49, 47); |
dkato | 0:b22a1df967cb | 576 | read_bl_len = ext_bits(csd, 83, 80); |
dkato | 0:b22a1df967cb | 577 | |
dkato | 0:b22a1df967cb | 578 | block_len = 1 << read_bl_len; |
dkato | 0:b22a1df967cb | 579 | mult = 1 << (c_size_mult + 2); |
dkato | 0:b22a1df967cb | 580 | blocknr = (c_size + 1) * mult; |
dkato | 0:b22a1df967cb | 581 | capacity = blocknr * block_len; |
dkato | 0:b22a1df967cb | 582 | blocks = capacity / 512; |
dkato | 0:b22a1df967cb | 583 | debug_if(_dbg, "\n\rSDBlockDevice\n\rc_size: %d \n\rcapacity: %ld \n\rsectors: %lld\n\r", c_size, capacity, blocks); |
dkato | 0:b22a1df967cb | 584 | break; |
dkato | 0:b22a1df967cb | 585 | |
dkato | 0:b22a1df967cb | 586 | case 1: |
dkato | 0:b22a1df967cb | 587 | _block_size = 1; |
dkato | 0:b22a1df967cb | 588 | hc_c_size = ext_bits(csd, 63, 48); |
dkato | 0:b22a1df967cb | 589 | blocks = (hc_c_size+1)*1024; |
dkato | 0:b22a1df967cb | 590 | debug_if(_dbg, "\n\rSDHC Card \n\rhc_c_size: %d\n\rcapacity: %lld \n\rsectors: %lld\n\r", hc_c_size, blocks*512, blocks); |
dkato | 0:b22a1df967cb | 591 | break; |
dkato | 0:b22a1df967cb | 592 | |
dkato | 0:b22a1df967cb | 593 | default: |
dkato | 0:b22a1df967cb | 594 | debug_if(_dbg, "CSD struct unsupported\r\n"); |
dkato | 0:b22a1df967cb | 595 | return 0; |
dkato | 0:b22a1df967cb | 596 | }; |
dkato | 0:b22a1df967cb | 597 | return blocks; |
dkato | 0:b22a1df967cb | 598 | } |
dkato | 0:b22a1df967cb | 599 | |
dkato | 0:b22a1df967cb | 600 | #endif /* DEVICE_SPI */ |