17 #ifndef MBED_SD_BLOCK_DEVICE_H 18 #define MBED_SD_BLOCK_DEVICE_H 23 #include "features/storage/blockdevice/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" 30 #include "hal/static_pinmap.h" 47 SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz = 1000000,
bool crc_on = 0);
87 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
105 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
124 virtual int trim(mbed::bd_addr_t addr, mbed::bd_size_t size);
143 virtual mbed::bd_size_t
size()
const;
149 virtual void debug(
bool dbg);
162 virtual const char *
get_type()
const;
169 CMD_NOT_SUPPORTED = -1,
170 CMD0_GO_IDLE_STATE = 0,
171 CMD1_SEND_OP_COND = 1,
172 CMD6_SWITCH_FUNC = 6,
173 CMD8_SEND_IF_COND = 8,
176 CMD12_STOP_TRANSMISSION = 12,
177 CMD13_SEND_STATUS = 13,
178 CMD16_SET_BLOCKLEN = 16,
179 CMD17_READ_SINGLE_BLOCK = 17,
180 CMD18_READ_MULTIPLE_BLOCK = 18,
182 CMD24_WRITE_BLOCK = 24,
183 CMD25_WRITE_MULTIPLE_BLOCK = 25,
185 CMD27_PROGRAM_CSD = 27,
186 CMD32_ERASE_WR_BLK_START_ADDR = 32,
188 CMD33_ERASE_WR_BLK_END_ADDR = 33,
194 CMD59_CRC_ON_OFF = 59,
196 ACMD6_SET_BUS_WIDTH = 6,
197 ACMD13_SD_STATUS = 13,
198 ACMD22_SEND_NUM_WR_BLOCKS = 22,
199 ACMD23_SET_WR_BLK_ERASE_COUNT = 23,
200 ACMD41_SD_SEND_OP_COND = 41,
201 ACMD42_SET_CLR_CARD_DETECT = 42,
202 ACMD51_SEND_SCR = 51,
206 int _cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg,
bool isAcmd = 0, uint32_t *resp = NULL);
219 uint32_t _go_idle_state();
220 int _initialise_card();
222 mbed::bd_size_t _sectors;
223 mbed::bd_size_t _sd_sectors();
225 bool _is_valid_trim(mbed::bd_addr_t addr, mbed::bd_size_t size);
228 mbed::Timer _spi_timer;
230 uint32_t _transfer_sck;
235 uint8_t _cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg);
236 void _spi_wait(uint8_t count);
238 bool _wait_token(uint8_t token);
239 bool _wait_ready(uint16_t ms = 300);
240 int _read(uint8_t *buffer, uint32_t length);
241 int _read_bytes(uint8_t *buffer, uint32_t length);
242 uint8_t _write(
const uint8_t *buffer, uint8_t token, uint32_t length);
255 virtual void unlock()
261 static const uint32_t _block_size;
262 uint32_t _erase_size;
263 bool _is_initialized;
265 uint32_t _init_ref_count;
267 #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 (using dynamic pin-map)
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.