Skip to main content

MicroPython Winbond Flash

Downloads Release MicroPython License: MIT CI

MicroPython library to interact with Winbond W25Q Flash chips

📚 The latest documentation is available at MicroPython Winbond ReadTheDocs 📚


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

Connect the MicroPython device to a network (if possible)

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

General

Install the latest package version of this lib on the MicroPython device

import mip
mip.install("github:brainelectronics/micropython-winbond")

For MicroPython versions below 1.19.1 use the upip package instead of mip

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

Specific version

Install a specific, fixed package version of this lib on the MicroPython device

import mip
# install a verions of a specific branch
mip.install("github:brainelectronics/micropython-winbond", version="feature/add-docs-and-detailed-examples")
# install a tag version
mip.install("github:brainelectronics/micropython-winbond", version="0.4.0")

For MicroPython versions below 1.19.1 use the upip package instead of mip. With upip always the latest available version will be installed.

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

Test version

Install a specific release candidate version uploaded to Test Python Package Index on every PR on the MicroPython device. If no specific version is set, the latest stable version will be used.

import mip
mip.install("github:brainelectronics/micropython-winbond", version="0.4.0-rc2.dev4")

For MicroPython versions below 1.19.1 use the upip package instead of mip. With upip always the latest available version will be installed.

import upip
# overwrite index_urls to only take artifacts from test.pypi.org
upip.index_urls = ['https://test.pypi.org/pypi']
upip.install('micropython-winbond')

See also brainelectronics Test PyPi Server in Docker for a test PyPi server running on Docker.

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

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

mkdir /pyboard/lib
mkdir /pyboard/lib/winbond

cp winbond/* /pyboard/lib/winbond
cp main.py /pyboard/lib/winbond
cp boot.py /pyboard/lib/winbond

Usage

from machine import SPI, Pin
import os
from winbond import W25QFlash

# the used SPI and CS pin is setup specific, change accordingly
# check the boot.py file of this repo for further boards
flash = W25QFlash(spi=SPI(2), cs=Pin(5), baud=2000000, software_reset=True)

flash_mount_point = '/external'

try:
    os.mount(flash, flash_mount_point)
except Exception as e:
    if e.errno == 19:
        # [Errno 19] ENODEV aka "No such device"
        # create the filesystem, this takes some seconds (approx. 10 sec)
        print('Creating filesystem for external flash ...')
        print('This might take up to 10 seconds')
        os.VfsFat.mkfs(flash)
    else:
        # takes some seconds/minutes (approx. 40 sec for 128MBit/16MB)
        print('Formatting external flash ...')
        print('This might take up to 60 seconds')
        # !!! only required on the very first start (will remove everything)
        flash.format()

        # create the filesystem, this takes some seconds (approx. 10 sec)
        print('Creating filesystem for external flash ...')
        print('This might take up to 10 seconds')
        # !!! only required on first setup and after formatting
        os.VfsFat.mkfs(flash)

    print('Filesystem for external flash created')

    # finally mount the external flash
    os.mount(flash, flash_mount_point)

Credits

Kudos and big thank you to crizeo of the MicroPython Forum and his post to use Winbond flash chips

Metadata

Release files for micropython-winbond 0.5.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micropython-winbond 0.5.4
File Size Uploaded
micropython-winbond-0.5.4.tar.gz 7.3 kB Details

Release files / micropython-winbond-0.5.4.tar.gz

Download URL micropython-winbond-0.5.4.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b3f568354d154c42df3d99de3cbc31d02dd203a93eea00c775d14b81e3f3925e
BLAKE2b-256 checksum
How to use checksums
d23140dd54a9409c1038deace2527704592446ac7f201db7c1713e44e98ee157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.5.4 This release

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page