Simple MicroPython Winbond library
Project description
MicroPython Winbond Flash
MicroPython library to interact with Winbond W25Q Flash chips
upip stetup
Connect your MicroPython board to the web and install this library with the following command
import upip
upip.install('micropython-winbond')
Manual Setup
For interaction with the filesystem of the device the Remote MicroPython shell can be used.
Installation
Install the required python package with the following command in a virtual environment to avoid any conflicts with other packages installed on your local system.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Test the tool by showing its man/help info description.
rshell --help
Setup check
Open the remote shell with the following command. Additionally use -b 115200
in case no CP210x is used but a CH34x to limit the communication speed to
115200 baud.
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
Check the board config with this simple boards
call inside the rshell. The
result will look similar to this after the connection
Using buffer-size of 32
Connecting to /dev/tty.SLAB_USBtoUART (buffer-size 32)...
Trying to connect to REPL connected
Retrieving sysname ... esp32
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /boot.py/
Setting time ... Feb 17, 2022 08:56:14
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/Users/Jones/Downloads/MicroPython/micropython-winbond> boards
pyboard @ /dev/tty.SLAB_USBtoUART connected Epoch: 2000 Dirs: /pyboard/boot.py
Download files to board
Files can be copied to the device with the following command
cp SOURCE_FILE_NAME /pyboard
# optional copy it as another file name
cp SOURCE_FILE_NAME /pyboard/NEW_FILE_NAME
Use these commands to download the files of this repo to the board.
cp winbond.py /pyboard
cp main.py /pyboard
cp boot.py /pyboard
Open REPL (in rshell)
Call repl
in the rshell. Use CTRL+X to leave the repl or CTRL+D for a soft
reboot of the device.
The boot.py
code will perform the following steps:
- create a flash object on
SPI2
with a SPI speed of 2kHz, chip select on machinepin 5
and a software reset interface. Check the datasheet of your flash chip whether software reset is supported. - try to mount the external flash to
/external
- in case of
OSError 19
the filesystem will be created first - otherwise the complete flash will be erased and the filesystem created
- finally mount the external flash
- in case of
The initial steps of formatting the flash and creating the filesystem will take around 45 seconds on an ESP32 board like the BE32-01 equipped with a 128MBit (16MB) external Winbond flash.
The main.py
code will perform the following steps:
- list all files and folders on the boards root directory
- try to read a file named
some-file.txt
on the external flash- if the file does not exist, it will be created
- extend the content of
some-file.txt
on the external flash with new content - list all files and folders on the external flash directory
A successful output of a first run after a soft reboot should look similar to this
MPY: soft reboot
manufacturer: 0xef
mem_type: 64
device: 0x4018
capacity: 16777216 bytes
Mounting the external flash to "/external" ...
Failed to mount the external flash due to: [Errno 19] ENODEV
Creating filesystem for external flash ...
This might take up to 10 seconds
Filesystem for external flash created
External flash mounted to "/external"
boot.py steps completed
Entered main.py
Listing all files and folders on the boards root directory "/":
['external', 'boot.py', 'main.py', 'winbond.py']
No test file "some-file.txt" exists on external flash "/external", creating it now
Listing all files and folders on the external flash directory "/external":
['some-file.txt']
Finished main.py code. Returning to REPL now
MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
Type "help()" for more information.
>>>
MPY: soft reboot
manufacturer: 0xef
mem_type: 64
device: 0x4018
capacity: 16777216 bytes
Mounting the external flash to "/external" ...
External flash mounted to "/external"
boot.py steps completed
Entered main.py
Listing all files and folders on the boards root directory "/":
['external', 'boot.py', 'main.py', 'winbond.py']
Test file "some-file.txt" exists on external flash "/external"
This is its content:
Hello World at 698411330
Appending new content to "/external/some-file.txt"
Listing all files and folders on the external flash directory "/external":
['some-file.txt']
Finished main.py code. Returning to REPL now
MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
Type "help()" for more information.
Create a PyPi (micropython) package
Setup
Install the required python package with the following command in a virtual environment to avoid any conflicts with other packages installed on your local system.
python3 -m venv .venv
source .venv/bin/activate
pip install twine
Create a distribution
This module overrides distutils (also compatible with setuptools) sdist
command to perform pre- and post-processing as required for MicroPython's
upip package manager. This script is taken from
pfalcon's picoweb and updated to be PEP8
conform.
python setup.py sdist
A new folder dist
will be created. The sdist_upip
will be
used to create everything necessary.
Upload to PyPi
Be aware: pypi.org and test.pypi.org are different
You can NOT login to test.pypi.org with the pypi.org account unless you created the same on the other. See invalid auth help page of test pypi
For testing purposes add --repository testpypi
to
upload it to test.pypi.org
twine upload dist/micropython-winbond-*.tar.gz -u PYPI_USERNAME -p PYPI_PASSWORD
Credits
Kudos and big thank you to crizeo of the MicroPython Forum and his post to use Winbond flash chips
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for micropython-winbond-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98e7bb69fb37f5126be66fa0fe5e047094bd43fc27a7572e87081de676b6bbfb |
|
MD5 | e888542f8d215faef851d6385f0609eb |
|
BLAKE2b-256 | d1c07509bfb068055f853b81604e228a9147abbdd85be8e1ec1e9f767ab2b2a1 |