17 #ifndef MBED_QSPIF_BLOCK_DEVICE_H 18 #define MBED_QSPIF_BLOCK_DEVICE_H 20 #include "drivers/QSPI.h" 21 #include "blockdevice/internal/SFDP.h" 22 #include "blockdevice/BlockDevice.h" 23 #include "platform/Callback.h" 25 #ifndef MBED_CONF_QSPIF_QSPI_IO0 26 #define MBED_CONF_QSPIF_QSPI_IO0 NC 28 #ifndef MBED_CONF_QSPIF_QSPI_IO1 29 #define MBED_CONF_QSPIF_QSPI_IO1 NC 31 #ifndef MBED_CONF_QSPIF_QSPI_IO2 32 #define MBED_CONF_QSPIF_QSPI_IO2 NC 34 #ifndef MBED_CONF_QSPIF_QSPI_IO3 35 #define MBED_CONF_QSPIF_QSPI_IO3 NC 37 #ifndef MBED_CONF_QSPIF_QSPI_SCK 38 #define MBED_CONF_QSPIF_QSPI_SCK NC 40 #ifndef MBED_CONF_QSPIF_QSPI_CSN 41 #define MBED_CONF_QSPIF_QSPI_CSN NC 43 #ifndef MBED_CONF_QSPIF_QSPI_POLARITY_MODE 44 #define MBED_CONF_QSPIF_QSPI_POLARITY_MODE 0 46 #ifndef MBED_CONF_QSPIF_QSPI_FREQ 47 #define MBED_CONF_QSPIF_QSPI_FREQ 40000000 55 QSPIF_BD_ERROR_OK = 0,
56 QSPIF_BD_ERROR_DEVICE_ERROR = mbed::BD_ERROR_DEVICE_ERROR,
57 QSPIF_BD_ERROR_PARSING_FAILED = -4002,
58 QSPIF_BD_ERROR_READY_FAILED = -4003,
59 QSPIF_BD_ERROR_WREN_FAILED = -4004,
60 QSPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005,
61 QSPIF_BD_ERROR_DEVICE_NOT_UNIQUE = -4006,
62 QSPIF_BD_ERROR_DEVICE_MAX_EXCEED = -4007
69 enum qspif_polarity_mode {
70 QSPIF_POLARITY_MODE_0 = 0,
74 #define QSPIF_MAX_ACTIVE_FLASH_DEVICES 10 129 PinName io1 = MBED_CONF_QSPIF_QSPI_IO1,
130 PinName io2 = MBED_CONF_QSPIF_QSPI_IO2,
131 PinName io3 = MBED_CONF_QSPIF_QSPI_IO3,
132 PinName sclk = MBED_CONF_QSPIF_QSPI_SCK,
133 PinName csel = MBED_CONF_QSPIF_QSPI_CSN,
134 int clock_mode = MBED_CONF_QSPIF_QSPI_POLARITY_MODE,
135 int freq = MBED_CONF_QSPIF_QSPI_FREQ);
168 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
183 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
198 virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
226 virtual mbed::bd_size_t
get_erase_size(mbed::bd_addr_t addr)
const;
243 virtual mbed::bd_size_t
size()
const;
249 virtual const char *
get_type()
const;
257 int add_new_csel_instance(PinName csel);
260 int remove_csel_instance(PinName csel);
267 mbed::bd_addr_t addr, mbed::bd_size_t *size);
277 mbed::bd_size_t tx_length,
const char *rx_buffer, mbed::bd_size_t rx_length);
280 int _qspi_send_read_sfdp_command(mbed::bd_addr_t addr,
void *rx_buffer, mbed::bd_size_t rx_length);
283 qspi_status_t _qspi_read_status_registers(uint8_t *reg_buffer);
286 qspi_status_t _qspi_write_status_registers(uint8_t *reg_buffer);
292 qspi_status_t _qspi_update_4byte_ext_addr_reg(mbed::bd_addr_t addr);
298 int _clear_block_protection();
301 int _set_write_enable();
304 bool _is_mem_ready();
307 int _enable_fast_mode();
310 int _handle_vendor_quirks();
316 int _sfdp_parse_basic_param_table(
mbed::Callback<
int(mbed::bd_addr_t,
void *, mbed::bd_size_t)> sfdp_reader,
320 int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
323 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
324 bool &set_quad_enable,
bool &is_qpi_mode);
327 int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
330 int _sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr);
333 int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr,
int basic_param_table_size);
336 enum qspif_clear_protection_method_t {
348 static int _number_of_active_qspif_flash_csel;
349 static PinName *_active_qspif_flash_csel_arr;
351 int _unique_device_status;
362 unsigned int _num_status_registers;
367 bool _attempt_4_byte_addressing;
372 int _quad_enable_register_idx;
373 int _quad_enable_bit;
375 bool _needs_fast_mode;
378 qspif_clear_protection_method_t _clear_protection_method;
383 unsigned int _page_size_bytes;
392 uint8_t _dummy_cycles;
395 uint32_t _init_ref_count;
396 bool _is_initialized;
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.
QSPIFBlockDevice(PinName io0=NC, PinName io1=NC, PinName io2=NC, PinName io3=NC, PinName sclk=NC, PinName csel=NC, int clock_mode=0, int freq=40000000)
Create QSPIFBlockDevice - An SFDP based Flash Block Device over QSPI bus.
A hardware device capable of writing and reading blocks.
virtual mbed::bd_size_t get_erase_size() const
Get the size of a eraseable block.
~QSPIFBlockDevice()
Desctruct QSPIFBlockDevie.
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 size() const
Get the total size of the underlying device.
SFDP JEDEC Parameter Table info.
virtual int get_erase_value() const
Get the value of storage byte after it was erased.
virtual int deinit()
Deinitialize a block device.
virtual mbed::bd_size_t get_read_size() const
Get the size of a readable block.
enum qspi_address_size qspi_address_size_t
Address size in bits.
virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size)
Erase blocks on a block device.
virtual int init()
Initialize a block device.
int qspi_inst_t
Type representing a QSPI instruction.
virtual const char * get_type() const
Get the BlockDevice class type.
uint8_t qspi_alt_size_t
Alternative size in bits.
enum qspi_bus_width qspi_bus_width_t
QSPI Bus width.
BlockDevice for SFDP based flash devices over QSPI bus.
Callback class based on template specialization.
A QSPI Driver, used for communicating with QSPI slave devices.
enum qspi_status qspi_status_t
QSPI return status.