Winbond W25Qフラッシュチップと対話するためのMicropythonライブラリ
最新のドキュメントは、Micropython Winbond Readthedocsで入手できます
Python3はシステムにインストールする必要があります。次のコマンドを使用して、現在のPythonバージョンを確認してください
python --version
python3 --versionどのコマンドPython 3.xy (xyをいくつかの数字として)が返されるかに応じて、そのコマンドを使用して続行します。
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtデバイスのファイルシステムとの相互作用には、リモートマイクロパイソンシェルを使用できます。
その人/ヘルプ情報の説明を表示してツールをテストします。
rshell --helpMicropythonデバイスをネットワークに接続します(可能であれば)
import network
station = network . WLAN ( network . STA_IF )
station . active ( True )
station . connect ( 'SSID' , 'PASSWORD' )
station . isconnected ()このLIBの最新のパッケージバージョンをMicropythonデバイスにインストールする
import mip
mip . install ( "github:brainelectronics/micropython-winbond" ) 1.19.1以下のMicropythonバージョンの場合、 mipの代わりにupipパッケージを使用します
import upip
upip . install ( 'micropython-winbond' )このLIBの特定の固定パッケージバージョンをMicropythonデバイスにインストールする
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" ) 1.19.1以下のMicropythonバージョンの場合、 mipの代わりにupipパッケージを使用します。 upipを使用すると、常に最新の利用可能なバージョンがインストールされます。
import upip
upip . install ( 'micropython-winbond' )Micropythonデバイス上のすべてのPRでPythonパッケージインデックスをテストするためにアップロードされた特定のリリース候補バージョンをインストールします。特定のバージョンが設定されていない場合、最新の安定したバージョンが使用されます。
import mip
mip . install ( "github:brainelectronics/micropython-winbond" , version = "0.4.0-rc2.dev4" ) 1.19.1以下のMicropythonバージョンの場合、 mipの代わりにupipパッケージを使用します。 upipを使用すると、常に最新の利用可能なバージョンがインストールされます。
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' )Dockerで実行されているテストPypiサーバーのBrainelectronicsテストPypiサーバーも参照してください。
モジュールをMicropythonボードにコピーし、以下に示すようにインポートするリモートマイクロパイソンシェル
次のコマンドでリモートシェルを開きます。さらに、CP210xが使用されない場合に-b 115200使用しますが、CH34Xです。
rshell -p /dev/tty.SLAB_USBtoUART --editor nano rshell内で次のコマンドを実行して、すべてのファイルとフォルダをデバイスにコピーする
mkdir /pyboard/lib
mkdir /pyboard/lib/winbond
cp winbond/ * /pyboard/lib/winbond
cp main.py /pyboard/lib/winbond
cp boot.py /pyboard/lib/winbond 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 )称賛と大規模なマイクロパイトンフォーラムのCrizeoとWinbond Flashチップを使用する彼の投稿に感謝します