Last active
June 18, 2021 07:44
-
-
Save orklann/be0a9309a0a743ef08d8accfa8eb79ba to your computer and use it in GitHub Desktop.
Meowbit read and write Flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from meowbit import screen | |
from meowbit import pyb | |
fl = pyb.Flash() | |
# Doc: | |
# 1. https://docs.micropython.org/en/latest/library/pyb.Flash.html#pyb-flash | |
# 2. https://docs.micropython.org/en/latest/reference/filesystem.html#stm32-pyboard | |
# 4000th blocks to read and write, as Meowbit has 2MB flash size, | |
# it has 1024 * 1024 * 2 / 512 = 4096 blocks | |
start = 4000 | |
bufr = bytearray(512) # Every block size is 512 | |
fl.readblocks(start, bufr) | |
s = "" + str(bufr[0]) | |
screen.text(s) | |
buf = bytearray(512) | |
buf[0] = bufr[0] + 1 | |
if buf[0] > 255: | |
buf[0] = 255 | |
fl.writeblocks(start, buf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment