17 #ifndef MBED_OSPIF_BLOCK_DEVICE_H 18 #define MBED_OSPIF_BLOCK_DEVICE_H 20 #include "drivers/OSPI.h" 21 #include "blockdevice/internal/SFDP.h" 22 #include "blockdevice/BlockDevice.h" 23 #include "platform/Callback.h" 25 #if defined(TARGET_MX25LM51245G) 26 #include "MX25LM51245G_config.h" 29 #if defined(TARGET_MX25LW51245G) 30 #include "MX25LW51245G_config.h" 33 #ifndef MBED_CONF_OSPIF_OSPI_IO0 34 #define MBED_CONF_OSPIF_OSPI_IO0 NC 36 #ifndef MBED_CONF_OSPIF_OSPI_IO1 37 #define MBED_CONF_OSPIF_OSPI_IO1 NC 39 #ifndef MBED_CONF_OSPIF_OSPI_IO2 40 #define MBED_CONF_OSPIF_OSPI_IO2 NC 42 #ifndef MBED_CONF_OSPIF_OSPI_IO3 43 #define MBED_CONF_OSPIF_OSPI_IO3 NC 45 #ifndef MBED_CONF_OSPIF_OSPI_IO4 46 #define MBED_CONF_OSPIF_OSPI_IO4 NC 48 #ifndef MBED_CONF_OSPIF_OSPI_IO5 49 #define MBED_CONF_OSPIF_OSPI_IO5 NC 51 #ifndef MBED_CONF_OSPIF_OSPI_IO6 52 #define MBED_CONF_OSPIF_OSPI_IO6 NC 54 #ifndef MBED_CONF_OSPIF_OSPI_IO7 55 #define MBED_CONF_OSPIF_OSPI_IO7 NC 57 #ifndef MBED_CONF_OSPIF_OSPI_SCK 58 #define MBED_CONF_OSPIF_OSPI_SCK NC 60 #ifndef MBED_CONF_OSPIF_OSPI_CSN 61 #define MBED_CONF_OSPIF_OSPI_CSN NC 63 #ifndef MBED_CONF_OSPIF_OSPI_DQS 64 #define MBED_CONF_OSPIF_OSPI_DQS NC 66 #ifndef MBED_CONF_OSPIF_OSPI_POLARITY_MODE 67 #define MBED_CONF_OSPIF_OSPI_POLARITY_MODE 0 69 #ifndef MBED_CONF_OSPIF_OSPI_FREQ 70 #define MBED_CONF_OSPIF_OSPI_FREQ 40000000 78 OSPIF_BD_ERROR_OK = 0,
79 OSPIF_BD_ERROR_DEVICE_ERROR = mbed::BD_ERROR_DEVICE_ERROR,
80 OSPIF_BD_ERROR_PARSING_FAILED = -4002,
81 OSPIF_BD_ERROR_READY_FAILED = -4003,
82 OSPIF_BD_ERROR_WREN_FAILED = -4004,
83 OSPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005,
84 OSPIF_BD_ERROR_DEVICE_NOT_UNIQUE = -4006,
85 OSPIF_BD_ERROR_DEVICE_MAX_EXCEED = -4007
98 enum ospif_polarity_mode {
99 OSPIF_POLARITY_MODE_0 = 0,
100 OSPIF_POLARITY_MODE_1
103 #define OSPIF_MAX_ACTIVE_FLASH_DEVICES 10 163 PinName io1 = MBED_CONF_OSPIF_OSPI_IO1,
164 PinName io2 = MBED_CONF_OSPIF_OSPI_IO2,
165 PinName io3 = MBED_CONF_OSPIF_OSPI_IO3,
166 PinName io4 = MBED_CONF_OSPIF_OSPI_IO4,
167 PinName io5 = MBED_CONF_OSPIF_OSPI_IO5,
168 PinName io6 = MBED_CONF_OSPIF_OSPI_IO6,
169 PinName io7 = MBED_CONF_OSPIF_OSPI_IO7,
170 PinName sclk = MBED_CONF_OSPIF_OSPI_SCK,
171 PinName csel = MBED_CONF_OSPIF_OSPI_CSN,
172 PinName dqs = MBED_CONF_OSPIF_OSPI_DQS,
173 int clock_mode = MBED_CONF_OSPIF_OSPI_POLARITY_MODE,
174 int freq = MBED_CONF_OSPIF_OSPI_FREQ);
207 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
222 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
237 virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
282 virtual mbed::bd_size_t
size()
const;
288 virtual const char *
get_type()
const;
307 int add_new_csel_instance(PinName csel);
310 int remove_csel_instance(PinName csel);
316 ospi_status_t _ospi_send_program_command(
mbed::ospi_inst_t prog_instruction,
const void *buffer,
317 mbed::bd_addr_t addr, mbed::bd_size_t *size);
320 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);
323 ospi_status_t _ospi_send_erase_command(
mbed::ospi_inst_t erase_instruction, mbed::bd_addr_t addr, mbed::bd_size_t size);
326 ospi_status_t _ospi_send_general_command(
mbed::ospi_inst_t instruction_int, mbed::bd_addr_t addr,
const char *tx_buffer,
327 mbed::bd_size_t tx_length,
const char *rx_buffer, mbed::bd_size_t rx_length);
330 int _ospi_send_read_sfdp_command(mbed::bd_addr_t addr, mbed::sfdp_cmd_addr_size_t addr_size,
331 uint8_t inst, uint8_t dummy_cycles,
332 void *rx_buffer, mbed::bd_size_t rx_length);
335 ospi_status_t _ospi_read_status_registers(uint8_t *reg_buffer);
338 ospi_status_t _ospi_write_status_registers(uint8_t *reg_buffer);
341 ospi_status_t _ospi_set_frequency(
int freq);
344 ospi_status_t _ospi_update_4byte_ext_addr_reg(mbed::bd_addr_t addr);
350 int _clear_block_protection();
353 int _set_write_enable();
356 bool _is_mem_ready();
359 int _enable_fast_mode();
362 int _enable_opi_mdoe();
365 int _handle_vendor_quirks();
371 int _sfdp_parse_basic_param_table(
mbed::Callback<
int(mbed::bd_addr_t, mbed::sfdp_cmd_addr_size_t, uint8_t, uint8_t,
void *, mbed::bd_size_t)> sfdp_reader,
375 int _sfdp_parse_4_byte_inst_table(
mbed::Callback<
int(mbed::bd_addr_t, mbed::sfdp_cmd_addr_size_t, uint8_t, uint8_t,
void *, mbed::bd_size_t)> sfdp_reader,
379 int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
382 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
383 bool &set_quad_enable,
bool &is_qpi_mode,
bool &is_opi_mode);
386 int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
389 int _sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr);
392 int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr,
int basic_param_table_size);
394 #ifdef MX_FLASH_SUPPORT_RWW 395 bool _is_mem_ready_rww(bd_addr_t addr, uint8_t rw);
399 enum ospif_clear_protection_method_t {
411 static int _number_of_active_ospif_flash_csel;
412 static PinName *_active_ospif_flash_csel_arr;
414 int _unique_device_status;
427 unsigned int _num_status_registers;
432 bool _attempt_4_byte_addressing;
437 bool _support_4_byte_inst;
440 int _quad_enable_register_idx;
441 int _quad_enable_bit;
443 bool _needs_fast_mode;
446 ospif_clear_protection_method_t _clear_protection_method;
451 unsigned int _page_size_bytes;
455 ospi_bus_width_t _inst_width;
456 ospi_inst_size_t _inst_size;
457 ospi_bus_width_t _address_width;
458 ospi_address_size_t _address_size;
459 ospi_alt_size_t _alt_size;
461 uint8_t _dummy_cycles;
462 ospi_bus_width_t _data_width;
464 uint32_t _init_ref_count;
465 bool _is_initialized;
466 #ifdef MX_FLASH_SUPPORT_RWW 473 wait_flag _wait_flag;
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.