mimxrt — functionality specific to NXP i.MXRT¶
The mimxrt module contains functions and classes specific to the NXP
i.MXRT family of microcontrollers.
Classes¶
- class mimxrt.Flash¶
Get the singleton object that exposes the user-storage region of the on-board QSPI flash as a
vfs.AbstractBlockDev-compatible block device. Block numbers are relative to the start of that region, not the physical start of flash.In most cases, to store persistent data on the device, you’ll want to use a higher-level abstraction – for example the filesystem via Python’s standard file API. This interface is useful to customise the filesystem configuration or implement a low-level storage system for your application.
The object also implements the buffer protocol, allowing read-only memory-mapped access to the entire flash storage region via the QSPI XIP base. This makes a zero-copy view of the region available without issuing any flash reads:
flash = mimxrt.Flash() view = memoryview(flash) magic = bytes(view[:4]) # read the first 4 bytes directly from XIP
The block size used by the underlying flash sectors can be queried at runtime with
ioctl(5, 0).- readblocks(block_num: int, buf: bytearray) None¶
- readblocks(block_num: int, buf: bytearray, offset: int) None
Read bytes from the flash into
buf. Two overloads expose the simple and extended interfaces:Simple form (
readblocks(block_num, buf)): reads whole blocks starting at block indexblock_num.len(buf)must be a multiple of the flash block size.Extended form (
readblocks(block_num, buf, offset)): readslen(buf)bytes – not necessarily a whole number of blocks – starting at byteoffsetwithin blockblock_num.len(buf)has no alignment constraint.
- writeblocks(block_num: int, buf: bytes) None¶
- writeblocks(block_num: int, buf: bytes, offset: int) None
Write bytes from
bufto the flash. Two overloads expose the simple and extended interfaces:Simple form (
writeblocks(block_num, buf)): writes whole blocks starting at block indexblock_num.len(buf)must be a multiple of the flash block size. Each affected block is erased automatically before being written.Extended form (
writeblocks(block_num, buf, offset)): writeslen(buf)bytes – not necessarily a whole number of blocks – starting at byteoffsetwithin blockblock_num.len(buf)has no alignment constraint, and no implicit erase is performed – the caller must ensure the affected blocks have been erased via a priorioctl(6, block_num)call.Raises
OSErrorif the underlying flash erase or write operation fails.
- ioctl(cmd: int, arg: int) int | None¶
Standard
vfs.AbstractBlockDevioctl entry point. Seevfs.AbstractBlockDev.ioctl()for the full list ofcmdvalues.cmd=5returns the flash block size in bytes;cmd=6erases the block with indexarg.