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 "blockdevice/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
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);
224 int _spi_send_read_sfdp_command(
mbed::bd_addr_t addr, mbed::sfdp_cmd_addr_size_t addr_size,
225 uint8_t inst, uint8_t dummy_cycles,
233 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
int &read_inst);
249 spif_bd_error _spi_send_general_command(
int instruction,
mbed::bd_addr_t addr,
char *tx_buffer,
250 size_t tx_length,
char *rx_buffer,
size_t rx_length);
253 spif_bd_error _spi_set_frequency(
int freq);
257 int _reset_flash_mem();
260 int _set_write_enable();
263 bool _is_mem_ready();
266 int _handle_vendor_quirks();
277 int _read_instruction;
278 int _prog_instruction;
279 int _erase_instruction;
284 unsigned int _page_size_bytes;
288 unsigned int _address_size;
289 unsigned int _read_dummy_and_mode_cycles;
290 unsigned int _write_dummy_and_mode_cycles;
291 unsigned int _dummy_and_mode_cycles;
292 uint32_t _init_ref_count;
293 bool _is_initialized;
BlockDevice for SFDP based flash devices over SPI bus.
virtual const char * get_type() const
Get the BlockDevice class type.
virtual mbed::bd_size_t get_read_size() const
Get the size of a readable block.
virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Read blocks from a block device.
virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Program blocks to a block device.
virtual mbed::bd_size_t get_program_size() const
Get the size of a programable block.
virtual mbed::bd_size_t size() const
Get the total size of the underlying device.
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 mbed::bd_size_t get_erase_size() const
Get the size of an erasable block.
virtual int deinit()
Deinitialize a block device.
virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size)
Erase blocks on a block device.
~SPIFBlockDevice()
Desctruct SPIFBlockDevice.
virtual int init()
Initialize a block device.
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const
Get the size of minimal erasable sector size of given address.
virtual int get_erase_value() const
Get the value of storage byte after it was erased.
A hardware device capable of writing and reading blocks.
Callback class based on template specialization.
An SPI Master, used for communicating with SPI slave devices.
uint64_t bd_size_t
Type representing a quantity of 8-bit bytes.
uint64_t bd_addr_t
Type representing the address of a specific block.
Utility class for creating and using a singleton.
SFDP JEDEC Parameter Table info.