{"id":13802643,"url":"https://github.com/rolandvs/micropython-fram","last_synced_at":"2025-05-13T13:32:33.296Z","repository":{"id":191378068,"uuid":"114886857","full_name":"rolandvs/micropython-fram","owner":"rolandvs","description":"Pyboard driver for Ferroelectric RAM module","archived":false,"fork":false,"pushed_at":"2018-01-04T21:02:23.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T20:57:18.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rolandvs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-12-20T12:48:53.000Z","updated_at":"2023-07-31T00:40:12.000Z","dependencies_parsed_at":"2023-08-29T16:08:52.921Z","dependency_job_id":null,"html_url":"https://github.com/rolandvs/micropython-fram","commit_stats":null,"previous_names":["rolandvs/micropython-fram"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolandvs%2Fmicropython-fram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolandvs%2Fmicropython-fram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolandvs%2Fmicropython-fram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rolandvs%2Fmicropython-fram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rolandvs","download_url":"https://codeload.github.com/rolandvs/micropython-fram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253950273,"owners_count":21989333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:49.285Z","updated_at":"2025-05-13T13:32:33.018Z","avatar_url":"https://github.com/rolandvs.png","language":"Python","readme":"# micropython-fram\nA driver to enable the Pyboard to access the Ferroelectric RAM (FRAM) board from\n[Adafruit](http://www.adafruit.com/product/1895). FRAM is a technology offering\nnonvolatile memory with extremely long endurance and fast access, avoiding the\nlimitations of Flash memory. Its endurance is specified as 10^13 writes,\ncontrasted with 10,000 which is the quoted endurance of the Pyboard's onboard\nFlash memory. In data logging applications the latter can be exceeded relatively\nrapidly. Flash writes can be slow because of the need for a sector erase: this\nis not a fast process. FRAM is byte addressable and is not subject to this\nlimitation. The downside is limited capacity. Compared to a Micro SD card fitted\nto the Pyboard it offers lower power consumption and longer endurance.\n\nFrom one to eight boards may be used to construct a nonvolatile memory module\nwith size ranging from 32KB to 256KB. The driver allows the memory either to be\nmounted in the Pyboard filesystem as a disk device or to be addressed as an\narray of bytes.\n\nNow accepts an I2C bus as argument to facilitate the use of multiple devices on\nthe bus. Also adapted to work on the ESP8266.\n\n# Connections\n\nTo wire up a single FRAM module, connect to the Pyboard as below (nc indicates\nno connection).\n\n| FRAM    |  L  |  R  |\n|:-------:|:---:|:---:|\n| Vcc     | 3V3 | 3V3 |\n| Gnd     | GND | GND |\n| WP      | nc  | nc  |\n| SCL     | X9  | Y9  |\n| SDA     | X10 | Y10 |\n| A2      | nc  | nc  |\n| A1      | nc  | nc  |\n| A0      | nc  | nc  |\n\nFor multiple modules the address lines A0, A1 and A2 of each module need to be\nwired to 3V3 in such a way as to give each device a unique address. These must\nstart at zero and be contiguous. Thus with three modules, the first would have\naddress lines unconnected (address 0), the second would have A0 connected to 3V3\n(address 1) and the third would have A1 connected to 3V3 (address 2).\n\nMultiple modules should have 3V3, Gnd, SCL and SDA lines wired in parallel.\n\n# Driver\n\nThe driver supports mounting the FRAM modules as a filesystem. Initially the\ndevice will be unformatted so it is necessary to issue code along these lines to\nformat the device.\n\n```python\nimport pyb\nfrom fram import FRAM\ni2c = pyb.I2C(2, pyb.I2C.MASTER)\nf = FRAM(i2c)\npyb.mount(f, '/fram', mkfs = True)\npyb.mount(None, '/fram')\n```\n\nAt the time of writing the ``pyb`` module provides no way to reformat a drive\nwhich already has a filesystem. As a workround the following will perform this:\n\n```python\nimport pyb \nfrom fram import FRAM\ni2c = pyb.I2C(2, pyb.I2C.MASTER)\nf = FRAM(i2c)\nf.low_level_format()\npyb.mount(f, '/fram', mkfs = True)\npyb.mount(None, '/fram')\n```\n\nNote that, at the outset, you need to decide whether to use the array as a\nmounted filesystem or as a byte array. As a filesystem the limited size is an\nissue, but a potential use case is for pickling Python objects for example to\nachieve persistence when issuing ``pyb.standby()``. Also for holding a small\nfrequently updated persistent btree database.\n\n### Constructor\n\n``FRAM()`` Takes two arguments:  \n 1. ``i2c`` Mandatory. An initialised master mode I2C bus.  \n 2. ``verbose`` (default False). If True, the constructor issues information on\n the FRAM devices it has detected.\n\nA ``FRAMException`` will be raised if a device is not detected or if device\naddress lines are not wired as  described in Connections above.\n\n### Methods providing the block protocol\n\nFor the protocol definition see\n[the pyb documentation](http://docs.micropython.org/en/latest/library/pyb.html)\n\n``readblocks()``  \n``writeblocks()``  \n``count()``  \n``ioctl()``\n\n### Methods providing byte level access\n\nThe following methods are available for general use.\n\n``readwrite()`` Provides byte level access to the memory array. Arguments:  \n 1. ``addr`` Starting byte address  \n 2. ``buf`` A buffer containing the data to write or to hold read data  \n 3. ``read`` If True, perform a read otherwise write. The size of the buffer\n determines the quantity of data read or written. A ``FRAMException`` will be\n thrown if the read or write extends beyond the end of the array.\n\n``low_level_format()`` Erases the filesystem! Currently (this may change) the\npyb module doesn't provide a means of forcing a drive format. Issuing a\n``low_level_format()`` followed by ``pyb.mount()`` with ``mkfs-True`` will\nformat the drive deleting all files.\n\n``available()`` Returns True if the device is detected and is supported.\n\nOther than for debugging there is no need to call ``available()``: the\nconstructor will throw a ``FRAMException`` if it fails to communicate with and\ncorrectly identify the chip.\n\n## File copy\n\nThis is really a piece of history now superseded. upysh in\n[micropython-lib](https://github.com/micropython/micropython-lib.git) is a much\nmore capable solution.\n\nA rudimentary ``cp(source, dest)`` function is provided as a generic file copy\nroutine for setup and debugging purposes at the REPL. The first argument is the\nfull pathname to the source file. The second may be a full path to the\ndestination file or a directory specifier which must have a trailing '/'. If an\nOSError is thrown (e.g. by the source file not existing or the FRAM becoming\nfull) it is up to the caller to handle it. For example (assuming the FRAM is\nmounted on /fram):\n\n```python\ncp('/flash/main.py','/fram/')\n```\n\n# ESP8266\n\nThe driver now supports this module. The file ``framtest_esp8266.py`` demonstrates\nits use. Note that currently the ESP8266 does not support concurrent mounting\nof multiple filesystems. Consequently the onboard flash must be unmounted (with\n``uos.umount()``) before the FRAM can be mounted.\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Storage"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frolandvs%2Fmicropython-fram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frolandvs%2Fmicropython-fram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frolandvs%2Fmicropython-fram/lists"}