Flash
The Flash module provides low-level access to flash memory partitions.
import flash from "embedded:storage/flash";Static Methods
Section titled “Static Methods”open(options)
Section titled “open(options)”Instantiates a Flash Partition instance from a flash partition path name.
flash.open({ path, mode, format })Parameters
Section titled “Parameters”options
path- A string indicating the name of the flash partition path name to open.
mode- A string indicating the mode used to access the partition. Values are"r"and"r+". Defaults to"r+".
format- A string indicating the data format to use for read and write operations. The only supported value is"buffer".
Flash Partition Class Pattern
Section titled “Flash Partition Class Pattern”status()
Section titled “status()”Returns an object with information about the partition.
Properties
Section titled “Properties”
size- The total number of bytes in the partition.
blockLength- The number of bytes in a block (sector).
blocks- The number of blocks in the partition.
eraseBlock(from[, to])
Section titled “eraseBlock(from[, to])”Erases one or more blocks in the partition.
read(count, offset)
Section titled “read(count, offset)”Reads count bytes from the partition starting at offset.
write(data, offset)
Section titled “write(data, offset)”Writes data to the partition starting at offset.
close()
Section titled “close()”Releases all resources associated with the partition instance.
Examples
Section titled “Examples”import flash from "embedded:storage/flash";
let partition = flash.open({ path: "ota-bootloader" });let status = partition.status();
partition.eraseBlock(0);partition.write(new Uint8Array([0x01, 0x02]), 0);
partition.close();