与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芯片