17 #ifndef MBED_SD_BLOCK_DEVICE_H 18 #define MBED_SD_BLOCK_DEVICE_H 23 #include "BlockDevice.h" 24 #include "drivers/SPI.h" 25 #include "drivers/Timer.h" 26 #include "drivers/MbedCRC.h" 27 #include "drivers/DigitalOut.h" 28 #include "platform/platform.h" 29 #include "platform/PlatformMutex.h" 46 SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz = 1000000,
bool crc_on = 0);
77 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
95 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
114 virtual int trim(mbed::bd_addr_t addr, mbed::bd_size_t size);
133 virtual mbed::bd_size_t
size()
const;
139 virtual void debug(
bool dbg);
152 virtual const char *
get_type()
const;
159 CMD_NOT_SUPPORTED = -1,
160 CMD0_GO_IDLE_STATE = 0,
161 CMD1_SEND_OP_COND = 1,
162 CMD6_SWITCH_FUNC = 6,
163 CMD8_SEND_IF_COND = 8,
166 CMD12_STOP_TRANSMISSION = 12,
167 CMD13_SEND_STATUS = 13,
168 CMD16_SET_BLOCKLEN = 16,
169 CMD17_READ_SINGLE_BLOCK = 17,
170 CMD18_READ_MULTIPLE_BLOCK = 18,
172 CMD24_WRITE_BLOCK = 24,
173 CMD25_WRITE_MULTIPLE_BLOCK = 25,
175 CMD27_PROGRAM_CSD = 27,
176 CMD32_ERASE_WR_BLK_START_ADDR = 32,
178 CMD33_ERASE_WR_BLK_END_ADDR = 33,
184 CMD59_CRC_ON_OFF = 59,
186 ACMD6_SET_BUS_WIDTH = 6,
187 ACMD13_SD_STATUS = 13,
188 ACMD22_SEND_NUM_WR_BLOCKS = 22,
189 ACMD23_SET_WR_BLK_ERASE_COUNT = 23,
190 ACMD41_SD_SEND_OP_COND = 41,
191 ACMD42_SET_CLR_CARD_DETECT = 42,
192 ACMD51_SEND_SCR = 51,
196 int _cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg,
bool isAcmd = 0, uint32_t *resp = NULL);
209 uint32_t _go_idle_state();
210 int _initialise_card();
212 mbed::bd_size_t _sectors;
213 mbed::bd_size_t _sd_sectors();
215 bool _is_valid_trim(mbed::bd_addr_t addr, mbed::bd_size_t size);
218 mbed::Timer _spi_timer;
220 uint32_t _transfer_sck;
225 uint8_t _cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg);
226 void _spi_wait(uint8_t count);
228 bool _wait_token(uint8_t token);
229 bool _wait_ready(uint16_t ms = 300);
230 int _read(uint8_t *buffer, uint32_t length);
231 int _read_bytes(uint8_t *buffer, uint32_t length);
232 uint8_t _write(
const uint8_t *buffer, uint8_t token, uint32_t length);
245 virtual void unlock()
251 static const uint32_t _block_size;
252 uint32_t _erase_size;
253 bool _is_initialized;
255 uint32_t _init_ref_count;
257 #if MBED_CONF_SD_CRC_ENABLED virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Program blocks to a block device.
virtual void debug(bool dbg)
Enable or disable debugging.
A hardware device capable of writing and reading blocks.
virtual int init()
Initialize a block device.
virtual mbed::bd_size_t size() const
Get the total size of the underlying device.
SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz=1000000, bool crc_on=0)
Creates an SDBlockDevice on a SPI bus specified by pins.
virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Read blocks from a block device.
virtual mbed::bd_size_t get_read_size() const
Get the size of a readable block.
CRC object provides CRC generation through hardware or software.
A digital output, used for setting the state of a pin.
A SPI Master, used for communicating with SPI slave devices.
virtual mbed::bd_size_t get_program_size() const
Get the size of a programmable block.
virtual int frequency(uint64_t freq)
Set the transfer frequency.
virtual int deinit()
Deinitialize a block device.
virtual const char * get_type() const
Get the BlockDevice class type.
virtual int trim(mbed::bd_addr_t addr, mbed::bd_size_t size)
Mark blocks as no longer in use.