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,
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,
63 QSPIF_BD_ERROR_INVALID_ARGUMENT = -4008
70enum qspif_polarity_mode {
71 QSPIF_POLARITY_MODE_0 = 0,
75#define QSPIF_MAX_ACTIVE_FLASH_DEVICES 10
130 PinName io1 = MBED_CONF_QSPIF_QSPI_IO1,
131 PinName io2 = MBED_CONF_QSPIF_QSPI_IO2,
132 PinName io3 = MBED_CONF_QSPIF_QSPI_IO3,
133 PinName sclk = MBED_CONF_QSPIF_QSPI_SCK,
134 PinName csel = MBED_CONF_QSPIF_QSPI_CSN,
135 int clock_mode = MBED_CONF_QSPIF_QSPI_POLARITY_MODE,
136 int freq = MBED_CONF_QSPIF_QSPI_FREQ);
258 int add_new_csel_instance(PinName csel);
261 int remove_csel_instance(PinName csel);
281 int _qspi_send_read_sfdp_command(
mbed::bd_addr_t addr, mbed::sfdp_cmd_addr_size_t addr_size,
282 uint8_t inst, uint8_t dummy_cycles,
286 qspi_status_t _qspi_read_status_registers(uint8_t *reg_buffer);
289 qspi_status_t _qspi_write_status_registers(uint8_t *reg_buffer);
301 int _clear_block_protection();
304 int _set_write_enable();
307 bool _is_mem_ready();
310 int _enable_fast_mode();
313 int _handle_vendor_quirks();
323 int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
326 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
327 bool &set_quad_enable,
bool &is_qpi_mode);
330 int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
333 int _sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr);
336 int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr,
int basic_param_table_size);
339 enum qspif_clear_protection_method_t {
348 static int _number_of_active_qspif_flash_csel;
350 int _unique_device_status;
361 unsigned int _num_status_registers;
366 bool _attempt_4_byte_addressing;
371 int _quad_enable_register_idx;
372 int _quad_enable_bit;
374 bool _needs_fast_mode;
377 bool _S25FS512S_quirk;
380 qspif_clear_protection_method_t _clear_protection_method;
385 unsigned int _page_size_bytes;
394 uint8_t _dummy_cycles;
397 uint32_t _init_ref_count;
398 bool _is_initialized;
BlockDevice for SFDP based flash devices over QSPI 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.
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.
~QSPIFBlockDevice()
Desctruct QSPIFBlockDevie.
virtual mbed::bd_size_t get_erase_size() const
Get the size of a eraseable 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.
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 eraseable 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.
A QSPI Driver, used for communicating with QSPI slave devices.
The Mutex class is used to synchronize the execution of threads.
int qspi_inst_t
Type representing a QSPI instruction.
uint8_t qspi_alt_size_t
Alternative size in bits.
enum qspi_status qspi_status_t
QSPI return status.
enum qspi_bus_width qspi_bus_width_t
QSPI Bus width.
enum qspi_address_size qspi_address_size_t
Address size in bits.
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.
SFDP JEDEC Parameter Table info.