SDK docs menu

class

Memory

One of the board's memory chips (an F-RAM, an EEPROM, a SPI NOR), as the firmware sees it now.

from hardlabs_sdk import Memory

Get one from Board.memory or Part.memory. Its contents last as long as the simulation: they start as the images you gave it ("config.bin@U7") or blank, change as the firmware writes them, survive Board.restart, and go when the board stops. Read or save them before then to keep them.

mem[0x100] reads one byte and mem[0:16] a range; len(mem) is its size.

Usage

u7 = board.memory("U7")
header = u7.read(0, 16)
u7.write(0x100, b"4")
assert u7[0x100:0x102] == b"4"

Attributes

boardBoard
The board it is on.
namestr
Its reference designator, else its slot.
refstr | None
Its reference designator, e.g. U7.
slotstr
The simulation's name for it.
modelstr | None
The simulation model behind it.
sizeint | None
Its size in bytes.

Memory.readmethod

Reads bytes from the chip as they are now.

mem.read(offset=0, length=None) -> bytes

Arguments

offsetintdefault 0
Where to start.
lengthint | Nonedefault None
How many bytes. None reads to the end.

Returns

bytes — The chip's bytes.

Raises

  • HardLabsError — The range runs past the chip's end, or the board isn't running.

Memory.writemethod

Writes bytes into the chip now, as if another device wrote them.

mem.write(offset, data)

The firmware reads them from its next access.

Arguments

offsetint
Where to write.
databytes
The bytes.

Raises

  • HardLabsError — The bytes run past the chip's end, or the board isn't running.

Memory.savemethod

Saves the chip's whole contents into a file.

mem.save(path) -> Path

Arguments

pathUnion[str, Path]
The file to write. Its folder is made if needed.

Returns

Path — The file written.