與Winbond W25Q Flash芯片互動的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 --help將Micropython設備連接到網絡(如果可能的話)
import network
station = network . WLAN ( network . STA_IF )
station . active ( True )
station . connect ( 'SSID' , 'PASSWORD' )
station . isconnected ()在Micropython設備上安裝此LIB的最新軟件包版本
import mip
mip . install ( "github:brainelectronics/micropython-winbond" )對於低於1.19.1的Micropython版本,請使用upip包而不是mip
import upip
upip . install ( 'micropython-winbond' )在Micropython設備上安裝此LIB的特定固定軟件包版本
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版本,請使用upip包而不是mip 。使用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版本,請使用upip包而不是mip 。使用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中的Braineleclectronics測試PYPI服務器,以獲取在Docker上運行的測試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 )榮譽和非常感謝Micropython論壇的Crizeo和他的帖子使用Winbond Flash芯片