Skip to main content

Simple MicroPython Winbond library

Project description

MicroPython Winbond Flash

Downloads Release MicroPython License: MIT CI

MicroPython library to interact with Winbond W25Q Flash chips


Installation

Install required tools

Python3 must be installed on your system. Check the current Python version with the following command

python --version
python3 --version

Depending on which command Python 3.x.y (with x.y as some numbers) is returned, use that command to proceed.

python3 -m venv .venv
source .venv/bin/activate

pip install -r requirements.txt

For interaction with the filesystem of the device the Remote MicroPython shell can be used.

Test the tool by showing its man/help info description.

rshell --help

Stetup

Install package with pip

Connect your MicroPython board to a network

import network
station = network.WLAN(network.STA_IF)
station.connect('SSID', 'PASSWORD')
station.isconnected()

and install this lib on the MicroPython device like this

import upip
upip.install('micropython-winbond')

Manually

Upload files to board

Copy the module to the MicroPython board and import them as shown below using Remote MicroPython shell

Open the remote shell with the following command. Additionally use -b 115200 in case no CP210x is used but a CH34x.

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

Perform the following command to copy all files and folders to the device

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 machine pin 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

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.

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

micropython-winbond-0.3.0.tar.gz (7.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page