I microcontrollori sono da tempo il cuore di numerosi sistemi embedded. Negli anni, la programmazione di questi dispositivi è passata da linguaggi a basso livello come l’Assembly o il C a linguaggi ad alto livello più accessibili come Python. Un esempio eccellente è MicroPython, un’implementazione snella ed efficiente di Python 3. Questo articolo approfondisce i dettagli dell’integrazione di MicroPython con l’STM32F4 (con un piccolo focus sulle schede WeAct STM32F411CE, STM32F401CC, e Nucleo), un microcontroller a basso costo e ad alto potenziale prodotto da STMicroelectronics.
Le schede WeAct STM32F411CE e STM32F401CC presentano una serie di funzionalità attraenti adatte per molte applicazioni IoT e di sistemi embedded. Tuttavia, per sfruttare questo potenziale, è necessario comprendere i pro e i contro dell’installazione del firmware, dell’ambiente di programmazione, e dell’uso degli strumenti standard.
Questa guida completa è pensata per guidarvi attraverso il processo passo-passo di configurazione di MicroPython sulle schede STM32F411CE e STM32F401CC. Faremo riferimento a risorse affidabili, inclusa una procedura di costruzione del firmware disponibile sul repository GitHub di WeAct Studio e ulteriori specifiche del dispositivo dal repository MiniSTM32F4x1 di WeAct Studio.
Che siate un hobbista, un accademico, o uno sviluppatore professionista, l’esplorazione che segue promette una comprensione più chiara di questa combinazione di risorse – STM32F4 e MicroPython. Preparatevi a scoprire un mondo di opportunità e a dare vita ai vostri progetti creativi con questo duo potente ma economico.
Specifiche del dispositivo
STM32F411
Link all’immagine ad alta risoluzione dello schema dei pin
Ecco le schede STM32 più usate STM32F103C8T6 STM32F401 STM32F411 ST-Link v2 ST-Link v2 official
Descrizione
I dispositivi STM32F411xC/xE si basano sul core RISC Arm® Cortex® -M4 a 32 bit ad alte prestazioni, operante ad una frequenza fino a 100 MHz. Il core Cortex®-M4 presenta una unità di calcolo in virgola mobile (FPU) a precisione singola che supporta tutte le istruzioni e i tipi di dati di elaborazione dei dati a precisione singola di Arm. Implementa inoltre un set completo di istruzioni DSP e una unità di protezione della memoria (MPU) che aumenta la sicurezza dell’applicazione. Gli STM32F411xC/xE appartengono alla linea di prodotti STM32 Dynamic Efficiency™ (con prodotti che combinano efficienza energetica, prestazioni e integrazione) aggiungendo una nuova caratteristica innovativa chiamata Batch Acquisition Mode (BAM) che consente di risparmiare ancora più energia durante il batching dei dati.
Gli STM32F411xC/xE incorporano memorie ad alta velocità incorporate (fino a 512 Kbytes di memoria Flash, 128 Kbytes di SRAM) e una vasta gamma di I/O potenziati e periferiche collegate a due bus APB, due bus AHB e una matrice di bus multi-AHB a 32 bit.
Tutti i dispositivi offrono un ADC a 12 bit, un RTC a basso consumo, sei timer general purpose a 16 bit incluso un timer PWM per il controllo dei motori, due timer general purpose a 32 bit. Dispongono inoltre di interfacce di comunicazione standard e avanzate.
Gli STM32F411xC/xE operano nell’intervallo di temperatura da – 40 a + 125 °C con un alimentazione da 1,7 (PDR OFF) a 3,6 V. Un set completo di modalità di risparmio energetico permette la progettazione di applicazioni a basso consumo.
Queste caratteristiche rendono i microcontrollori STM32F411xC/xE adatti a un’ampia gamma di applicazioni. (da ST)
Presta attenzione nella serie STM32411 i pin 10 e 41 non sono tolleranti a 5v (quadrato rosso nel diagramma dei pin)
Questo tipo di scheda offre un socket sul fondo per aggiungere una Flash SPI esterna, e SPI1 CS/SCK/MISO/MOSI (PA4/PA5/PA6/PA7) sono collegati al footprint per la flash esterna.
STM32F401
Link all’immagine della disposizione dei pin ad alta risoluzione
Ecco le schede STM32 più utilizzate STM32F103C8T6 STM32F401 STM32F411 ST-Link v2 ST-Link v2 official
Descrizione
I dispositivi STM32F401xB/STM32F401xC si basano sul core RISC Arm® Cortex® -M4 a 32 bit ad alte prestazioni, operante ad una frequenza fino a 84 MHz. Il core Cortex®-M4 presenta una unità di calcolo in virgola mobile (FPU) a precisione singola che supporta tutte le istruzioni e i tipi di dati di elaborazione dei dati a precisione singola di Arm. Implementa inoltre un set completo di istruzioni DSP e una unità di protezione della memoria (MPU) che aumenta la sicurezza dell’applicazione. Gli STM32F401xB/STM32F401xC incorporano memorie ad alta velocità incorporate, e una vasta gamma di I/O potenziati e periferiche collegate a due bus APB, due bus AHB e una matrice di bus multi-AHB a 32 bit.
Tutti i dispositivi offrono un ADC a 12 bit, un RTC a basso consumo, sei timer general purpose a 16 bit incluso un timer PWM per il controllo dei motori, due timer general purpose a 32 bit. Dispongono inoltre di interfacce di comunicazione standard e avanzate.
Gli STM32F401xB/STM32F401xC operano nell’intervallo di temperatura da – 40 a + 125 °C con un alimentazione da 1,7 (PDR OFF) a 3,6 V. Un set completo di modalità di risparmio energetico permette la progettazione di applicazioni a basso consumo.
Queste caratteristiche rendono i microcontrollori STM32F401xB/STM32F401xC adatti a un’ampia gamma di applicazioni. (da ST)
Tutti i STM32401 hanno pin tolleranti ai 5v (quadrato verde nel diagramma dei pin)
Questo tipo di scheda offre un socket sul fondo per aggiungere una Flash SPI esterna, e SPI1 CS/SCK/MISO/MOSI (PA4/PA5/PA6/PA7) sono collegati al footprint per la flash esterna.
Firmware MicroPython
Alcune schede sono supportate ufficialmente, e il firmware viene distribuito direttamente da MicroPython. Per la scheda che utilizzo solitamente, stiamo per costruire il firmware.
Scheda NUCLEO standard e supportata
Per la scheda supportata standard, puoi scaricare il firmware da qui stm32f0, stm32f4, stm32f7, stm32g0, stm32g4, stm32h7, stm32l0, stm32l1, stm32l4, stm32wb, stm32wl.
Firmware MicroPython per STM32F411CE e STM32F401CCU6
Creazione del firmware
È necessario Ubuntu o il sottosistema Linux di Win10
Prima di tutto, hai bisogno di git sulla tua distribuzione Linux, e quando hai risolto questo prerequisito, puoi scaricare l’implementazione di MicroPython.
git clone https://github.com/micropython/micropython.git
Ecco il processo
reef@PORTATIREEF:/mnt/c/Users/renzo$ git clone https://github.com/micropython/micropython.git
Cloning into 'micropython'...
remote: Enumerating objects: 108701, done.
remote: Counting objects: 100% (35946/35946), done.
remote: Compressing objects: 100% (3332/3332), done.
remote: Total 108701 (delta 34271), reused 32639 (delta 32614), pack-reused 72755
Receiving objects: 100% (108701/108701), 55.52 MiB | 2.20 MiB/s, done.
Resolving deltas: 100% (81403/81403), done.
Checking out files: 100% (5153/5153), done.
Ora hai bisogno del sottomodulo.
cd micropython
git submodule
update --init
Attendi un po’.
reef@PORTATIREEF:/mnt/c/Users/renzo$ cd micropython
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython$ git submodule update --init
Submodule 'lib/asf4' (https://github.com/adafruit/asf4) registered for path 'lib/asf4'
Submodule 'lib/axtls' (https://github.com/micropython/axtls.git) registered for path 'lib/axtls'
Submodule 'lib/berkeley-db-1.xx' (https://github.com/pfalcon/berkeley-db-1.xx) registered for path 'lib/berkeley-db-1.xx'
Submodule 'lib/btstack' (https://github.com/bluekitchen/btstack.git) registered for path 'lib/btstack'
Submodule 'lib/cyw43-driver' (https://github.com/georgerobotics/cyw43-driver.git) registered for path 'lib/cyw43-driver'
Submodule 'lib/fsp' (https://github.com/renesas/fsp.git) registered for path 'lib/fsp'
Submodule 'lib/libffi' (https://github.com/atgreen/libffi) registered for path 'lib/libffi'
Submodule 'lib/libhydrogen' (https://github.com/jedisct1/libhydrogen.git) registered for path 'lib/libhydrogen'
Submodule 'lib/lwip' (https://github.com/lwip-tcpip/lwip.git) registered for path 'lib/lwip'
Submodule 'lib/mbedtls' (https://github.com/ARMmbed/mbedtls.git) registered for path 'lib/mbedtls'
Submodule 'lib/micropython-lib' (https://github.com/micropython/micropython-lib.git) registered for path 'lib/micropython-lib'
Submodule 'lib/mynewt-nimble' (https://github.com/micropython/mynewt-nimble.git) registered for path 'lib/mynewt-nimble'
Submodule 'lib/nrfx' (https://github.com/NordicSemiconductor/nrfx.git) registered for path 'lib/nrfx'
Submodule 'lib/nxp_driver' (https://github.com/hathach/nxp_driver.git) registered for path 'lib/nxp_driver'
Submodule 'lib/pico-sdk' (https://github.com/raspberrypi/pico-sdk.git) registered for path 'lib/pico-sdk'
Submodule 'lib/stm32lib' (https://github.com/micropython/stm32lib) registered for path 'lib/stm32lib'
Submodule 'lib/tinyusb' (https://github.com/hathach/tinyusb) registered for path 'lib/tinyusb'
Submodule 'lib/wiznet' (https://github.com/andrewleech/wiznet_ioLibrary_Driver.git) registered for path 'lib/wiznet5k'
Cloning into '/mnt/c/Users/renzo/micropython/lib/asf4'...
fatal: unable to access 'https://github.com/adafruit/asf4/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/adafruit/asf4' into submodule path '/mnt/c/Users/renzo/micropython/lib/asf4' failed
Failed to clone 'lib/asf4'. Retry scheduled
Cloning into '/mnt/c/Users/renzo/micropython/lib/axtls'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/berkeley-db-1.xx'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/btstack'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/cyw43-driver'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/fsp'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/libffi'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/libhydrogen'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/lwip'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/mbedtls'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/micropython-lib'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/mynewt-nimble'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/nrfx'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/nxp_driver'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/pico-sdk'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/stm32lib'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/tinyusb'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/wiznet5k'...
Cloning into '/mnt/c/Users/renzo/micropython/lib/asf4'...
Submodule path 'lib/asf4': checked out '84f56af13292d8f32c40acbd949bde698ddd4507'
Submodule path 'lib/axtls': checked out '531cab9c278c947d268bd4c94ecab9153a961b43'
Submodule path 'lib/berkeley-db-1.xx': checked out '35aaec4418ad78628a3b935885dd189d41ce779b'
Submodule path 'lib/btstack': checked out '1635e36d06821af8b61302509e91bfcc1ade84c4'
Submodule path 'lib/cyw43-driver': checked out '36144f94bee69ad5e7b46fef06ce0c2405bafee5'
Submodule path 'lib/fsp': checked out 'e78939d32d1ccea9f0ba8bb42c51aceffd386b9b'
Submodule path 'lib/libffi': checked out 'e9de7e35f2339598b16cbb375f9992643ed81209'
Submodule path 'lib/libhydrogen': checked out '5c5d513093075f7245ea522101b17c50aa579af2'
Submodule path 'lib/lwip': checked out '6ca936f6b588cee702c638eee75c2436e6cf75de'
Submodule path 'lib/mbedtls': checked out '981743de6fcdbe672e482b6fd724d31d0a0d2476'
Submodule path 'lib/micropython-lib': checked out 'c113611765278b2fc8dcf8b2f2c3513b35a69b39'
Submodule path 'lib/mynewt-nimble': checked out '42849560ba7906f023f61e5f7ff3709ba2c1dfca'
Submodule path 'lib/nrfx': checked out '7a4c9d946cf1801771fc180acdbf7b878f270093'
Submodule path 'lib/nxp_driver': checked out 'fa5a554c7944d2a196626f8d3631e44943f9abcc'
Submodule path 'lib/pico-sdk': checked out 'f396d05f8252d4670d4ea05c8b7ac938ef0cd381'
Submodule path 'lib/stm32lib': checked out 'fdb1ec6879bc8b7bb54ded73bac04839003c5a07'
Submodule path 'lib/tinyusb': checked out '868f2bcda092b0b8d5f7ac55ffaef2c81316d35e'
Submodule path 'lib/wiznet5k': checked out '0803fc519ad7227e841287fb3638d6c8b2f111a1'
Submodule path 'lib/asf4': checked out '84f56af13292d8f32c40acbd949bde698ddd4507'
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython$
Ora compila mpy-cross
cd mpy-cross
make -j4
Ed ecco il risultato
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython/mpy-cross$ make -j4
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build/genhdr
mkdir -p build/
mkdir -p build/py/
mkdir -p build/shared/runtime/
GEN build/genhdr/mpversion.h
GEN build/genhdr/qstr.i.last
GEN build/genhdr/qstr.split
GEN build/genhdr/moduledefs.split
GEN build/genhdr/root_pointers.split
GEN build/genhdr/moduledefs.collected
GEN build/genhdr/root_pointers.collected
Root pointer registrations updated
Module registrations updated
GEN build/genhdr/root_pointers.h
GEN build/genhdr/moduledefs.h
GEN build/genhdr/qstrdefs.collected.h
QSTR updated
GEN build/genhdr/qstrdefs.generated.h
CC ../py/mpstate.c
CC ../py/nlr.c
CC ../py/nlrx86.c
CC ../py/nlrx64.c
CC ../py/nlrthumb.c
CC ../py/nlraarch64.c
CC ../py/nlrmips.c
CC ../py/nlrpowerpc.c
CC ../py/nlrxtensa.c
CC ../py/nlrsetjmp.c
CC ../py/malloc.c
CC ../py/gc.c
CC ../py/pystack.c
CC ../py/qstr.c
CC ../py/vstr.c
CC ../py/mpprint.c
CC ../py/unicode.c
CC ../py/mpz.c
CC ../py/reader.c
CC ../py/lexer.c
CC ../py/parse.c
CC ../py/scope.c
CC ../py/compile.c
CC ../py/emitcommon.c
CC ../py/emitbc.c
CC ../py/asmbase.c
CC ../py/asmx64.c
CC ../py/emitnx64.c
CC ../py/asmx86.c
CC ../py/emitnx86.c
CC ../py/asmthumb.c
CC ../py/emitnthumb.c
CC ../py/emitinlinethumb.c
CC ../py/asmarm.c
CC ../py/emitnarm.c
CC ../py/asmxtensa.c
CC ../py/emitnxtensa.c
CC ../py/emitinlinextensa.c
CC ../py/emitnxtensawin.c
CC ../py/formatfloat.c
CC ../py/parsenumbase.c
CC ../py/parsenum.c
CC ../py/emitglue.c
CC ../py/persistentcode.c
CC ../py/runtime.c
CC ../py/runtime_utils.c
CC ../py/scheduler.c
CC ../py/nativeglue.c
CC ../py/pairheap.c
CC ../py/ringbuf.c
CC ../py/stackctrl.c
CC ../py/argcheck.c
CC ../py/warning.c
CC ../py/profile.c
CC ../py/map.c
CC ../py/obj.c
CC ../py/objarray.c
CC ../py/objattrtuple.c
CC ../py/objbool.c
CC ../py/objboundmeth.c
CC ../py/objcell.c
CC ../py/objclosure.c
CC ../py/objcomplex.c
CC ../py/objdeque.c
CC ../py/objdict.c
CC ../py/objenumerate.c
CC ../py/objexcept.c
CC ../py/objfilter.c
CC ../py/objfloat.c
CC ../py/objfun.c
CC ../py/objgenerator.c
CC ../py/objgetitemiter.c
CC ../py/objint.c
CC ../py/objint_longlong.c
CC ../py/objint_mpz.c
CC ../py/objlist.c
CC ../py/objmap.c
CC ../py/objmodule.c
CC ../py/objobject.c
CC ../py/objpolyiter.c
CC ../py/objproperty.c
CC ../py/objnone.c
CC ../py/objnamedtuple.c
CC ../py/objrange.c
CC ../py/objreversed.c
CC ../py/objset.c
CC ../py/objsingleton.c
CC ../py/objslice.c
CC ../py/objstr.c
CC ../py/objstrunicode.c
CC ../py/objstringio.c
CC ../py/objtuple.c
CC ../py/objtype.c
CC ../py/objzip.c
CC ../py/opmethods.c
CC ../py/sequence.c
CC ../py/stream.c
CC ../py/binary.c
CC ../py/builtinimport.c
CC ../py/builtinevex.c
CC ../py/builtinhelp.c
CC ../py/modarray.c
CC ../py/modbuiltins.c
CC ../py/modcollections.c
CC ../py/modgc.c
CC ../py/modio.c
CC ../py/modmath.c
CC ../py/modcmath.c
CC ../py/modmicropython.c
CC ../py/modstruct.c
CC ../py/modsys.c
CC ../py/moduerrno.c
CC ../py/modthread.c
CC ../py/vm.c
CC ../py/bc.c
CC ../py/showbc.c
CC ../py/repl.c
CC ../py/smallint.c
CC ../py/frozenmod.c
CC main.c
CC gccollect.c
CC ../shared/runtime/gchelper_generic.c
LINK build/mpy-cross
text data bss dec hex filename
316431 13712 840 330983 50ce7 build/mpy-cross
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython/mpy-cross$
Definizione di STM32F411CE
Ora possiamo scaricare la definizione della scheda dal repository di WeActStudio per F411CE.
cd ../ports/stm32/boards
git clone https://github.com/WeActTC/WeAct_F411CE-MicroPython.git WeAct_F411CE
cd ..
Ecco il risultato.
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython/ports/stm32/boards$ git clone https://github.com/WeActTC/WeAct_F411CE-MicroPython.git WeAct_F411CE
Cloning into 'WeAct_F411CE'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 64 (delta 34), reused 50 (delta 21), pack-reused 0
Unpacking objects: 100% (64/64), done.
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython/ports/stm32/boards$ cd ..
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython/ports/stm32$
O scarica il mio repository per F411CE e copia la cartella WeAct_F411CE all’interno della definizione delle schede di MicroPython.
\micropython\ports\stm32\boards
Definizione di STM32F401CCU6
O scarica il mio repository per F401CC e copia la cartella WeAct_F411CE all’interno della definizione delle schede di MicroPython.
\micropython\ports\stm32\boards
Personalizza la configurazione
mpconfigboard.h
/* BOARD Ver 2.0 set 1 ,other set 0 ex.V1.3,V2.1 V3.0 */
#define VERSION_V20 (1)
/* Use the built-in flash to change to 1 , use the external flash to change to 0 */
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
// Flash Size:
// 4MB Flash 32Mbit
// 8MB Flash 64Mbit
// 16MB Flash 128Mbit
#define MICROPY_HW_SPIFLASH_SIZE_BITS (32 * 1024 * 1024)
FLASH SPI:
#define MICROPY_HW_SPIFLASH_CS (pin_A4)
#define MICROPY_HW_SPIFLASH_SCK (pin_A5)
#if VERSION_V20
#define MICROPY_HW_SPIFLASH_MISO (pin_B4)
#else
#define MICROPY_HW_SPIFLASH_MISO (pin_A6)
#endif
#define MICROPY_HW_SPIFLASH_MOSI (pin_A7)
Compilare il firmware
Ora puoi provare a creare il firmware con questo comando per F411CE
make BOARD=WeAct_F411CE -j
o questo per F401CC
make BOARD=WeAct_F401CC -j
Ma se provi a compilare senza gcc-arm-none-eabi
otterrai questo errore
reef@PORTATIREEF:/mnt/c/Users/renzo/micropython/ports/stm32$ make BOARD=WeAct_F411CE -j
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build-WeAct_F411CE/genhdr
mkdir -p build-WeAct_F411CE/boards/WeAct_F411CE/
mkdir -p build-WeAct_F411CE/build-WeAct_F411CE/
mkdir -p build-WeAct_F411CE/drivers/bus/
mkdir -p build-WeAct_F411CE/drivers/dht/
mkdir -p build-WeAct_F411CE/drivers/memory/
mkdir -p build-WeAct_F411CE/extmod/
mkdir -p build-WeAct_F411CE/lib/libm/
mkdir -p build-WeAct_F411CE/lib/littlefs/
mkdir -p build-WeAct_F411CE/lib/oofatfs/
mkdir -p build-WeAct_F411CE/lib/stm32lib/CMSIS/STM32F4xx/Source/Templates/
mkdir -p build-WeAct_F411CE/lib/stm32lib/CMSIS/STM32F4xx/Source/Templates/gcc/
mkdir -p build-WeAct_F411CE/lib/stm32lib/STM32F4xx_HAL_Driver/Src/
mkdir -p build-WeAct_F411CE/py/
mkdir -p build-WeAct_F411CE/shared/libc/
mkdir -p build-WeAct_F411CE/shared/netutils/
mkdir -p build-WeAct_F411CE/shared/readline/
mkdir -p build-WeAct_F411CE/shared/runtime/
mkdir -p build-WeAct_F411CE/shared/timeutils/
mkdir -p build-WeAct_F411CE/usbdev/class/src/
mkdir -p build-WeAct_F411CE/usbdev/core/src/
GEN stmconst build-WeAct_F411CE/genhdr/modstm_const.h
GEN build-WeAct_F411CE/pins_WeAct_F411CE.c
GEN build-WeAct_F411CE/genhdr/pybcdc.inf
GEN build-WeAct_F411CE/genhdr/pllfreqtable.h
GEN build-WeAct_F411CE/genhdr/pybcdc_inf.h
GEN build-WeAct_F411CE/genhdr/mpversion.h
GEN build-WeAct_F411CE/genhdr/qstr.i.last
Traceback (most recent call last):
File "../../py/makeqstrdefs.py", line 209, in <module>
preprocess()
File "../../py/makeqstrdefs.py", line 76, in preprocess
for output in p.imap(pp(flags), chunks):
File "/usr/lib/python3.6/multiprocessing/pool.py", line 735, in next
raise value
File "/usr/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "../../py/makeqstrdefs.py", line 60, in run
return subprocess.check_output(args.pp + flags + files)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'arm-none-eabi-gcc': 'arm-none-eabi-gcc'
../../py/mkrules.mk:110: recipe for target 'build-WeAct_F411CE/genhdr/qstr.i.last' failed
make: *** [build-WeAct_F411CE/genhdr/qstr.i.last] Error 1
make: *** Deleting file 'build-WeAct_F411CE/genhdr/qstr.i.last'
Ora scaricalo con il gestore di pacchetti predefinito, oppure scarica e poi dai la pacca al compilatore con questo comando.
make BOARD=WeAct_F411CE CROSS_COMPILE=/mnt/e/MCU/tools/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi- -j
Dopo la compilazione, puoi trovare il firmware in questa cartella.
PERCORSO micropython\ports\stm32\build-WeAct_F411CE\firmware.hex
Scarica il firmware precompilato
Compilo il firmware e lo carico in questi repository.
Carica il firmware
Per l’originale STM32, non hai bisogno di più del cavo USB. Integra già l’ST-Link.
Driver ST-Link
Scarica e installa i driver st-link da qui.
Una volta installato, puoi collegare la scheda di valutazione ST al tuo computer con un cavo mini-USB.
Programma l’STM32 con gli strumenti ST-LINK
Scarica e scompatta la release binaria degli strumenti st-link da GitHub
Salva il file hex nella stessa directory in cui hai decompresso i binari st-link.
Apri un prompt dei comandi e naviga fino alla cartella st-link ed esegui i seguenti comandi:
st-flash.exe erase
Ecco l’output
D:\program\st-link\stlink-1.7.0-x86_64-w64-mingw32\bin>st-flash.exe erase
st-flash 1.7.0
2023-05-21T09:14:08 INFO common.c: stm32f411re: 128 KiB SRAM, 512 KiB flash in almeno 16 KiB pagine.
Cancellazione di massa.....
D:\program\st-link\stlink-1.7.0-x86_64-w64-mingw32\bin>
Ora iniziamo a caricare il firmware MicroPython.
st-flash.exe --format ihex write firmware.hex
Ecco il risultato.
D:\program\st-link\stlink-1.7.0-x86_64-w64-mingw32\bin>st-flash.exe --format ihex write firmware.hex
st-flash 1.7.0
2023-05-21T09:16:52 INFO common.c: stm32f411re: 128 KiB SRAM, 512 KiB flash in at least 16 KiB pages.
2023-05-21T09:16:52 INFO common.c: Attempting to write 449524 (0x6dbf4) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x4000 2023-05-21T09:16:52 INFO common.c: Flash page at addr: 0x08000000 erased
EraseFlash - Sector:0x1 Size:0x4000 2023-05-21T09:16:52 INFO common.c: Flash page at addr: 0x08004000 erased
EraseFlash - Sector:0x2 Size:0x4000 2023-05-21T09:16:53 INFO common.c: Flash page at addr: 0x08008000 erased
EraseFlash - Sector:0x3 Size:0x4000 2023-05-21T09:16:53 INFO common.c: Flash page at addr: 0x0800c000 erased
EraseFlash - Sector:0x4 Size:0x10000 2023-05-21T09:16:54 INFO common.c: Flash page at addr: 0x08010000 erased
EraseFlash - Sector:0x5 Size:0x20000 2023-05-21T09:16:56 INFO common.c: Flash page at addr: 0x08020000 erased
EraseFlash - Sector:0x6 Size:0x20000 2023-05-21T09:16:58 INFO common.c: Flash page at addr: 0x08040000 erased
EraseFlash - Sector:0x7 Size:0x20000 2023-05-21T09:17:00 INFO common.c: Flash page at addr: 0x08060000 erased
2023-05-21T09:17:00 INFO common.c: Finished erasing 8 pages of 131072 (0x20000) bytes
2023-05-21T09:17:00 INFO common.c: Starting Flash write for F2/F4/F7/L4
2023-05-21T09:17:00 INFO flash_loader.c: Successfully loaded flash loader in sram
2023-05-21T09:17:00 INFO flash_loader.c: Clear DFSR
2023-05-21T09:17:00 INFO flash_loader.c: Clear CFSR
2023-05-21T09:17:00 INFO flash_loader.c: Clear HFSR
2023-05-21T09:17:00 INFO common.c: enabling 32-bit flash writes
2023-05-21T09:17:07 INFO common.c: Starting verification of write complete
2023-05-21T09:17:11 INFO common.c: Flash written and verified! jolly good!
D:\program\st-link\stlink-1.7.0-x86_64-w64-mingw32\bin>
Programma lo STM32 con STM32CubeProgrammer
Ora, per caricare il firmware, puoi utilizzare STM32CubeProgrammer rilasciato da STMicroelectronics. Puoi scaricarlo da qui.
Dopo, avvialo e seleziona la tua connessione preferita.
Nel mio caso,
- Ho messo il dispositivo in modalità di programmazione con:
- Mantenere premuto il pulsante BOOTD
- Premere il pulsante NRST
- Rilasciare BOOTD
- Ho selezionato USB
- Poi il pulsante di aggiornamento
- E infine, la connessione.
Ora puoi cliccare su Avvia Programma..
Ora il firmware è attivo sul dispositivo.
Inizia a programmare in una console interattiva (REPL)
Ora inizieremo a programmare in Python immediatamente. Per farlo, possiamo utilizzare un monitor seriale per connetterci alla console interattiva del dispositivo.
Usa un monitor seriale per visualizzare l’output del tuo codice MicroPython. Ci sono diverse opzioni per i monitor seriali, tra cui:
screen
(macOS/Linux): Apri un terminale e esegui il seguente comando, sostituendo/dev/ttyUSB0
con la corretta porta seriale della tua scheda:
screen COM5 115200
- PuTTY (Windows): Scarica e installa PuTTY dal sito ufficiale (https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html), poi apri PuTTY e configuralo per usare la corretta porta seriale e baud rate (di solito 115200).
- CoolTerm (macOS/Windows): Scarica e install a CoolTerm dal sito ufficiale, poi apri CoolTerm e configuralo per usare la corretta porta seriale e baud rate (di solito 115200).
Scrivere ed eseguire codice Python con una sessione interattiva
Una volta che hai installato MicroPython sulla tua scheda, puoi utilizzare il REPL (Read-Eval-Print Loop) per interagire con la scheda ed eseguire il codice Python. Il REPL è un modo semplice per inserire comandi Python e vedere il loro output in tempo reale. Puoi connetterti al REPL della scheda utilizzando un programma di terminale seriale, come PuTTY o screen, tramite una connessione USB.
Per accedere al REPL su una scheda STM32, apri un programma di terminale seriale e connetti alla porta seriale della scheda con un baud rate di 115200. Dovresti vedere un prompt come questo:
MicroPython v1.20.0-93-g05e143dbd on 2023-05-20; WeAct Studio Core with STM32F411CE
Scrivi "help()" per maggiori informazioni.
>>>
Questo è il prompt di Python, dove puoi inserire comandi Python. Ad esempio, puoi inserire il seguente comando per stampare “Ciao, mondo!” nella console:
>>> print("Ciao da www.mischianti.org")
Dovresti vedere il seguente output:
Ciao da www.mischianti.org
Puoi anche scrivere codice Python sul tuo computer e caricarlo sulla scheda utilizzando un tool come ampy o rshell. Questi strumenti ti permettono di trasferire i file Python sulla scheda e di eseguirli dal file system della scheda.
Interazione con le periferiche hardware della scheda:
MicroPython sullo STM32 permette di accedere alle periferiche hardware della scheda, come i pin GPIO, i bus SPI e I2C e gli ingressi analogici. Puoi utilizzare il codice Python per interagire con queste periferiche e costruire progetti che interagiscono con il mondo fisico.
Devi installare il pacchetto “machine
” con pip.
Probabilmente otterrai questo errore.
D:\projects\micropython\testesp>pip install machine
Defaulting to user installation because normal site-packages is not writeable
Collecting machine
Downloading machine-0.0.1-py2.py3-none-any.whl (4.2 kB)
Collecting pycrypto
Downloading pycrypto-2.6.1.tar.gz (446 kB)
|████████████████████████████████| 446 kB 2.2 MB/s
Using legacy 'setup.py install' for pycrypto, since package 'wheel' is not installed.
Installing collected packages: pycrypto, machine
Running setup.py install for pycrypto ... error
ERROR: Command errored out with exit status 1:
command: 'c:\program files\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\renzo\\AppData\\Local\\Temp\\pip-install-svmkdo9_\\pycrypto_ee48e2c475ff47aaa23d619983f3b5e3\\setup.py'"'"'; __file__='"'"'C:\\Users\\renzo\\AppData\\Local\\Temp\\pip-install-svmkdo9_\\pycrypto_ee48e2c475ff47aaa23d619983f3b5e3\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\renzo\AppData\Local\Temp\pip-record-qctz6vm0\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\renzo\AppData\Roaming\Python\Python39\Include\pycrypto'
cwd: C:\Users\renzo\AppData\Local\Temp\pip-install-svmkdo9_\pycrypto_ee48e2c475ff47aaa23d619983f3b5e3\
Complete output (183 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.9
creating build\lib.win-amd64-3.9\Crypto
copying lib\Crypto\pct_warnings.py -> build\lib.win-amd64-3.9\Crypto
copying lib\Crypto\__init__.py -> build\lib.win-amd64-3.9\Crypto
creating build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\hashalgo.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\HMAC.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\MD2.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\MD4.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\MD5.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\RIPEMD.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\SHA.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\SHA224.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\SHA256.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\SHA384.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\SHA512.py -> build\lib.win-amd64-3.9\Crypto\Hash
copying lib\Crypto\Hash\__init__.py -> build\lib.win-amd64-3.9\Crypto\Hash
creating build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\AES.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\ARC2.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\ARC4.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\blockalgo.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\Blowfish.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\CAST.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\DES.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\DES3.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\PKCS1_OAEP.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\PKCS1_v1_5.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\XOR.py -> build\lib.win-amd64-3.9\Crypto\Cipher
copying lib\Crypto\Cipher\__init__.py -> build\lib.win-amd64-3.9\Crypto\Cipher
creating build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\asn1.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\Counter.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\number.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\py3compat.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\randpool.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\RFC1751.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\winrandom.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\_number_new.py -> build\lib.win-amd64-3.9\Crypto\Util
copying lib\Crypto\Util\__init__.py -> build\lib.win-amd64-3.9\Crypto\Util
creating build\lib.win-amd64-3.9\Crypto\Random
copying lib\Crypto\Random\random.py -> build\lib.win-amd64-3.9\Crypto\Random
copying lib\Crypto\Random\_UserFriendlyRNG.py -> build\lib.win-amd64-3.9\Crypto\Random
copying lib\Crypto\Random\__init__.py -> build\lib.win-amd64-3.9\Crypto\Random
creating build\lib.win-amd64-3.9\Crypto\Random\Fortuna
copying lib\Crypto\Random\Fortuna\FortunaAccumulator.py -> build\lib.win-amd64-3.9\Crypto\Random\Fortuna
copying lib\Crypto\Random\Fortuna\FortunaGenerator.py -> build\lib.win-amd64-3.9\Crypto\Random\Fortuna
copying lib\Crypto\Random\Fortuna\SHAd256.py -> build\lib.win-amd64-3.9\Crypto\Random\Fortuna
copying lib\Crypto\Random\Fortuna\__init__.py -> build\lib.win-amd64-3.9\Crypto\Random\Fortuna
creating build\lib.win-amd64-3.9\Crypto\Random\OSRNG
copying lib\Crypto\Random\OSRNG\fallback.py -> build\lib.win-amd64-3.9\Crypto\Random\OSRNG
copying lib\Crypto\Random\OSRNG\nt.py -> build\lib.win-amd64-3.9\Crypto\Random\OSRNG
copying lib\Crypto\Random\OSRNG\posix.py -> build\lib.win-amd64-3.9\Crypto\Random\OSRNG
copying lib\Crypto\Random\OSRNG\rng_base.py -> build\lib.win-amd64-3.9\Crypto\Random\OSRNG
copying lib\Crypto\Random\OSRNG\__init__.py -> build\lib.win-amd64-3.9\Crypto\Random\OSRNG
creating build\lib.win-amd64-3.9\Crypto\SelfTest
copying lib\Crypto\SelfTest\st_common.py -> build\lib.win-amd64-3.9\Crypto\SelfTest
copying lib\Crypto\SelfTest\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\common.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_AES.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_ARC2.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_ARC4.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_Blowfish.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_CAST.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_DES.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_DES3.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_pkcs1_15.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_pkcs1_oaep.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\test_XOR.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
copying lib\Crypto\SelfTest\Cipher\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Cipher
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\common.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_HMAC.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_MD2.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_MD4.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_MD5.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_RIPEMD.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_SHA.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_SHA224.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_SHA256.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_SHA384.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\test_SHA512.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
copying lib\Crypto\SelfTest\Hash\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Hash
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Protocol
copying lib\Crypto\SelfTest\Protocol\test_AllOrNothing.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Protocol
copying lib\Crypto\SelfTest\Protocol\test_chaffing.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Protocol
copying lib\Crypto\SelfTest\Protocol\test_KDF.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Protocol
copying lib\Crypto\SelfTest\Protocol\test_rfc1751.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Protocol
copying lib\Crypto\SelfTest\Protocol\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Protocol
creating build\lib.win-amd64-3.9\Crypto\SelfTest\PublicKey
copying lib\Crypto\SelfTest\PublicKey\test_DSA.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\PublicKey
copying lib\Crypto\SelfTest\PublicKey\test_ElGamal.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\PublicKey
copying lib\Crypto\SelfTest\PublicKey\test_importKey.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\PublicKey
copying lib\Crypto\SelfTest\PublicKey\test_RSA.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\PublicKey
copying lib\Crypto\SelfTest\PublicKey\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\PublicKey
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Random
copying lib\Crypto\SelfTest\Random\test_random.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random
copying lib\Crypto\SelfTest\Random\test_rpoolcompat.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random
copying lib\Crypto\SelfTest\Random\test__UserFriendlyRNG.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random
copying lib\Crypto\SelfTest\Random\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Random\Fortuna
copying lib\Crypto\SelfTest\Random\Fortuna\test_FortunaAccumulator.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\Fortuna
copying lib\Crypto\SelfTest\Random\Fortuna\test_FortunaGenerator.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\Fortuna
copying lib\Crypto\SelfTest\Random\Fortuna\test_SHAd256.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\Fortuna
copying lib\Crypto\SelfTest\Random\Fortuna\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\Fortuna
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
copying lib\Crypto\SelfTest\Random\OSRNG\test_fallback.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
copying lib\Crypto\SelfTest\Random\OSRNG\test_generic.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
copying lib\Crypto\SelfTest\Random\OSRNG\test_nt.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
copying lib\Crypto\SelfTest\Random\OSRNG\test_posix.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
copying lib\Crypto\SelfTest\Random\OSRNG\test_winrandom.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
copying lib\Crypto\SelfTest\Random\OSRNG\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Random\OSRNG
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Util
copying lib\Crypto\SelfTest\Util\test_asn1.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Util
copying lib\Crypto\SelfTest\Util\test_Counter.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Util
copying lib\Crypto\SelfTest\Util\test_number.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Util
copying lib\Crypto\SelfTest\Util\test_winrandom.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Util
copying lib\Crypto\SelfTest\Util\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Util
creating build\lib.win-amd64-3.9\Crypto\SelfTest\Signature
copying lib\Crypto\SelfTest\Signature\test_pkcs1_15.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Signature
copying lib\Crypto\SelfTest\Signature\test_pkcs1_pss.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Signature
copying lib\Crypto\SelfTest\Signature\__init__.py -> build\lib.win-amd64-3.9\Crypto\SelfTest\Signature
creating build\lib.win-amd64-3.9\Crypto\Protocol
copying lib\Crypto\Protocol\AllOrNothing.py -> build\lib.win-amd64-3.9\Crypto\Protocol
copying lib\Crypto\Protocol\Chaffing.py -> build\lib.win-amd64-3.9\Crypto\Protocol
copying lib\Crypto\Protocol\KDF.py -> build\lib.win-amd64-3.9\Crypto\Protocol
copying lib\Crypto\Protocol\__init__.py -> build\lib.win-amd64-3.9\Crypto\Protocol
creating build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\DSA.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\ElGamal.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\pubkey.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\RSA.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\_DSA.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\_RSA.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\_slowmath.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
copying lib\Crypto\PublicKey\__init__.py -> build\lib.win-amd64-3.9\Crypto\PublicKey
creating build\lib.win-amd64-3.9\Crypto\Signature
copying lib\Crypto\Signature\PKCS1_PSS.py -> build\lib.win-amd64-3.9\Crypto\Signature
copying lib\Crypto\Signature\PKCS1_v1_5.py -> build\lib.win-amd64-3.9\Crypto\Signature
copying lib\Crypto\Signature\__init__.py -> build\lib.win-amd64-3.9\Crypto\Signature
Skipping optional fixer: buffer
Skipping optional fixer: idioms
Skipping optional fixer: set_literal
Skipping optional fixer: ws_comma
running build_ext
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Random.OSRNG.winrandom' extension
creating build\temp.win-amd64-3.9
creating build\temp.win-amd64-3.9\Release
creating build\temp.win-amd64-3.9\Release\src
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/ -Isrc/inc-msvc/ -Ic:\program files\python39\include -Ic:\program files\python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt /Tcsrc/winrand.c /Fobuild\temp.win-amd64-3.9\Release\src/winrand.obj
winrand.c
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(27): error C2061: errore di sintassi: identificatore 'intmax_t'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(28): error C2061: errore di sintassi: identificatore 'rem'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(28): error C2059: errore di sintassi: ';'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(29): error C2059: errore di sintassi: '}'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(31): error C2061: errore di sintassi: identificatore 'imaxdiv_t'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(31): error C2059: errore di sintassi: ';'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(41): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(42): error C2146: errore di sintassi: ')' mancante prima dell'identificatore '_Number'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(42): error C2061: errore di sintassi: identificatore '_Number'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(42): error C2059: errore di sintassi: ';'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(43): error C2059: errore di sintassi: ')'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(46): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(47): error C2146: errore di sintassi: ')' mancante prima dell'identificatore '_Numerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(47): error C2061: errore di sintassi: identificatore '_Numerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(47): error C2059: errore di sintassi: ';'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(47): error C2059: errore di sintassi: ','
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(49): error C2059: errore di sintassi: ')'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(51): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(57): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(64): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(70): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(77): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(83): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(90): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\inttypes.h(96): error C2143: errore di sintassi: '{' mancante prima di '__cdecl'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\program files\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\renzo\\AppData\\Local\\Temp\\pip-install-svmkdo9_\\pycrypto_ee48e2c475ff47aaa23d619983f3b5e3\\setup.py'"'"'; __file__='"'"'C:\\Users\\renzo\\AppData\\Local\\Temp\\pip-install-svmkdo9_\\pycrypto_ee48e2c475ff47aaa23d619983f3b5e3\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\renzo\AppData\Local\Temp\pip-record-qctz6vm0\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\renzo\AppData\Roaming\Python\Python39\Include\pycrypto' Check the logs for full command output.
From the log, you can get the path of Microsoft Visual Studio BuildTools, and then execute these commands:
cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build"
vcvarsall.bat x86_amd64
cd %VCINSTALLDIR%
for /R %f in (*stdint.h) do set CL=-FI"%f"
pip install machine
D:\projects\micropython\testesp>cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build"
D:\projects\micropython\testesp>c:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build>vcvarsall.bat x86_amd64
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86_x64'
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build>cd %VCINSTALLDIR%
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC>for /R %f in (*stdint.h) do set CL=-FI"%f"
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC>set CL=-FI"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include\stdint.h"
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC>pip install pycrypto
Defaulting to user installation because normal site-packages is not writeable
Collecting pycrypto
Using cached pycrypto-2.6.1.tar.gz (446 kB)
Using legacy 'setup.py install' for pycrypto, since package 'wheel' is not installed.
Installing collected packages: pycrypto
Running setup.py install for pycrypto ... done
Successfully installed pycrypto-2.6.1
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC>pip install machine
Defaulting to user installation because normal site-packages is not writeable
Collecting machine
Using cached machine-0.0.1-py2.py3-none-any.whl (4.2 kB)
Requirement already satisfied: pycrypto in c:\users\renzo\appdata\roaming\python\python39\site-packages (from machine) (2.6.1)
Installing collected packages: machine
WARNING: The script sample.exe is installed in 'C:\Users\renzo\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed machine-0.0.1
Controllare un LED
Per controllare un LED collegato al pin PC13
su una scheda ESP8266 (È il LED integrato per WeMos D1 mini), puoi inserire i seguenti comandi:
import machine
pin = machine.Pin('PC13', machine.Pin.OUT)
pin.on()
pin.off()
La prima riga importa il modulo machine
, che contiene classi e funzioni per interagire con l’hardware della scheda ESP8266 o ESP32.
La seconda riga crea un nuovo oggetto Pin
, che rappresenta un pin GPIO sulla scheda. In questo caso, l’oggetto Pin
viene creato con 2
come numero di pin e machine.Pin.OUT
come modalità, che imposta il pin come un’uscita. L’oggetto Pin
viene assegnato alla variabile pin
.
Questo accende l’uscita dell’oggetto pin
, che farà in modo che il corrispondente pin fisico sulla scheda emetta un’alta tensione.
Questo spegne l’uscita dell’oggetto pin
, che farà in modo che il corrispondente pin fisico sulla scheda emetta una bassa tensione.
Sketch blink led
Ecco un completo sketch MicroPython, un semplice programma che fa lampeggiare un LED integrato.
Prendi il tuo editor preferito, crea un file main.py
, e aggiungi queste righe.
import machine
import utime
pin = machine.Pin('PC13', machine.Pin.OUT)
while True:
pin.value(0)
utime.sleep_ms(500)
pin.value(1)
utime.sleep_ms(500)
Naturalmente, puoi anche testarlo in una sessione in tempo reale.
Per passare più righe devi:
Ctrl+E
- Incolla il codice
Ctrl+D
Carica il codice e visualizza l’output usando un monitor seriale
Carica il codice MicroPython sulla tua scheda STM32 utilizzando lo strumento da riga di comando adafruit-ampy
e visualizza l’output utilizzando un monitor seriale:
- Collega la tua scheda ESP8266 o ESP32 al tuo computer via USB.
- Installa il pacchetto
adafruit-ampy
utilizzando pip, che è un gestore di pacchetti per Python. Puoi installare questo pacchetto aprendo un prompt dei comandi (Windows) o un terminale (macOS/Linux) e es eguendo il seguente comando:
pip install adafruit-ampy
D:\projects\micropython\testesp>pip install adafruit-ampy
Defaulting to user installation because normal site-packages is not writeable
Collecting adafruit-ampy
Downloading adafruit_ampy-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting click
Using cached click-8.1.3-py3-none-any.whl (96 kB)
Requirement already satisfied: pyserial in c:\users\renzo\appdata\roaming\python\python39\site-packages (from adafruit-ampy) (3.0.1)
Collecting python-dotenv
Downloading python_dotenv-1.0.0-py3-none-any.whl (19 kB)
Collecting colorama
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Installing collected packages: python-dotenv, colorama, click, adafruit-ampy
WARNING: The script dotenv.exe is installed in 'C:\Users\renzo\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script ampy.exe is installed in 'C:\Users\renzo\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed adafruit-ampy-1.1.0 click-8.1.3 colorama-0.4.6 python-dotenv-1.0.0
- Potrebbe apparire anche un avviso durante il processo di installazione
WARNING: The script ampy.exe is installed in 'C:\Users\renzo\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
Allora andremo ad aggiungere anche il percorso Script alla variabile path.
- Cerca nel menu di Windows “
Modifica le variabili d'ambiente di sistema
“; - Nel pannello clicca su
Variabili d'ambiente...
. - Nelle variabili utente, seleziona “
Path
“ - Ed aggiungi la cartella Script.
- Scrivi il tuo codice MicroPython in un file sul tuo computer.
- Usa lo strumento da riga di comando
ampy
per caricare il file sulla scheda. Ad esempio, se il tuo codice MicroPython si trova in un file chiamatomain.py
e la tua scheda è collegata alla porta serialeCOM5
, puoi eseguire il seguente comando:
ampy --port COM5 put main.py
Nota: Sostituisci COM5 con la corretta porta seriale della tua scheda, e main.py
con il nome del tuo file di codice MicroPython.
- Una volta configurato il tuo monitor seriale, resetta la scheda premendo il pulsante di reset o scollegando e ricollegando il cavo USB. La scheda inizierà automaticamente ad eseguire il codice che hai caricato, e dovresti vedere l’output del tuo codice MicroPython nel monitor seriale.