STM32 Nucleo BoardでMicropythonを楽しむ
Micropythonをビルドしてボードにインストールする
はじめに
遅ればせながらMicropythonに興味が出てきた。まずはSTマイクロエレクトロニクスのSTM32 Nucleo BoardにMicropythonを入れて動かすことからを始める。
使用したボード
STM32 Nucleo Board STM32F446RET
主なCPUの仕様
購入先
ソースからコンパイルする
開発環境 *1
- Intel Core i7-6700 CPU 3.40GHz
- Windows 10, 64-bit (Build 18362) 10.0.18362
- VMware Workstation 15 Player 15.5.2 build-15785246
- Ubuntu 16.04 LTS 64-bit
必要な開発ツール *1
Micropythonのビルドに必要な開発ツール
- git
- gcc (cross compiler)
- build-essential
- cmake (3.4.2 or later)
- pkg-config
- libusb-1.0
そのほか
- screen or picocom などのターミナルソフト
パッケージのインストール *3
私の環境では以下のパッケージをインストールした。足りないパッケージをインストールする
sudo apt-get install libffi-dev
sudo apt-get install gcc-arm-none-eabi
sudo apt-get install cmake
sudo apt-get install libusb-1.0.0-dev
sudo apt-get install screen
書き込みユーティリティ *1 *3
ビルドしたmicropythonのバイナリをボードに書き込むツールStlink Toolsをビルドする。すべてのユーザが使えるようにインストールする場合である。
git clone https://github.com/texane/stlink.git cd stlink make release make debug cd build/Release sudo make install sudo ldconfig
ビルド *2
ここでMicropythonをソースからビルドする。対象とするボードに合わせてmakeするが、どのボードが対応しているかは、treeコマンドを実行するとわかる。自分のボードにあったボード名でビルドする
# get source git clone https://github.com/micropython/micropython # This command should be executed from the root directory of this repository. cd micropython make -C mpy-cross # All other commands below should be executed from the ports/stm32/ directory. cd ports/stm32/ make submodules # this command to find your board tree -d boards/ # select board name & exectute make make BOARD=NUCLEO_F446RE # write binary to flash ram on board, use stlink tool sudo make BOARD=NUCLEO_F446RE deploy-stlink
テスト *2
PC上のubuntuからターミナルソフトを使ってボード上のMicropythonにアクセスする
screenの場合
# ctl+ a, k でターミナル終了 sudo screen /dev/ttyACM0 115200
picocomの場合
# ctl+a, ctl+x でターミナル終了 sudo picocom --b 115200 /dev/ttyACM0
参考文献
*2 README.md
*3 寝台急行はまなす