17 #ifndef MBED_OSPIF_BLOCK_DEVICE_H 18 #define MBED_OSPIF_BLOCK_DEVICE_H 20 #include "drivers/OSPI.h" 21 #include "drivers/internal/SFDP.h" 22 #include "blockdevice/BlockDevice.h" 23 #include "platform/Callback.h" 25 #ifndef MBED_CONF_OSPIF_OSPI_IO0 26 #define MBED_CONF_OSPIF_OSPI_IO0 NC 28 #ifndef MBED_CONF_OSPIF_OSPI_IO1 29 #define MBED_CONF_OSPIF_OSPI_IO1 NC 31 #ifndef MBED_CONF_OSPIF_OSPI_IO2 32 #define MBED_CONF_OSPIF_OSPI_IO2 NC 34 #ifndef MBED_CONF_OSPIF_OSPI_IO3 35 #define MBED_CONF_OSPIF_OSPI_IO3 NC 37 #ifndef MBED_CONF_OSPIF_OSPI_IO4 38 #define MBED_CONF_OSPIF_OSPI_IO4 NC 40 #ifndef MBED_CONF_OSPIF_OSPI_IO5 41 #define MBED_CONF_OSPIF_OSPI_IO5 NC 43 #ifndef MBED_CONF_OSPIF_OSPI_IO6 44 #define MBED_CONF_OSPIF_OSPI_IO6 NC 46 #ifndef MBED_CONF_OSPIF_OSPI_IO7 47 #define MBED_CONF_OSPIF_OSPI_IO7 NC 49 #ifndef MBED_CONF_OSPIF_OSPI_SCK 50 #define MBED_CONF_OSPIF_OSPI_SCK NC 52 #ifndef MBED_CONF_OSPIF_OSPI_CSN 53 #define MBED_CONF_OSPIF_OSPI_CSN NC 55 #ifndef MBED_CONF_OSPIF_OSPI_DQS 56 #define MBED_CONF_OSPIF_OSPI_DQS NC 58 #ifndef MBED_CONF_OSPIF_OSPI_POLARITY_MODE 59 #define MBED_CONF_OSPIF_OSPI_POLARITY_MODE 0 61 #ifndef MBED_CONF_OSPIF_OSPI_FREQ 62 #define MBED_CONF_OSPIF_OSPI_FREQ 40000000 70 OSPIF_BD_ERROR_OK = 0,
71 OSPIF_BD_ERROR_DEVICE_ERROR = BD_ERROR_DEVICE_ERROR,
72 OSPIF_BD_ERROR_PARSING_FAILED = -4002,
73 OSPIF_BD_ERROR_READY_FAILED = -4003,
74 OSPIF_BD_ERROR_WREN_FAILED = -4004,
75 OSPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005,
76 OSPIF_BD_ERROR_DEVICE_NOT_UNIQUE = -4006,
77 OSPIF_BD_ERROR_DEVICE_MAX_EXCEED = -4007
90 enum ospif_polarity_mode {
91 OSPIF_POLARITY_MODE_0 = 0,
95 #define OSPIF_MAX_ACTIVE_FLASH_DEVICES 10 155 PinName io1 = MBED_CONF_OSPIF_OSPI_IO1,
156 PinName io2 = MBED_CONF_OSPIF_OSPI_IO2,
157 PinName io3 = MBED_CONF_OSPIF_OSPI_IO3,
158 PinName io4 = MBED_CONF_OSPIF_OSPI_IO4,
159 PinName io5 = MBED_CONF_OSPIF_OSPI_IO5,
160 PinName io6 = MBED_CONF_OSPIF_OSPI_IO6,
161 PinName io7 = MBED_CONF_OSPIF_OSPI_IO7,
162 PinName sclk = MBED_CONF_OSPIF_OSPI_SCK,
163 PinName csel = MBED_CONF_OSPIF_OSPI_CSN,
164 PinName dqs = MBED_CONF_OSPIF_OSPI_DQS,
165 int clock_mode = MBED_CONF_OSPIF_OSPI_POLARITY_MODE,
166 int freq = MBED_CONF_OSPIF_OSPI_FREQ);
199 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
214 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
229 virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
274 virtual mbed::bd_size_t
size()
const;
280 virtual const char *
get_type()
const;
299 int add_new_csel_instance(PinName csel);
302 int remove_csel_instance(PinName csel);
308 ospi_status_t _ospi_send_program_command(
mbed::ospi_inst_t prog_instruction,
const void *buffer,
309 mbed::bd_addr_t addr, mbed::bd_size_t *size);
312 ospi_status_t _ospi_send_read_command(
mbed::ospi_inst_t read_instruction,
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
315 ospi_status_t _ospi_send_erase_command(
mbed::ospi_inst_t erase_instruction, mbed::bd_addr_t addr, mbed::bd_size_t size);
318 ospi_status_t _ospi_send_general_command(
mbed::ospi_inst_t instruction_int, mbed::bd_addr_t addr,
const char *tx_buffer,
319 mbed::bd_size_t tx_length,
const char *rx_buffer, mbed::bd_size_t rx_length);
322 int _ospi_send_read_sfdp_command(mbed::bd_addr_t addr,
void *rx_buffer, mbed::bd_size_t rx_length);
325 ospi_status_t _ospi_read_status_registers(uint8_t *reg_buffer);
328 ospi_status_t _ospi_write_status_registers(uint8_t *reg_buffer);
331 ospi_status_t _ospi_set_frequency(
int freq);
334 ospi_status_t _ospi_update_4byte_ext_addr_reg(bd_addr_t addr);
340 int _clear_block_protection();
343 int _set_write_enable();
346 bool _is_mem_ready();
349 int _enable_fast_mode();
352 int _enable_opi_mdoe();
355 int _handle_vendor_quirks();
361 int _sfdp_parse_basic_param_table(
mbed::Callback<
int(mbed::bd_addr_t,
void *, mbed::bd_size_t)> sfdp_reader,
365 int _sfdp_parse_4_byte_inst_table(
mbed::Callback<
int(mbed::bd_addr_t,
void *, mbed::bd_size_t)> sfdp_reader,
369 int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
372 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
373 bool &set_quad_enable,
bool &is_qpi_mode,
bool &is_opi_mode);
376 int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
379 int _sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr);
382 int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr,
int basic_param_table_size);
385 enum ospif_clear_protection_method_t {
397 static int _number_of_active_ospif_flash_csel;
398 static PinName *_active_ospif_flash_csel_arr;
400 int _unique_device_status;
413 unsigned int _num_status_registers;
418 bool _attempt_4_byte_addressing;
423 bool _support_4_byte_inst;
426 int _quad_enable_register_idx;
427 int _quad_enable_bit;
429 bool _needs_fast_mode;
432 ospif_clear_protection_method_t _clear_protection_method;
437 unsigned int _page_size_bytes;
441 ospi_bus_width_t _inst_width;
442 ospi_inst_size_t _inst_size;
443 ospi_bus_width_t _address_width;
444 ospi_address_size_t _address_size;
445 ospi_alt_size_t _alt_size;
447 uint8_t _dummy_cycles;
448 ospi_bus_width_t _data_width;
450 uint32_t _init_ref_count;
451 bool _is_initialized;
virtual int get_erase_value() const
Get the value of storage byte after it was erased.
virtual int deinit()
Deinitialize a block device.
BlockDevice for SFDP based flash devices over OSPI bus.
virtual int change_mode(int mode)
Change the operation mode(SPI, SOPI or DOPI) of flash.
A hardware device capable of writing and reading blocks.
A OSPI Driver, used for communicating with OSPI slave devices.
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 erase(mbed::bd_addr_t addr, mbed::bd_size_t size)
Erase blocks on a block device.
virtual int init()
Initialize a block device.
SFDP JEDEC Parameter Table info.
virtual mbed::bd_size_t get_erase_size() const
Get the size of a eraseable block.
virtual mbed::bd_size_t size() const
Get the total size of the underlying device.
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.
int ospi_inst_t
Type representing a OSPI instruction.
virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Read blocks from a block device.
OSPIFBlockDevice(PinName io0=NC, PinName io1=NC, PinName io2=NC, PinName io3=NC, PinName io4=NC, PinName io5=NC, PinName io6=NC, PinName io7=NC, PinName sclk=NC, PinName csel=NC, PinName dqs=NC, int clock_mode=0, int freq=40000000)
Create OSPIFBlockDevice - An SFDP based Flash Block Device over OSPI bus.
~OSPIFBlockDevice()
Desctruct OSPIFBlockDevie.
Callback class based on template specialization.