NUCLEO-F767ZIにMicropythonをインストールする(v2)
2020/5/22
NUCLEO F767ZI MicroPython Install(v2)
NUCLEO F767ZI MicroPython Install(v2)
概要
「NUCLEO F767ZI」にMicropythonをインストールする方法について記載する (ホストPCとしてはubuntuを想定している)
事前準備
(1)書き込みツール(st-flash)のインストール
sudo apt install cmake
sudo apt install libusb-1.0
git clone https://github.com/texane/stlink.git
cd stlink
make
cd build/Release
sudo make install
sudo ldconfig
(2)ampyのインストール
AMPY_PORTは、自分の環境に合わせる。
pip install adafruit-ampy
export AMPY_PORT=/dev/ttyACM0
export AMPY_BAUD=115200
(3)picocomのインストール
sudo apt-get install picocom
以上のうち、exportしているものは、.bashrcに登録することを勧める。
コンパイラのバージョンアップ
以下でインストールしたコンパイラが古くてビルドエラーが出たのでバージョンアップする。
sudo apt-get install gcc-arm-none-eabi
(1)以下のurlから最新版をダウンロードする:
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
解凍したものを以下のフォルダに置く:
$HOME/Downloads/gcc-arm-none-eabi-8-2019-q3-update
(2)パス設定
#古いコンパイラを削除する
sudo apt-get remove gcc-arm-none-eabi
#パスを設定する
export PATH=$PATH:$HOME/Downloads/gcc-arm-none-eabi-8-2019-q3-update/bin
ビルド手順
以下の手順で行なう:
mkdir mp_nucleo
cd mp_nucleo
git clone https://github.com/micropython/micropython.git
cd micropython
cd mpy-cross
make
cd ..
cd ports/stm32
make submodules
make BOARD=NUCLEO_F767ZI
ls -l build-NUCLEO_F767ZI/firmware.*
-rw-rw-r-- 1 xxxx xxxx 458749 5月 21 23:42 build-NUCLEO_F767ZI/firmware.dfu
-rwxrwxr-x 1 xxxx xxxx 921348 5月 21 23:42 build-NUCLEO_F767ZI/firmware.elf
-rw-rw-r-- 1 xxxx xxxx 1289515 5月 21 23:42 build-NUCLEO_F767ZI/firmware.hex
-rw-rw-r-- 1 xxxx xxxx 1949998 5月 21 23:42 build-NUCLEO_F767ZI/firmware.map
arm-none-eabi-objcopy -O binary build-NUCLEO_F767ZI/firmware.elf build-NUCLEO_F767ZI/firmware.bin
ls -l build-NUCLEO_F767ZI/firmware.*
-rwxrwxr-x 1 xxxx xxxx 574668 5月 21 23:44 build-NUCLEO_F767ZI/firmware.bin
-rw-rw-r-- 1 xxxx xxxx 458749 5月 21 23:42 build-NUCLEO_F767ZI/firmware.dfu
-rwxrwxr-x 1 xxxx xxxx 921348 5月 21 23:42 build-NUCLEO_F767ZI/firmware.elf
-rw-rw-r-- 1 xxxx xxxx 1289515 5月 21 23:42 build-NUCLEO_F767ZI/firmware.hex
-rw-rw-r-- 1 xxxx xxxx 1949998 5月 21 23:42 build-NUCLEO_F767ZI/firmware.map
書き込み手順
上でビルドしたbinをst-flashで書き込む
st-flash write build-NUCLEO_F767ZI/firmware.bin 0x8000000
#出力例:
st-flash 1.6.0
2020-05-21T23:51:37 INFO common.c: Loading device parameters....
2020-05-21T23:51:37 INFO common.c: Device connected is: F76xxx device, id 0x10016451
2020-05-21T23:51:37 INFO common.c: SRAM size: 0x80000 bytes (512 KiB), Flash: 0x200000 bytes (2048 KiB) in pages of 2048 bytes
2020-05-21T23:51:37 INFO common.c: Attempting to write 574668 (0x8c4cc) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08080000 erasedEraseFlash - Sector:0x6 Size:0x40000
2020-05-21T23:51:43 INFO common.c: Finished erasing 7 pages of 262144 (0x40000) bytes
2020-05-21T23:51:43 INFO common.c: Starting Flash write for F2/F4/L4
2020-05-21T23:51:43 INFO flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 32768
size: 32768
<省略>
size: 32768
size: 17612
2020-05-21T23:51:52 INFO common.c: Starting verification of write complete
2020-05-21T23:51:57 INFO common.c: Flash written and verified! jolly good!
動作確認
picocomを使いボードとシリアルで通信する。
以下、通信(REPL)例:
$ picocom /dev/ttyACM0 -b115200
MicroPython v1.12-464-gcae77da on 2020-05-21; NUCLEO-F767ZI with STM32F767
Type "help()" for more information.
>>> import os
>>> os.uname()
(sysname='pyboard', nodename='pyboard', release='1.12.0', version='v1.12-464-gcae77da on 2020-05-21', machine='NUCLEO-F767ZI with STM32F767')
>>>
>>>
>>> list(5 * x + y for x in range(10) for y in [4, 2, 1])
[4, 2, 1, 9, 7, 6, 14, 12, 11, 19, 17, 16, 24, 22, 21, 29, 27, 26, 34, 32, 31, 39, 37, 36, 44, 42, 41, 49, 47, 46]
>>>
>>> import gc
>>> gc.collect()
>>> gc.mem_free()
273696
>>>
>>> help('modules')
__main__ math uasyncio/lock uos
_onewire micropython uasyncio/stream urandom
_uasyncio network ubinascii ure
_webrepl onewire ucollections uselect
builtins pyb ucryptolib usocket
cmath stm uctypes ussl
dht sys uerrno ustruct
framebuf uarray uhashlib utime
gc uasyncio/__init__ uheapq utimeq
lcd160cr uasyncio/core uio uwebsocket
lcd160cr_test uasyncio/event ujson uzlib
lwip uasyncio/funcs umachine
Plus any modules on the filesystem
>>>
# network,usocket,uwebsocketなどネットワーク関連が追加されていることが分かる。
ampy実行例
$ ampy -p /dev/ttyACM0 ls
/flash
$ ampy -p /dev/ttyACM0 ls /flash
/flash/README.txt
/flash/boot.py
/flash/main.py
/flash/pybcdc.inf
$ ampy -p /dev/ttyACM0 get /flash/boot.py
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
import machine
import pyb
pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse
$ ampy -p /dev/ttyACM0 get /flash/main.py
# main.py -- put your code here!
サンプルスクリプト
blink.py
# LED(1) // Green LED on board
# LED(2) // Blue LED on board
# LED(3) // Red LED on board
while True:
pyb.LED(1).on()
pyb.LED(2).on()
pyb.LED(3).on()
pyb.delay(1000)
pyb.LED(1).off()
pyb.LED(2).off()
pyb.LED(3).off()
pyb.delay(250)
ボード上の3つのLEDが点滅する。
実行例:
$ ampy -p /dev/ttyACM0 run blink.py
この場合、flashにスクリプトを書き込まずに直接RAMで実行される。
ボードの電源オンで直接スクリプトを実行する場合は
以下のようにする。(blink.pyをmain.pyに上書きする)
$ ampy -p /dev/ttyACM0 put blink.py /flash/main.py
この書き込み後、リセットボタンを押すと自動的にスクリプトが動作する。
User USB
User_USBコネクタをホストPCとUSB接続するとPYBFLASHホルダが現れ、ここにMicroPythonのプログラムを置くことができる。
(電源はstlink側のUSBコネクタから供給されているので、stlink側のコネクタもホストPCに接続する必要がある)
ストレージとしてMicroPythonのプログラムを置くことができるので、この場合、ampyを使用する必要はない、
Perfomance Test
performanceTest.py
# Peformace Test
import pyb
def performanceTest():
millis = pyb.millis
endTime = millis() + 10000
count = 0
while millis() < endTime:
count += 1
print("Count: ", count)
performanceTest()
実行結果としては以下のような数字になった:
>>> import performanceTest
Count: 5676566
>>>
参照URL
Turtorial Examples for Nucleo-MicroPython
NUCLEO-F767ZI digikey
NUCLEO-F767ZI mbed
The MicroPython project
STM32 Nucleo Board STM32F446RE
Quick reference for the pyboard
ampyを用いたMicroPythonのファイル操作とプログラム実行
MicroPython pyboard v1.1
新しいボードへMicroPythonを対応させる方法をざっくり解説
以上
| 固定リンク
「linux」カテゴリの記事
- platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法(2021.03.10)
- micro:bit Yotta開発ツール(linux版)(2021.01.09)
- PlatformIOをRaspberryPi4で動かしてみる(実験)(2020.10.20)
- headless RaspberryPiインストール方法(v2)(2020.10.20)
- wio-terminalのファームウェア・アップデートについて(linux版)(2020.10.15)
「mbed」カテゴリの記事
- micro:bit Yotta開発ツール(linux版)(2021.01.09)
- micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)(2021.01.02)
- NUCLEO-F767ZIにMicropythonをインストールする(v2)(2020.05.22)
- 開発ツールPlatformIOをArchProで使う(mbed版)(2020.05.20)
- 開発ツールmbed-cliをインストールする(2020.04.10)
「MicroPython」カテゴリの記事
- microbit-v2にMicropythonをインストールする(2021.05.06)
- PicoボードのMicroPythonをVS_CodeのextensionのPico-Goでプログラミングする(2021.02.10)
- MicroPython/CircuitPython Performance Test(2021.02.07)
- PicoボードにMicropython/CircuitPythonをインストールする(2021.02.03)
- MicroPython(F767ZI) Network Samples(2021.01.03)
「Nucleo」カテゴリの記事
- MicroPython/CircuitPython Performance Test(2021.02.07)
- MicroPython(F767ZI) Network Samples(2021.01.03)
- MicroPython(F767ZI)でStartwars(AsciiArt)を動かす(2020.12.29)
- NUCLEO-F767ZIにMicropythonをインストールする(v2)(2020.05.22)
- Nucleo-F303K8でADCの値をLCD(AQM0802)(i2c)に表示する(Arduino版)(2020.05.16)
この記事へのコメントは終了しました。
コメント