2019-12-04 02:50:51 +00:00
|
|
|
.. currentmodule:: pyb
|
|
|
|
.. _pyb.Flash:
|
|
|
|
|
|
|
|
class Flash -- access to built-in flash storage
|
|
|
|
===============================================
|
|
|
|
|
|
|
|
The Flash class allows direct access to the primary flash device on the pyboard.
|
|
|
|
|
|
|
|
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, but this interface is useful to :ref:`customise the filesystem
|
|
|
|
configuration <filesystem>` or implement a low-level storage system for your
|
|
|
|
application.
|
|
|
|
|
|
|
|
Constructors
|
|
|
|
------------
|
|
|
|
|
2022-06-21 05:33:23 +01:00
|
|
|
.. class:: Flash()
|
2019-12-04 02:50:51 +00:00
|
|
|
|
|
|
|
Create and return a block device that represents the flash device presented
|
|
|
|
to the USB mass storage interface.
|
|
|
|
|
|
|
|
It includes a virtual partition table at the start, and the actual flash
|
|
|
|
starts at block ``0x100``.
|
|
|
|
|
|
|
|
This constructor is deprecated and will be removed in a future version of MicroPython.
|
|
|
|
|
2022-06-21 05:33:23 +01:00
|
|
|
.. class:: Flash(*, start=-1, len=-1)
|
2020-06-04 02:38:45 +01:00
|
|
|
:noindex:
|
2019-12-04 02:50:51 +00:00
|
|
|
|
|
|
|
Create and return a block device that accesses the flash at the specified offset. The length defaults to the remaining size of the device.
|
|
|
|
|
|
|
|
The *start* and *len* offsets are in bytes, and must be a multiple of the block size (typically 512 for internal flash).
|
|
|
|
|
|
|
|
Methods
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. method:: Flash.readblocks(block_num, buf)
|
2020-06-04 02:38:45 +01:00
|
|
|
Flash.readblocks(block_num, buf, offset)
|
2019-12-04 02:50:51 +00:00
|
|
|
.. method:: Flash.writeblocks(block_num, buf)
|
2020-06-04 02:38:45 +01:00
|
|
|
Flash.writeblocks(block_num, buf, offset)
|
2019-12-04 02:50:51 +00:00
|
|
|
.. method:: Flash.ioctl(cmd, arg)
|
|
|
|
|
|
|
|
These methods implement the simple and :ref:`extended
|
|
|
|
<block-device-interface>` block protocol defined by
|
2021-08-12 04:59:29 +01:00
|
|
|
:class:`os.AbstractBlockDev`.
|
2019-12-04 02:50:51 +00:00
|
|
|
|
|
|
|
Hardware Note
|
|
|
|
-------------
|
|
|
|
|
|
|
|
On boards with external spiflash (e.g. Pyboard D), the MicroPython firmware will
|
|
|
|
be configured to use that as the primary flash storage. On all other boards, the
|
|
|
|
internal flash inside the :term:`MCU` will be used.
|