16 #ifndef MBED_SPIF_BLOCK_DEVICE_H 17 #define MBED_SPIF_BLOCK_DEVICE_H 19 #include "platform/SingletonPtr.h" 21 #include "DigitalOut.h" 22 #include "BlockDevice.h" 30 SPIF_BD_ERROR_DEVICE_ERROR = BD_ERROR_DEVICE_ERROR,
31 SPIF_BD_ERROR_PARSING_FAILED = -4002,
32 SPIF_BD_ERROR_READY_FAILED = -4003,
33 SPIF_BD_ERROR_WREN_FAILED = -4004,
34 SPIF_BD_ERROR_INVALID_ERASE_PARAMS = -4005,
38 #define SPIF_MAX_REGIONS 10 39 #define MAX_NUM_OF_ERASE_TYPES 4 86 SPIFBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName csel,
int freq = 40000000);
118 virtual int read(
void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t
size);
132 virtual int program(
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
145 virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
173 virtual mbed::bd_size_t
get_erase_size(mbed::bd_addr_t addr)
const;
190 virtual mbed::bd_size_t
size()
const;
196 virtual const char *
get_type()
const;
206 int _sfdp_parse_sfdp_headers(uint32_t &basic_table_addr,
size_t &basic_table_size,
207 uint32_t §or_map_table_addr,
size_t §or_map_table_size);
210 int _sfdp_parse_basic_param_table(uint32_t basic_table_addr,
size_t basic_table_size);
213 int _sfdp_parse_sector_map_table(uint32_t sector_map_table_addr,
size_t sector_map_table_size);
216 int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
int &read_inst);
219 unsigned int _sfdp_detect_page_size(uint8_t *basic_param_table_ptr,
int basic_param_table_size);
222 int _sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param_table_ptr,
int basic_param_table_size,
224 int *erase_type_inst_arr,
unsigned int *erase_type_size_arr);
230 int _utils_find_addr_region(bd_size_t offset)
const;
234 int _utils_iterate_next_largest_erase_type(uint8_t &bitfield,
int size,
int offset,
int boundry);
240 spif_bd_error _spi_send_program_command(
int prog_inst,
const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
244 spif_bd_error _spi_send_read_command(
int read_inst, uint8_t *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
247 spif_bd_error _spi_send_erase_command(
int erase_inst, mbed::bd_addr_t addr, mbed::bd_size_t size);
250 spif_bd_error _spi_send_general_command(
int instruction, mbed::bd_addr_t addr,
char *tx_buffer,
251 size_t tx_length,
char *rx_buffer,
size_t rx_length);
254 spif_bd_error _spi_set_frequency(
int freq);
258 int _reset_flash_mem();
261 int _set_write_enable();
264 bool _is_mem_ready();
277 int _read_instruction;
278 int _prog_instruction;
279 int _erase_instruction;
283 int _erase_type_inst_arr[MAX_NUM_OF_ERASE_TYPES];
284 unsigned int _erase_type_size_arr[MAX_NUM_OF_ERASE_TYPES];
288 int _region_size_bytes[SPIF_MAX_REGIONS];
289 bd_size_t _region_high_boundary[SPIF_MAX_REGIONS];
291 uint8_t _region_erase_types_bitfield[SPIF_MAX_REGIONS];
292 unsigned int _min_common_erase_size;
294 unsigned int _page_size_bytes;
295 bd_size_t _device_size_bytes;
298 unsigned int _address_size;
299 unsigned int _read_dummy_and_mode_cycles;
300 unsigned int _write_dummy_and_mode_cycles;
301 unsigned int _dummy_and_mode_cycles;
302 uint32_t _init_ref_count;
303 bool _is_initialized;
virtual mbed::bd_size_t get_read_size() const
Get the size of a readable block.
virtual const char * get_type() const
Get the BlockDevice class type.
A hardware device capable of writing and reading blocks.
virtual int init()
Initialize a block device.
virtual mbed::bd_size_t size() const
Get the total size of the underlying device.
SPIFBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName csel, int freq=40000000)
Creates a SPIFBlockDevice on a SPI bus specified by pins.
virtual int get_erase_value() const
Get the value of storage byte after it was erased.
BlockDevice for SFDP based flash devices over SPI bus.
~SPIFBlockDevice()
Desctruct SPIFBlockDevice.
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 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.
virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size)
Erase blocks on a block device.
A digital output, used for setting the state of a pin.
A SPI Master, used for communicating with SPI slave devices.
virtual int deinit()
Deinitialize a block device.
virtual mbed::bd_size_t get_erase_size() const
Get the size of an erasable block.