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,
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
93 OSPIF_OPI_MODE_SPI = 0,
102enum ospif_polarity_mode {
103 OSPIF_POLARITY_MODE_0 = 0,
104 OSPIF_POLARITY_MODE_1
107#define OSPIF_MAX_ACTIVE_FLASH_DEVICES 10
167 PinName io1 = MBED_CONF_OSPIF_OSPI_IO1,
168 PinName io2 = MBED_CONF_OSPIF_OSPI_IO2,
169 PinName io3 = MBED_CONF_OSPIF_OSPI_IO3,
170 PinName io4 = MBED_CONF_OSPIF_OSPI_IO4,
171 PinName io5 = MBED_CONF_OSPIF_OSPI_IO5,
172 PinName io6 = MBED_CONF_OSPIF_OSPI_IO6,
173 PinName io7 = MBED_CONF_OSPIF_OSPI_IO7,
174 PinName sclk = MBED_CONF_OSPIF_OSPI_SCK,
175 PinName csel = MBED_CONF_OSPIF_OSPI_CSN,
176 PinName dqs = MBED_CONF_OSPIF_OSPI_DQS,
177 int clock_mode = MBED_CONF_OSPIF_OSPI_POLARITY_MODE,
178 int freq = MBED_CONF_OSPIF_OSPI_FREQ);
311 int add_new_csel_instance(PinName csel);
314 int remove_csel_instance(PinName csel);
320 ospi_status_t _ospi_send_program_command(
mbed::ospi_inst_t prog_instruction,
const void *buffer,
334 int _ospi_send_read_sfdp_command(
mbed::bd_addr_t addr, mbed::sfdp_cmd_addr_size_t addr_size,
335 uint8_t inst, uint8_t dummy_cycles,
339 ospi_status_t _ospi_read_status_registers(uint8_t *reg_buffer);
342 ospi_status_t _ospi_write_status_registers(uint8_t *reg_buffer);
345 ospi_status_t _ospi_set_frequency(
int freq);
354 int _clear_block_protection();
357 int _set_write_enable();
360 bool _is_mem_ready();
363 int _enable_fast_mode();
366 int _enable_opi_mdoe();
369 int _handle_vendor_quirks();
383 int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
386 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
387 bool &set_quad_enable,
bool &is_qpi_mode,
bool &is_opi_mode);
390 int _sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr);
393 int _sfdp_set_qpi_enabled(uint8_t *basic_param_table_ptr);
396 int _sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_param_table_ptr,
int basic_param_table_size);
398#ifdef MX_FLASH_SUPPORT_RWW
399 bool _is_mem_ready_rww(bd_addr_t addr, uint8_t rw);
403 enum ospif_clear_protection_method_t {
412 static int _number_of_active_ospif_flash_csel;
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;
BlockDevice for SFDP based flash devices over OSPI bus.
virtual const char * get_type() const
Get the BlockDevice class type.
virtual int change_mode(int mode)
Change the operation mode(SPI, SOPI or DOPI) of flash.
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.
~OSPIFBlockDevice()
Desctruct OSPIFBlockDevie.
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.
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.
virtual int init()
Initialize a block device.
virtual int get_erase_value() const
Get the value of storage byte after it was erased.
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr)
Get the size of minimal eraseable sector size of given address.
A hardware device capable of writing and reading blocks.
Callback class based on template specialization.
A OSPI Driver, used for communicating with OSPI slave devices.
The Mutex class is used to synchronize the execution of threads.
int ospi_inst_t
Type representing a OSPI instruction.
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.