17 #ifndef MBED_SPIF_BLOCK_DEVICE_H 18 #define MBED_SPIF_BLOCK_DEVICE_H 20 #include "platform/SingletonPtr.h" 21 #include "drivers/SPI.h" 22 #include "drivers/DigitalOut.h" 23 #include "drivers/internal/SFDP.h" 24 #include "blockdevice/BlockDevice.h" 26 #ifndef MBED_CONF_SPIF_DRIVER_SPI_MOSI 27 #define MBED_CONF_SPIF_DRIVER_SPI_MOSI NC 29 #ifndef MBED_CONF_SPIF_DRIVER_SPI_MISO 30 #define MBED_CONF_SPIF_DRIVER_SPI_MISO NC 32 #ifndef MBED_CONF_SPIF_DRIVER_SPI_CLK 33 #define MBED_CONF_SPIF_DRIVER_SPI_CLK NC 35 #ifndef MBED_CONF_SPIF_DRIVER_SPI_CS 36 #define MBED_CONF_SPIF_DRIVER_SPI_CS NC 38 #ifndef MBED_CONF_SPIF_DRIVER_SPI_FREQ 39 #define MBED_CONF_SPIF_DRIVER_SPI_FREQ 40000000 48 SPIF_BD_ERROR_DEVICE_ERROR = BD_ERROR_DEVICE_ERROR,
49 SPIF_BD_ERROR_PARSING_FAILED = -4002,
50 SPIF_BD_ERROR_READY_FAILED = -4003,
51 SPIF_BD_ERROR_WREN_FAILED = -4004,
52 SPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005,
104 PinName miso = MBED_CONF_SPIF_DRIVER_SPI_MISO,
105 PinName sclk = MBED_CONF_SPIF_DRIVER_SPI_CLK,
106 PinName csel = MBED_CONF_SPIF_DRIVER_SPI_CS,
107 int freq = MBED_CONF_SPIF_DRIVER_SPI_FREQ);
139 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
153 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
166 virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
194 virtual mbed::bd_size_t
get_erase_size(mbed::bd_addr_t addr)
const;
211 virtual mbed::bd_size_t
size()
const;
217 virtual const char *
get_type()
const;
224 int _spi_send_read_sfdp_command(mbed::bd_addr_t addr,
void *rx_buffer, mbed::bd_size_t rx_length);
227 int _sfdp_parse_basic_param_table(
mbed::Callback<
int(mbed::bd_addr_t,
void *, mbed::bd_size_t)> sfdp_reader,
231 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
int &read_inst);
237 spif_bd_error _spi_send_program_command(
int prog_inst,
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
241 spif_bd_error _spi_send_read_command(
int read_inst, uint8_t *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
244 spif_bd_error _spi_send_erase_command(
int erase_inst, mbed::bd_addr_t addr, mbed::bd_size_t size);
247 spif_bd_error _spi_send_general_command(
int instruction, mbed::bd_addr_t addr,
char *tx_buffer,
248 size_t tx_length,
char *rx_buffer,
size_t rx_length);
251 spif_bd_error _spi_set_frequency(
int freq);
255 int _reset_flash_mem();
258 int _set_write_enable();
261 bool _is_mem_ready();
264 int _handle_vendor_quirks();
275 int _read_instruction;
276 int _prog_instruction;
277 int _erase_instruction;
282 unsigned int _page_size_bytes;
283 bd_size_t _device_size_bytes;
286 unsigned int _address_size;
287 unsigned int _read_dummy_and_mode_cycles;
288 unsigned int _write_dummy_and_mode_cycles;
289 unsigned int _dummy_and_mode_cycles;
290 uint32_t _init_ref_count;
291 bool _is_initialized;
virtual mbed::bd_size_t get_read_size() const
Get the size of a readable block.
virtual const char * get_type() const
Get the BlockDevice class type.
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.
virtual int get_erase_value() const
Get the value of storage byte after it was erased.
BlockDevice for SFDP based flash devices over SPI bus.
~SPIFBlockDevice()
Desctruct SPIFBlockDevice.
virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Read blocks from a block device.
SFDP JEDEC Parameter Table info.
virtual mbed::bd_size_t get_program_size() const
Get the size of a programable block.
virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Program blocks to a block device.
virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size)
Erase blocks on a block device.
A SPI Master, used for communicating with SPI slave devices.
SPIFBlockDevice(PinName mosi=NC, PinName miso=NC, PinName sclk=NC, PinName csel=NC, int freq=40000000)
Creates a SPIFBlockDevice on a SPI bus specified by pins.
virtual int deinit()
Deinitialize a block device.
Callback class based on template specialization.
virtual mbed::bd_size_t get_erase_size() const
Get the size of an erasable block.