Workshop example
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
QSPIFBlockDevice Class Reference
BlockDevice for SFDP based flash devices over QSPI bus. More...
#include <QSPIFBlockDevice.h>
Public Member Functions | |
QSPIFBlockDevice (PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName csel, int clock_mode, int freq=MBED_CONF_QSPIF_QSPI_FREQ) | |
Create QSPIFBlockDevice - An SFDP based Flash Block Device over QSPI bus. | |
virtual int | init () |
Initialize a block device. | |
virtual int | deinit () |
Deinitialize a block device. | |
~QSPIFBlockDevice () | |
Desctruct QSPIFBlockDevie. | |
virtual int | read (void *buffer, bd_addr_t addr, bd_size_t size) |
Read blocks from a block device. | |
virtual int | program (const void *buffer, bd_addr_t addr, bd_size_t size) |
Program blocks to a block device. | |
virtual int | erase (bd_addr_t addr, bd_size_t size) |
Erase blocks on a block device. | |
virtual bd_size_t | get_read_size () const |
Get the size of a readable block. | |
virtual bd_size_t | get_program_size () const |
Get the size of a programable block. | |
virtual bd_size_t | get_erase_size () const |
Get the size of a eraseable block. | |
virtual bd_size_t | get_erase_size (bd_addr_t addr) |
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. | |
virtual bd_size_t | size () const |
Get the total size of the underlying device. |
Detailed Description
BlockDevice for SFDP based flash devices over QSPI bus.
// Here's an example using QSPI flash device on DISCO_L476VG target #include "mbed.h" #include "QSPIFBlockDevice.h" QSPIFBlockDevice block_device(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0, MBED_CONF_QSPIF_QSPI_FREQ); int main() { printf("QSPI SFDP Flash Block Device example\n"); // Initialize the SPI flash device and print the memory layout block_device.init(); bd_size_t sector_size_at_address_0 = block_device.get_erase_size(0); printf("QSPIF BD size: %llu\n", block_device.size()); printf("QSPIF BD read size: %llu\n", block_device.get_read_size()); printf("QSPIF BD program size: %llu\n", block_device.get_program_size()); printf("QSPIF BD erase size (at address 0): %llu\n", sector_size_at_address_0); // Write "Hello World!" to the first block char *buffer = (char *) malloc(sector_size_at_address_0); sprintf(buffer, "Hello World!\n"); block_device.erase(0, sector_size_at_address_0); block_device.program(buffer, 0, sector_size_at_address_0); // Read back what was stored block_device.read(buffer, 0, sector_size_at_address_0); printf("%s", buffer); // Deinitialize the device block_device.deinit(); }
Definition at line 88 of file QSPIFBlockDevice.h.
Constructor & Destructor Documentation
QSPIFBlockDevice | ( | PinName | io0, |
PinName | io1, | ||
PinName | io2, | ||
PinName | io3, | ||
PinName | sclk, | ||
PinName | csel, | ||
int | clock_mode, | ||
int | freq = MBED_CONF_QSPIF_QSPI_FREQ |
||
) |
Create QSPIFBlockDevice - An SFDP based Flash Block Device over QSPI bus.
- Parameters:
-
io0 1st IO pin used for sending/receiving data during data phase of a transaction io1 2nd IO pin used for sending/receiving data during data phase of a transaction io2 3rd IO pin used for sending/receiving data during data phase of a transaction io3 4th IO pin used for sending/receiving data during data phase of a transaction sclk QSPI Clock pin csel QSPI chip select pin clock_mode specifies the QSPI Clock Polarity mode (QSPIF_POLARITY_MODE_0/QSPIF_POLARITY_MODE_1) default value = 0 freq Clock frequency of the QSPI bus (defaults to 40MHz)
Definition at line 113 of file QSPIFBlockDevice.cpp.
~QSPIFBlockDevice | ( | ) |
Desctruct QSPIFBlockDevie.
Definition at line 124 of file QSPIFBlockDevice.h.
Member Function Documentation
int deinit | ( | ) | [virtual] |
Deinitialize a block device.
- Returns:
- QSPIF_BD_ERROR_OK(0) - success QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
Definition at line 261 of file QSPIFBlockDevice.cpp.
int erase | ( | bd_addr_t | addr, |
bd_size_t | size | ||
) | [virtual] |
Erase blocks on a block device.
The state of an erased block is undefined until it has been programmed
- Parameters:
-
addr Address of block to begin erasing size Size to erase in bytes, must be a multiple of erase block size
- Returns:
- QSPIF_BD_ERROR_OK(0) - success QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed QSPIF_BD_ERROR_READY_FAILED - Waiting for Memory ready failed or timed out QSPIF_BD_ERROR_WREN_FAILED - Write Enable failed QSPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables QSPIF_BD_ERROR_INVALID_ERASE_PARAMS - Trying to erase unaligned address or size
Definition at line 379 of file QSPIFBlockDevice.cpp.
bd_size_t get_erase_size | ( | ) | const [virtual] |
Get the size of a eraseable block.
- Returns:
- Size of a minimal erase block, common to all regions, in bytes
- Note:
- Must be a multiple of the program size
Definition at line 474 of file QSPIFBlockDevice.cpp.
bd_size_t get_erase_size | ( | bd_addr_t | addr ) | [virtual] |
Get the size of minimal eraseable sector size of given address.
- Parameters:
-
addr Any address within block queried for erase sector size (can be any address within flash size offset)
- Returns:
- Size of minimal erase sector size, in given address region, in bytes
- Note:
- Must be a multiple of the program size
Definition at line 481 of file QSPIFBlockDevice.cpp.
int get_erase_value | ( | ) | const [virtual] |
Get the value of storage byte after it was erased.
If get_erase_value returns a non-negative byte value, the underlying storage is set to that value when erased, and storage containing that value can be programmed without another erase.
- Returns:
- The value of storage when erased, or -1 if you can't rely on the value of erased storage
Definition at line 517 of file QSPIFBlockDevice.cpp.
bd_size_t get_program_size | ( | ) | const [virtual] |
Get the size of a programable block.
- Returns:
- Size of a program block size in bytes
- Note:
- Must be a multiple of the read size
Definition at line 468 of file QSPIFBlockDevice.cpp.
bd_size_t get_read_size | ( | ) | const [virtual] |
Get the size of a readable block.
- Returns:
- Size of a readable block in bytes
Definition at line 462 of file QSPIFBlockDevice.cpp.
int init | ( | ) | [virtual] |
Initialize a block device.
- Returns:
- QSPIF_BD_ERROR_OK(0) - success QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed QSPIF_BD_ERROR_READY_FAILED - Waiting for Memory ready failed or timedout QSPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables
Definition at line 130 of file QSPIFBlockDevice.cpp.
int program | ( | const void * | buffer, |
bd_addr_t | addr, | ||
bd_size_t | size | ||
) | [virtual] |
Program blocks to a block device.
The blocks must have been erased prior to being programmed
- Parameters:
-
buffer Buffer of data to write to blocks addr Address of block to begin writing to size Size to write in bytes, must be a multiple of program block size
- Returns:
- QSPIF_BD_ERROR_OK(0) - success QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed QSPIF_BD_ERROR_READY_FAILED - Waiting for Memory ready failed or timed out QSPIF_BD_ERROR_WREN_FAILED - Write Enable failed QSPIF_BD_ERROR_PARSING_FAILED - unexpected format or values in one of the SFDP tables
Definition at line 323 of file QSPIFBlockDevice.cpp.
int read | ( | void * | buffer, |
bd_addr_t | addr, | ||
bd_size_t | size | ||
) | [virtual] |
Read blocks from a block device.
- Parameters:
-
buffer Buffer to write blocks to addr Address of block to begin reading from size Size to read in bytes, must be a multiple of read block size
- Returns:
- QSPIF_BD_ERROR_OK(0) - success QSPIF_BD_ERROR_DEVICE_ERROR - device driver transaction failed
Definition at line 298 of file QSPIFBlockDevice.cpp.
bd_size_t size | ( | ) | const [virtual] |
Get the total size of the underlying device.
- Returns:
- Size of the underlying device in bytes
Definition at line 512 of file QSPIFBlockDevice.cpp.
Generated on Tue Jul 12 2022 22:34:15 by 1.7.2