mbed

2021年1月 9日 (土)

micro:bit Yotta開発ツール(linux版)

2021/1/9
初版

yotta micro:bit MBED tool

yotta micro:bit MBED tool

概要

micro:bit Yotta開発ツール(linux版)
なお、本ツールは、microbit-v1用である。

インストール手順

mkdir microbit_ws cd microbit_ws # 必要なライブラリやツールをインストールする sudo apt-get update && sudo apt-get install python-setuptools cmake build-essential ninja-build python-dev libffi-dev libssl-dev && sudo easy_install pip # yotta をインストールする sudo pip install yotta # micoribt-samples をダウンロードする git clone https://github.com/lancaster-university/microbit-samples cd microbit-samples # yottaの設定 yt target bbc-microbit-classic-gcc # src/main.cppがターゲットソースになる yt build # ビルド結果(hex)をmicrobitに転送する # <USER>は実際の環境に合わせる cp build/bbc-microbit-classic-gcc/source/microbit-samples-combined.hex /media/<USER>/MICROBIT/

なお、source/examples に他のサンプルがある。

参考情報

Yotta/Installation on Linux

yotta Documentation
yotta: Build Software with Reusable Components

https://os.mbed.com/users/MACRUM/notebook/microbit/
micro:bit の使い方

https://github.com/toyowata/microbit_web_bluetooth/blob/master/README.md
Web Bluetooth(micro:bitとbluetooth接続してブラウザから制御する)

以上

続きを読む "micro:bit Yotta開発ツール(linux版)"

| | コメント (0)

2021年1月 2日 (土)

micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)

2021/1/9+
・BLE関連ライブラリでビルドできなかったが platformio.iniを変更してビルド可能にした。
・SoftDevice書き込みツールの インストール方法を追加した。

2021/1/5
SoftDevice(bleファームウェア)の再書き込みについて記載した。

2021/1/2
初版

cli micro:bit Arduino/MBED tool

cli micro:bit Arduino/MBED tool

概要

micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)

この記事は「 micro:bit MBED開発ツール(VScode+PlatformIO) 」の続編にあたり、arduinoプラットフォームでの設定やmicro:bit-v2の対応方法についても記述している。
(ホストはubuntuを想定している)

PlatformIOのインストール

python3 -m venv pio_env source pio_env/bin/activate pip3 install platformio インストール後も、本ツールを使用する場合 同じディレクトリで以下を実行する: source pio_env/bin/activate # 「source」は、「.」でも良い

準備

以下を実行して、udevのrulesを登録する:

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

microbit-v2対応

microbit-v2の対応がまだ未完了のようなので、以下を行なう必要がある。

cd ~/.platformio/boards # boardsがなければmkdirで作成する wget https://raw.githubusercontent.com/platformio/platform-nordicnrf52/master/boards/bbcmicrobit_v2.json

bbcmicrobit_v2.jsonの内容にミスがあるので 以下のように修正する:

"name": "BBC micro:bit V2", "upload": { "maximum_ram_size": 65536, "maximum_size": 524288, "protocol": "cmsis-dap", "protocols": [ "jlink", 上を以下のように修正する: "name": "BBC micro:bit V2", "upload": { "maximum_ram_size": 131072, "maximum_size": 524288, "protocol": "cmsis-dap", "protocols": [ "jlink",

RAMサイズが間違っていた。(64KB→128KB)

コンパイル時(pio run)で以下のようなメッセージになればOK.

-------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/bbcmicrobit_v2.html PLATFORM: Nordic nRF52 (6.0.0) > BBC micro:bit V2 HARDWARE: NRF52833 64MHz, 128KB RAM, 512KB Flash DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink, stlink) PACKAGES: - framework-arduinonordicnrf5 1.700.201209 (7.0) - tool-bossac-nordicnrf52 1.10901.201022 (1.9.1)

ちなみにv1の場合は以下のようになる:

-------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf51/bbcmicrobit.html PLATFORM: Nordic nRF51 (6.1.0) > BBC micro:bit HARDWARE: NRF51822 16MHz, 16KB RAM, 256KB Flash DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (jlink) PACKAGES: - framework-arduinonordicnrf5 1.700.201209 (7.0) - tool-nrfjprog 1.90702.1 (9.7.2)

arduino用のplatformio.ini

microbit-v1用

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:bbcmicrobit] platform = nordicnrf51 board = bbcmicrobit framework = arduino build_flags = -DMICROBIT monitor_speed = 115200 lib_ldf_mode = deep+ #upload_port = /media/USER/MICROBIT #upload_protocol = mbed upload_protocol = cmsis-dap lib_deps = https://github.com/adafruit/Adafruit_BusIO/archive/master.zip https://github.com/sparkfun/SparkFun_MAG3110_Breakout_Board_Arduino_Library/archive/master.zip https://cdn-learn.adafruit.com/assets/assets/000/046/217/original/MMA8653.zip https://github.com/stm32duino/LSM303AGR/archive/master.zip https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip # #https://github.com/sandeepmistry/arduino-BLEPeripheral/archive/master.zip #https://github.com/adafruit/Adafruit_Microbit/archive/master.zip

BLE関連を含むライブラリはコンパイルエラーになるのでコメントアウトしている。 コンパイルエラーになる原因は不明(今後、調査予定)(2021/1/9時点で解決)

microbit-v2用

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:bbcmicrobit_v2] platform = nordicnrf52 board = bbcmicrobit_v2 framework = arduino build_flags = -DMICROBIT_V2 monitor_speed = 115200 lib_ldf_mode = deep+ #upload_port = /media/USER/MICROBIT #upload_protocol = mbed upload_protocol = cmsis-dap lib_deps = https://github.com/adafruit/Adafruit_BusIO/archive/master.zip https://github.com/sparkfun/SparkFun_MAG3110_Breakout_Board_Arduino_Library/archive/master.zip https://cdn-learn.adafruit.com/assets/assets/000/046/217/original/MMA8653.zip https://github.com/stm32duino/LSM303AGR/archive/master.zip https://github.com/adafruit/ Adafruit-GFX-Library/archive/master.zip # #https://github.com/sandeepmistry/arduino-BLEPeripheral/archive/master.zip #https://github.com/adafruit/Adafruit_Microbit/archive/master.zip

BLE関連を含むライブラリはコンパイルエラーになるのでコメントアウトしている。 コンパイルエラーになるのはmicrobit-v2のプロセッサ対応が未完のせいが考えられる。

テスト用スケッチ

以下はv1/v2の両方で動作する:

src/ASCIItable.ino

/* ASCII table Prints out byte values in all possible formats: - as raw binary values - as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti <http://www.zambetti.com> modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ASCIITable */ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example, '!' is the same as 33, so you could also use this: // int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the byte. // The Serial Monitor interprets all bytes as ASCII, so 33, the first number, // will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. // this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if (thisByte == 126) { // you could also use if (thisByte == '~') { // This loop loops forever and does nothing while (true) { continue; } } // go on to the next character thisByte++; }

arduinoのサンプルそのもの(bpsのみ変更)

src/microbit_blink.ino

#ifdef MICROBIT const int COL1 = 3; // Column #1 control const int LED = 26; // 'row 1' led #endif #ifdef MICROBIT_V2 const int COL1 = 4; const int LED = 21; #endif void setup() { Serial.begin(115200); Serial.println("microbit is ready!"); // because the LEDs are multiplexed, we must ground the opposite side of the LED pinMode(COL1, OUTPUT); digitalWrite(COL1, LOW); pinMode(LED, OUTPUT); } void loop(){ Serial.println("blink!"); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); }

MatrixLEDの仕様が変更になったので#ifdefで切り替えている。

テスト用スケッチ(ビルドエラーが起きるもの)

以下は、platformioでライブラリがBLEに関係がありエラーになった例である:

src/matrixdemo.ino

// This is a demo of the matrix driver code // works with Adafruit GFX commands - its just // a really small screen! // https://learn.adafruit.com/adafruit-gfx-graphics-library #include <Adafruit_Microbit.h> Adafruit_Microbit_Matrix microbit; const uint8_t smile_bmp[] = { B00000, B01010, B00000, B10001, B01110, }; void setup() { Serial.begin(9600); Serial.println("microbit matrix demo is ready!"); microbit.begin(); } void loop(){ // Fill screen microbit.fillScreen(LED_ON); delay(1000); // draw a heart microbit.show(microbit.HEART); delay(1000); // draw a no cross microbit.show(microbit.NO); delay(1000); // draw a yes check microbit.show(microbit.YES); delay(1000); // draw a custom made bitmap face microbit.show(smile_bmp); delay(1000); microbit.clear(); // Draw a line 'by hand' microbit.drawPixel(0, 0, LED_ON); microbit.drawPixel(1, 1, LED_ON); microbit.drawPixel(2, 2, LED_ON); microbit.drawPixel(3, 3, LED_ON); microbit.drawPixel(4, 4, LED_ON); // draw the 'opposite' line with drawline (easier!) microbit.drawLine(0, 4, 4, 0, LED_ON); delay(1000); // erase screen, draw a square microbit.clear(); microbit.drawRect(0,0, 5, 5, LED_ON); // top left corner @ (0,0), 5 by 5 pixels size delay(1000); // erase screen, draw a circle microbit.clear(); microbit.drawCircle(2,2, 2, LED_ON); // center on 2, 2, radius 2 delay(1000); // erase screen, draw a filled triangle microbit.clear(); microbit.fillTriangle(0,4, 2,0, 4,4, LED_ON); delay(1000); // scroll some text the 'easy' way microbit.print("HELLO WORLD"); // count up! for (int i=0; i<10; i++) { microbit.print(i); delay(500); } microbit.print(3.1415, 4); // pi time, 4 digits of precision!! }

本家のArduino-IDEではコンパイルができて実行もできた。(だだしv1のみ)

動作しない場合、SoftDevice(BLEファームウェア)が消されている可能性があるので
以下でダウンロードしたhexファイルをMICROBITフォルダにドラッグ&ドロップ後、
書き込みを行なう。(Softdevice:"S110"にすることを忘れずに!)

wget https://cdn-learn.adafruit.com/assets/assets/000/046/777/original/microbit-adv.hex

上の方法は、簡易的な方法になる。正式な書き込みツールのインストール方法については参考情報のリンクを参照のこと。

src/ble_uartdemo.ino

/* * Serial Port over BLE * Create UART service compatible with Nordic's *nRF Toolbox* and Adafruit's *Bluefruit LE* iOS/Android apps. * * Copyright (c) Sandeep Mistry. All rights reserved. * Licensed under the MIT license. See LICENSE file in the project root for full license information. * BLESerial class implements same protocols as Arduino's built-in Serial class and can be used as it's wireless * replacement. Data transfers are routed through a BLE service with TX and RX characteristics. To make the * service discoverable all UUIDs are NUS (Nordic UART Service) compatible. * * Please note that TX and RX characteristics use Notify and WriteWithoutResponse, so there's no guarantee * that the data will make it to the other end. However, under normal circumstances and reasonable signal * strengths everything works well. */ #include <Adafruit_Microbit.h> Adafruit_Microbit microbit; void setup() { Serial.begin(115200); Serial.println("Microbit ready!"); // custom services and characteristics can be added as well microbit.BTLESerial.begin(); microbit.BTLESerial.setLocalName("microbit"); // Start LED matrix driver after radio (required) microbit.begin(); } void loop() { microbit.BTLESerial.poll(); forward(); //loopback(); spam(); } // forward received from Serial to microbit.BTLESerial and vice versa void forward() { if (microbit.BTLESerial && Serial) { int byte; if (microbit.BTLESerial.available()) { Serial.write(microbit.BTLESerial.read()); } char buffer[10]; memset(buffer, 0x0, 10); int idx = 0; while (Serial.available() && idx != 10) { buffer[idx] = Serial.read(); idx++; } if (idx) { microbit.BTLESerial.write(buffer, idx); } } delay(1); } // echo all received data back void loopback() { if (microbit.BTLESerial) { int byte; while ((byte = microbit.BTLESerial.read()) > 0) { microbit.BTLESerial.write(byte); } } } // periodically sent time stamps void spam() {  if (microbit.BTLESerial) { microbit.BTLESerial.print(millis()); microbit.BTLESerial.println(" tick-tacks!"); delay(1000); } }

本家のArduino-IDEではコンパイルができて実行もできた。(だだしv1のみ)

動作しない場合、SoftDevide(BLEファームウェア)が消されている可能性があるので
以下でダウンロードしたhexファイルをMICROBITフォルダにドラッグ&ドロップ後、
書き込みを行なう。(Softdevice:"S110"にすることを忘れずに!)

wget https://cdn-learn.adafruit.com/assets/assets/000/046/777/original/microbit-adv.hex

上の方法は、簡易的な方法になる。正式な書き込みツールのインストール方法については参考情報のリンクを参照のこと。

対向するフマフォ・アプリは以下になる:
Bluefruit Connect/iPhone
Bluefruit Connect/Android

スマフォ・アプリ使用時、デバイスのMACアドレスだけでデバイス名がないので
「Uart Capable」と付記があるアドレスのデバイスを選択すること。

Arduino-IDEを使用する際の設定

(1)IDEを起動して[ファイル/環境設定(Preferences)]に入り 以下のurlを[追加のボードマネージャーのURL]のテキストボックスに以下を入力する。 https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json (2)[ツール/ボード/ボードマネージャ(Tools>Board>Boards Manager)]で「nRF5」で検索して "Nordic Semiconductor nRF5 Boards" by Sandeep Mistry をインストールする (3)platformio.iniに登録されているzipのurlにアクセスしてzipファイルをダウンロードする (4)[スケッチ/ライブラリをインクルード/.ZIP形式でインストール]でダウンロードしたzipファイルを指定してインストールする

注意:
ボードとして [BBC micro:bit](v1)を選択した場合、Softdeviceは"S110"に設定すること。
v2の場合、不要(設定できない)

ショートカット:

上の(3)(4)は以下の方法でも良い: cd ~/Arduino/libraries wget https://xxxxx/archive/master.zip unzip master.zip rm master.zip # 以上をファイルの数だけ繰り返す

mbed対応

上で述べたplatformio.iniのplatformのところを以下のように変更するとmbed対応になる。

framework = arduino 以下のように変更する: framework = mbed

ただし、v2は、まだ、mbed対応になっていなのでエラーになる。 また、当然のことながら、arduino用ライブラリでなくmbed用ライブラリを使うこと。

また、microbit-v1用開発ツールとして以下のものを使用する選択肢もある:
micro:bit Yotta開発ツール(linux版)

platformioでBLE関連ライブラリがビルドできなかった問題の解決(2021/1/9)

microbit-v1用のplatformio.iniを以下のように変更する:
(変更箇所のみ記載)

<省略> build_flags = -DMICROBIT -DNRF51_S110 <省略> # https://github.com/sandeepmistry/arduino-BLEPeripheral/archive/master.zip https://github.com/adafruit/Adafruit_Microbit/archive/master.zip <省略>

具体的には、ビルドできなかった以下のスケッチがビルド&実行可能になる。

src/matrixdemo.ino src/ble_uartdemo.ino

ただし、ble_uartdemo.ino は参照エラーになるので
ソースの先頭に以下のプロトタイプ宣言を追加すること:

// prototype definitions void forward(); void spam(); void loopback();

参考情報

SoftDevice書き込みツールのインストール方法
https://github.com/sandeepmistry/arduino-nRF5#flashing-a-softdevice

Flashing a SoftDevice cd <SKETCHBOOK>, where <SKETCHBOOK> is your Arduino Sketch folder: OS X: ~/Documents/Arduino Linux: ~/Arduino Windows: ~/Documents/Arduino Create the following directories: tools/nRF5FlashSoftDevice/tool/ Download nRF5FlashSoftDevice.jar to <SKETCHBOOK>/tools/nRF5FlashSoftDevice/tool/ wget https://github.com/sandeepmistry/arduino-nRF5/releases/download/tools/nRF5FlashSoftDevice.jar Restart the Arduino IDE Select your nRF board from the Tools -> Board menu Select a SoftDevice from the Tools -> "SoftDevice: " menu Select a Programmer (J-Link, ST-Link V2, or CMSIS-DAP) from the Tools -> "Programmer: " menu Select Tools -> nRF5 Flash SoftDevice Read license agreement Click "Accept" to accept license and continue, or "Decline" to decline and abort If accepted, SoftDevice binary will be flashed to the board

micro:bit v2 で遊ぶ

platformio関連:

https://docs.platformio.org/en/latest/boards/nordicnrf52/bbcmicrobit_v2.html https://docs.platformio.org/en/latest/platforms/creating_board.html Installation 1.Create boards directory in core_dir if it doesn’t exist. 2.Create myboard.json file in this boards directory. 3.Search available boards via pio boards command. You should see myboard board.

PlatformIO Core (CLI)

以上

続きを読む "micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)"

| | コメント (0)

2020年5月22日 (金)

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を対応させる方法をざっくり解説

MicroPython Performance Test

以上

続きを読む "NUCLEO-F767ZIにMicropythonをインストールする(v2)"

| | コメント (0)

2020年5月20日 (水)

開発ツールPlatformIOをArchProで使う(mbed版)

2020/5/20+

PlatformIO cli ArchPro

PlatformIO cli ArchPro

概要

開発ツールPlatformIOを以下のArchProで使う(mbed版)。VisualCodeのプラグインとしてPlatformIOを使用することができるが、ここでは、cliとしての使い方について記する。 (ホストPCとしてはubuntuを想定している)

Arch Pro

PlatformIOのインストール

python3 -m venv pio_env source pio_env/bin/activate pip3 install platformio インストール後も、本ツールを使用する場合 同じディレクトリで以下を実行する: source pio_env/bin/activate # 「source」は、「.」でも良い

準備

以下を実行して、udevのrulesを登録する:

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

interface firmwareをアップデートする:

wget https://developer.mbed.org/media/uploads/yihui/lpc11u35_lpc1768_if_mbed_20150128.bin # ボードのボタンを押しながらホストPCとUSB接続する #「MBED LOADER」のホルダが現れるので、 # ここに上のダウンロードしたファイルをドラッグ&ドロップする # ファームウェアの書き込みが開始されるので # 書き込みが終了するまで待つ

なお、以下のバイナリが最新版のようだが、linuxでエラー(容量不足)になって書き込めなかったので、 上で説明したバイナリを利用した:
https://armmbed.github.io/DAPLink/firmware/0253_lpc11u35_archpro_0x0000.bin
(windowsでは書き込めるのかもしれない)

#ターゲットボードのtarget名を検索する # (ここでは seeedArchPro を検索する) $ pio boards | grep Arch #出力例: seeedArchBLE NRF51822 16MHz 128KB 16KB Seeed Arch BLE seeedArchLink NRF51822 16MHz 256KB 16KB Seeed Arch Link seeedArchGPRS LPC11U37 48MHz 128KB 10KB Seeed Arch GPRS V2 seeedArchPro LPC1768 96MHz 512KB 64KB Seeed Arch Pro seeedArchMax STM32F407VET6 168MHz 512KB 192KB Seeed Arch Max #target名として「seeedArchPro」が判明した # プロジェクトblink のディレクトリを作成する mkdir blink cd blink # 以下を実行して必要なファイルを作成する pio init --board seeedArchPro nano platformio.ini # platformio.iniを以下のように編集する:
; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:seeedArchPro] platform = nxplpc board = seeedArchPro framework = mbed upload_port = /media/USER/MBED upload_protocol = mbed debug_tool = cmsis-dap

「/media/USER/MBED」の部分は、自分の環境に合わせる。

続き:

# テスト用のmain.cppを作成する nano src/main.cpp 以下の内容に編集する:
#include "mbed.h" //DigitalOut led1(LED4); // ORANGE DigitalOut led1(LED3); // BLUE //DigitalOut led1(LED2); // RED //DigitalOut led1(LED1); // GREEN int main() { while(1) { led1 = !led1; wait(0.1); } }

続き:

# build pio run # ボードをホストPCに接続する # build&upload(flash) pio run -t upload # buildしないで書き込む場合は以下を実行する: pio run -t nobuild -t upload -v # -v は、詳細を表示するオプション # 以上で、基本的な操作としては完了となる

書き込み後、ボード上にある4つのLEDのうちの1つが点滅する。 VScodeにplatformioのプラグインがインストールされているのであれば
code ./blink
でVScodeを起動して、ソース上の行番号の左側をクリックして ブレークポイントを設定してデバッガができる。

別のサンプル例

#include "mbed.h" Serial pc(USBTX, USBRX, 115200); // tx, rx DigitalIn mypin(P0_23); // change this to the button on your board DigitalOut myled(LED3); int main() { // check mypin object is initialized and connected to a pin if(mypin.is_connected()) { pc.printf("mypin is connected and initialized! \n\r"); } // Optional: set mode as PullUp/PullDown/PullNone/OpenDrain mypin.mode(PullNone); // press the button and see the console / led change while(1) { pc.printf("mypin has value : %d \n\r", mypin.read()); myled = mypin; // toggle led based on value of button wait(0.25); } }

書き込みが完了すると、以下の動作になる:
P0_23が入力ポートになっているので、このポートをGNDか3V3に接続すると、 値か0か1に変化する。この値が0の場合、青いLED3が光る。入力ポートの 状態は、シリアル(/dev/ttyACM0)出力される。

参考情報

Seeeduino-Arch-Pro mbed
mbed/Platform/ArchPro wiki

PlatformIO Core (CLI)

ARMmbed/DAPLink

以上

続きを読む "開発ツールPlatformIOをArchProで使う(mbed版)"

| | コメント (0)

2020年4月10日 (金)

開発ツールmbed-cliをインストールする

2020/4/10

mbed-cli Install KL25Z

mbed-cli Install KL25Z

概要

開発ツールmbed-cliをインストールする。ターゲットボードは以下のKL25Zとする。python2.7がツールのインストールに必要なので そのための仮想環境を設定する。(pythonは、anacondaでインストールされている前提)
(ホストPCとしてはubuntuを想定している)

FRDM-KL25Z

開発ツールのインストール

conda create -n mbed python=2.7 conda activate mbed pip install mbed-cli

設定した仮想環境を確認するには以下を実行する:
conda info -e

この出力に「mbed」が含まれていればOK。

インストール後も、本ツールを使用する場合 以下を実行する:
conda activate mbed

デモ用プロジェクトhelloworldを作成する

mkdir helloworld cd helloworld mbed new .

main.cppを作成する

nano main.cpp

以下の内容のmain.cppを作成する:
main.cpp

// Colorful LED #include <mbed.h> #define DELAY 500 DigitalOut ledR(LED_RED); DigitalOut ledG(LED_GREEN); DigitalOut ledB(LED_BLUE); int main(){ while(true){ // Orange ledR = 0; ledG = 0; ledB = -1; Thread::wait(DELAY); // Megenta ledR = 0; ledG = -1;; ledB = 0; Thread::wait(DELAY); // Red ledR = 0; ledG = -1; ledB = -1; Thread::wait(DELAY); // Cyan ledR = -1; ledG = 0; ledB = 0; Thread::wait(DELAY); // Green ledR = -1; ledG = 0; ledB = -1; Thread::wait(DELAY); // Blue ledR = -1; ledG = -1; ledB = 0; Thread::wait(DELAY); // Black ledR = -1; ledG = -1; ledB = -1; Thread::wait(DELAY); // White ledR = 0; ledG = 0; ledB = 0; Thread::wait(DELAY); } }

ビルド

mbed compile -v -t GCC_ARM -m kl25z

ビルド出力例:

... ... Link: helloWorld Elf2Bin: helloWorld | Module | .text | .data | .bss | |------------------|---------------|-------------|-------------| | [fill] | 44(+44) | 4(+4) | 28(+28) | | [lib]/c.a | 19072(+19072) | 2472(+2472) | 89(+89) | | [lib]/gcc.a | 8900(+8900) | 0(+0) | 0(+0) | | [lib]/misc | 192(+192) | 4(+4) | 28(+28) | | main.o | 80(+80) | 0(+0) | 0(+0) | | mbed-os/drivers | 92(+92) | 0(+0) | 0(+0) | | mbed-os/hal | 1436(+1436) | 4(+4) | 67(+67) | | mbed-os/platform | 3044(+3044) | 264(+264) | 220(+220) | | mbed-os/rtos | 6460(+6460) | 168(+168) | 5973(+5973) | | mbed-os/targets | 2424(+2424) | 4(+4) | 19(+19) | | Subtotals | 41744(+41744) | 2920(+2920) | 6424(+6424) | Total Static RAM memory (data + bss): 9344(+9344) bytes Total Flash memory (text + data): 44664(+44664) bytes Image: ./BUILD/KL25Z/GCC_ARM/helloWorld.bin

書き込み

上で作成したhelloworld.binをmbedストレージにドラッグ&ドロップする。

実行

書き込みが終わったら、ボードのresetボタンを押す。 ボードのLEDが色々な色で光れば動作としてはOK.

mbed-cli コマンドリスト

$ mbed -h usage: mbed [-h] [--version] ... Command-line code management tool for ARM mbed OS - http://www.mbed.com version 1.10.2 Use "mbed <command> -h|--help" for detailed help. Online manual and guide available at https://github.com/ARMmbed/mbed-cli optional arguments: -h, --help show this help message and exit --version print version number and exit Commands: new Create new mbed program or library import Import program from URL add Add library from URL remove Remove library deploy Find and add missing libraries publish Publish program or library update Update to branch, tag, revision or latest sync Synchronize library references ls View dependency tree releases Show release tags status Show version control status compile Compile code using the mbed build tools test Find, build and run tests device-management device management subcommand export Generate an IDE project detect Detect connected Mbed targets/boards sterm Open serial terminal to connected target. config Tool configuration target Set or get default target toolchain Set or get default toolchain cache Repository cache management help This help screen

サポートしているボードを確認したい場合、変則的なやり方になるが 以下を実行するとサポートしているボードがリストアップされる:
(意図的にエラーを出力させる)
mbed compile -v -t GCC_ARM -m x

参考情報

mbedのプロジェクトをmbed-cliを使ってGCC-ARMでビルドするまで
Working with Mbed CLI

主なMbed対応デバイスの紹介

mbed FRDM KL25Z Examples

An introduction to Arm Mbed OS 5
Arm Mbed OS 2 vs. Arm Mbed OS 5

以上

続きを読む "開発ツールmbed-cliをインストールする"

| | コメント (0)

2020年1月16日 (木)

microbit MicroPython CLI開発ツール

2020/1/15+

microbit Micropython CLI(Command Line Interface) tool

microbit MicroPython CLI tool

概要

microbitのMicroPythonのプログラミングの書き込み/実行をコマンドラインで行なう方法について説明する。 MicroPythonのfirmwareのhexとMicroPythonのスクリプトの2つをhexとして結合したものを microbitに書き込んでいるので、firmwareとスクリプトを結合するツールを利用する。

ツールのインストール

mkdir microbit_MP cd microbit_MP git clone https://github.com/bbcmicrobit/micropython.git cd micropython/tools #このディレクトリにあるmakecombinedhex.pyをツールとして使うことになる。

firmwareのダウンロード(その1)

micro:bitの最新版の場合、v2.0のeditorの出力したfirmwareを利用する。 以下のオンラインツールを利用してfirmwareを作る。
(1)以下のリンクをクリックしてエディタを起動する。
microbit-python-editor v2.0
(2)編集して空のスクリプトを作る。
(3)[Download]を押して、生成したhexをダウンロードする。
(4)ダウンロードしたhexをfirmwareV20.hexにrenameする。
(5)このhexファイルを~/microbit_MP/micropython/toolsに置く。

firmwareのダウンロード(その2)

互換ボードのchibi:bitの場合、メモリマップの違いか、microbitの最新版用のhexを書き込んだ場合、エラーになり動作しないことがあるので、初期バージョンのpython-editor-mbf0.1.zipに含まれるfirmware.hexをそのまま使用する。
このhexファイルを~/microbit_MP/micropython/toolsに置く。
現在はネットに置いていない?ようなので、取り出したfirmware.hexをここに置く。
(microbitのみしか使用しないときは、本件は不要)

使用例

以下の実行例でmicrobitに書き込むouthexがDownloadのディレクトリにでき、hello.py、compass.pyが入力するスクリプトのファイルになる。入力するスクリプトは任意のエディタで作る。

~/microbit_MP/micropython/tools$ ./makecombinedhex.py firmwareV20.hex hello.py -o ~/Downloads/out.hex ./makecombinedhex.py firmwareV20.hex ../examples/compass.py -o ~/Downloads/out.hex

書き込み/実行

上で作ったout.hexを接続しているmicrobitのストレージに書き込む。 書き込んだ後、該当のストレージが消えるが、再度、出現したら書き込み完了になるので ボードの[reset]を押すと書き込んだプログラムが起動する。

bashスクリプト定義

上のままだと使いにくいので、以下のようなbashスクリプトを定義する。:
(chmd u+x filename で実行権限を与えること)

chibibit用:
(chibibitのストレージなどは自分の環境に合わせること)
mpy2chibi

#!/bin/bash HX=~/microbit_MP/micropython/tools/firmware.hex PY=$PWD/$1 OUT=~/Downloads/$1_V10.hex #echo $HX #echo $PY #echo $OUT ~/microbit_MP/micropython/tools/makecombinedhex.py $HX $PY -o $OUT cp $OUT /media/user/CHIBIBIT/ rm $OUT

microibt用:
(microbitのストレージなどは自分の環境に合わせること)
mpy2mb

#!/bin/bash HX=~/microbit_MP/micropython/tools/firmwareV20.hex PY=$PWD/$1 OUT=~/Downloads/$1_V20.hex #echo $HX #echo $PY #echo $OUT ~/microbit_MP/micropython/tools/makecombinedhex.py $HX $PY -o $OUT cp $OUT /media/user/MICROBIT/ rm $OUT

これらのスクリプトを利用して
以下のようにで一気に書き込みが行える。

./mpy2chibi hello.py ./mpy2mb hello.py

これで、好みのエディタで作成したスクリプトをmicrobitで実行できる。

おまけ(offline editor)

以下のやり方でofflineのeditorが使えるようになる。

git clone https://github.com/bbcmicrobit/PythonEditor cd PythonEditor git submodule update --init --recursive # 以下のコマンドでeditorを起動することができる。。 ./bin/show Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... # http://localhost:8000/editor.htmlをブラウザーでアクセスするとオンラインと同じeditorが起動する。 # 以下のコマンドでもeditorを起動する firefox editor.html # または chromium-browser editor.html

参考参照:
Python Editor Version 2
version 2.0になってから、WebUSB(chromeのみ)を利用して、cmsis-dap経由で、microbitにプログラムを書き込んだり、シリアルでデータをやり取りできるようになり、便利になった。

以上

続きを読む "microbit MicroPython CLI開発ツール"

| | コメント (0)

2020年1月12日 (日)

Nucleo STM32F303K8 開発ツール

2020/1/12

Nucleo STM32F303K8 tool (VScode+PlatformIO)

Nucleo STM32F303K8 tool (VScode+PlatformIO)

概要

「Nucleo STM32F303K8」ボードの開発ツールとして、VScodeの拡張としてPlatformIOを導入して、そのなかで開発ツール(コンパイラ、リンカ、アップローダー)をインストールする。 ここでは、linux環境でのインストール方法について説明する。

準備

ツールをインストール前に環境整備として以下を設定する:
(1)Python 2.7またはPython 3.5+のインストール

sudo apt-get install python3

(2)udevのruleの設定

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo service udev restart sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER/home/komatsu/Documents/PlatformIO/Projects/LPC1768_mbed_01/src/main.cpp

開発ツールのインストール

上の準備が終わったら、プロセッサとボードの種類は異なるが、インストール方法が分かりやすいので、以下を参考にインストールする。:
https://www.media.lab.uec.ac.jp/?page_id=1414
ESP32をVSCodeとPlatformIO IDEで動かす方法

新しいプロジェクトを作り、その際、今回の場合、Boardとして、
「ST Nucleo F303K8」を選択し、Frameworkとして
3つの選択肢(Arduino,Mbed,STM32Cube)から「mbed」を選択して Nameに任意の名前を入力して[Finish]をクリックする。
(このNameはプロジェクト名かつフォルダ名になる)

その後、必要なツールのインストールが開始するが、完了後、platform.iniの内容に以下が含まれることを確認する。

[env:nucleo_f303k8] platform = ststm32 board = nucleo_f303k8 framework = mbed

IDE設定

platformio.iniファイルを以下のように編集する:
upload_portは、自分の環境に合わせて変更すること。

;PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:nucleo_f303k8] platform = ststm32 board = nucleo_f303k8 framework = mbed upload_port = /media/user/NODE_F303K8 upload_protocol = mbed

ビルドテストのためのサンプルプログラム

サンプル(複数のプログラムを#defineで切り替える):

#include <mbed.h> //#define BLINK #define SERIAL #ifdef BLINK // LED2(Red) for PWR, LED1 for COM(usb) on board DigitalOut myled(LED3); // Green LED on board int main() { while(1) { myled = 1; wait(0.4); myled = 0; wait(1); } } #endif //========================================= #ifdef SERIAL Serial pc(SERIAL_TX, SERIAL_RX); // 9600 bauds DigitalOut myled(LED3); int main() { int i = 1; pc.printf("Hello World !\n"); while(1) { wait(1); pc.printf("This program runs since %d seconds.\n", i++); myled = !myled; } } #endif //=========================================

build/upload

(1)ボードとホストPCをUSBケーブルで接続する。
(2)VScode画面の最下行にあるアイコンからBuildのアイコンをクリックしてビルド実行する。
(3)VScode画面の最下行にあるアイコンからUploadのアイコンをクリックしてアップロード(ボードへのプログラム書込)を実行する。
注意:SerialMoniter画面に切り替えている場合、その画面で、Ctrl+Cを押して、事前に閉じる必要がある。
(4)書き込み終了後、自動的に書き込んだプログラムが起動する。 (起動しない場合や再起動したい場合、ボードの[reset]ボタンを押す)

build出力ログ例:

> Executing task in folder ST32F303K8_mbed_01: platformio run < Processing nucleo_f303k8 (platform: ststm32; board: nucleo_f303k8; framework: mbed) --------------------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f303k8.html PLATFORM: ST STM32 6.0.0 > ST Nucleo F303K8 HARDWARE: STM32F303K8T6 72MHz, 12KB RAM, 64KB Flash DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink) PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51401.191023 (5.14.1) Collecting mbed sources... LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 14 compatible libraries Scanning dependencies... No dependencies Building in release mode <省略> Linking .pio/build/nucleo_f303k8/firmware.elf Checking size .pio/build/nucleo_f303k8/firmware.elf Building .pio/build/nucleo_f303k8/firmware.bin Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" DATA: [= ] 13.0% (used 1600 bytes from 12288 bytes) PROGRAM: [==== ] 43.0% (used 28196 bytes from 65536 bytes) ===== [SUCCESS] Took 11.12 seconds ===== Terminal will be reused by tasks, press any key to close it.

upload出力ログ例:

> Executing task in folder ST32F303K8_mbed_01: platformio run --target upload < Processing nucleo_f303k8 (platform: ststm32; board: nucleo_f303k8; framework: mbed) ----------------------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f303k8.html PLATFORM: ST STM32 6.0.0 > ST Nucleo F303K8 HARDWARE: STM32F303K8T6 72MHz, 12KB RAM, 64KB Flash DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink) PACKAGES: tool-dfuutil 1.9.190708, toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51401.191023 (5.14.1), tool-stm32duino 1.0.1, tool-openocd 2.1000.190707 (10.0) Collecting mbed sources... LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 14 compatible libraries Scanning dependencies... No dependencies Building in release mode Checking size .pio/build/nucleo_f303k8/firmware.elf Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" DATA: [= ] 13.0% (used 1600 bytes from 12288 bytes) PROGRAM: [==== ] 43.0% (used 28196 bytes from 65536 bytes) Configuring upload protocol... AVAILABLE: blackmagic, jlink, mbed, stlink CURRENT: upload_protocol = mbed Looking for upload disk... Use manually specified: /media/komatsu/NODE_F303K8 Uploading .pio/build/nucleo_f303k8/firmware.bin Firmware has been successfully uploaded. (Some boards may require manual hard reset) ===== [SUCCESS] Took 9.34 seconds ==== Terminal will be reused by tasks, press any key to close it.```

Serial Monitor出力例:

$ platformio device monitor --baud 9600 --- Miniterm on /dev/ttyACM0 9600,8,N,1 --- --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- Hello World ! This program runs since 1 seconds. This program runs since 2 seconds. This program runs since 3 seconds. This program runs since 4 seconds. This program runs since 5 seconds. This program runs since 6 seconds. --- exit ---

MBEDストレージに書き込めない(uploadできない)場合

実際に体験したが、該当のストレージがRead-Onlyになりuploadできなくなったことがある。この場合、該当のMBEDストレージを初期化する。

[参考]mbedのFAQからの抜粋:
・mbedに書き込みができなくなった
・ファイルを消しても空き容量が小さくなってしまっている
・mbed内に消せないファイルがあって困っている

mbedをフォーマットしてしまうことで解決できます

稀にmbedのストレージエリアに書き込みができない/ファイルを消せない問題が起こることがあります.また不可視ファイルが溜まっていって,空き容量が少なくなってしまうこともあります.
このような場合は,mbedをフォーマットしてしまう方法があります.
フォーマットしても「MBED.HTM」は電源の再投入(USBの抜き差しなど)で再び現れます

フォルダ構成

デフォルトの設定では、home/Documents/PlatformIO/Projectsのなかにプロジェクト名のフォルダが生成される。

参考URL

A new generation ecosystem for embedded development
Boards » NUCLEO-F303K8
STM32 Nucleo Board STM32F303K8

以上

続きを読む "Nucleo STM32F303K8 開発ツール"

| | コメント (0)

2020年1月 3日 (金)

NXP LPC1768 mbed開発ツール

2020/1/3

NXP LPC1768 tool (VScode+PlatformIO)

NXP LPC1768 tool (VScode+PlatformIO)

概要

LPC1768ボードの開発ツールとして、VScodeの拡張としてPlatformIOを導入して、そのなかで開発ツール(コンパイラ、リンカ、アップローダー)をインストールする。 ここでは、linux環境でのインストール方法について説明する。

準備

ツールをインストール前に環境整備として以下を設定する:
(1)Python 2.7またはPython 3.5+のインストール

sudo apt-get install python3

(2)udevのruleの設定

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo service udev restart sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER/home/komatsu/Documents/PlatformIO/Projects/LPC1768_mbed_01/src/main.cpp

開発ツールのインストール

上の準備が終わったら、プロセッサとボードの種類は異なるが、インストール方法が分かりやすいので、以下を参考にインストールする。:
https://www.media.lab.uec.ac.jp/?page_id=1414
ESP32をVSCodeとPlatformIO IDEで動かす方法

新しいプロジェクトを作り、その際、今回の場合、Boardとして、
「NXP mbed LPC1768」を選択し、Frameworkとして
「mbed」を選択して Nameに任意の名前を入力して[Finish]をクリックする。
(このNameはプロジェクト名かつフォルダ名になる)

その後、必要なツールのインストールが開始するが、完了後、platform.iniの内容に以下が含まれることを確認する。

[env:lpc1768] platform = nxplpc board = lpc1768 framework = mbed

IDE設定

platformio.iniファイルを以下のように編集する:
upload_portは、自分の環境に合わせて変更すること。

;PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:lpc1768] platform = nxplpc board = lpc1768 framework = mbed upload_port = /media/user/MBED upload_protocol = mbed ;upload_protocol = cmsis-dap

ビルドテストのためのサンプルプログラム

LED点滅サンプル:

#include <mbed.h> //DigitalOut myled(LED1); DigitalOut myled(LED2); //DigitalOut myled(LED3); //DigitalOut myled(LED4); int main() { while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } }

build/upload

(1)ボードとホストPCをUSBケーブルで接続する。
(2)VScode画面の最下行にあるアイコンからBuidのアイコンをクリックしてビルド実行する。
(3)VScode画面の最下行にあるアイコンからUploadのアイコンをクリックしてアップロード(ボードへのプログラム書込)を実行する。
注意:SerialMoniter画面に切り替えている場合、その画面で、Ctrl+Cを押して、事前に閉じる必要がある。
(4)書き込み終了後、ボードの[reset]ボタンを押して書き込んだプログラムを起動する。

build出力ログ例:

> Executing task in folder LPC1768_mbed_01: platformio run < Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/nxplpc/lpc1768.html PLATFORM: NXP LPC 5.0.0 > NXP mbed LPC1768 HARDWARE: LPC1768 96MHz, 64KB RAM, 512KB Flash DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink) PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51401.191023 (5.14.1) Collecting mbed sources... LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 11 compatible libraries Scanning dependencies... No dependencies Building in release mode Checking size .pio/build/lpc1768/firmware.elf Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" DATA: [= ] 5.3% (used 3441 bytes from 65536 bytes) PROGRAM: [= ] 6.5% (used 34148 bytes from 524288 bytes) ===== [SUCCESS] Took 8.68 seconds ===== Terminal will be reused by tasks, press any key to close it.

upload出力ログ例:

> Executing task in folder LPC1768_mbed_01: platformio run --target upload < Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/nxplpc/lpc1768.html PLATFORM: NXP LPC 5.0.0 > NXP mbed LPC1768 HARDWARE: LPC1768 96MHz, 64KB RAM, 512KB Flash DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink) PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51401.191023 (5.14.1) Collecting mbed sources... LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 11 compatible libraries Scanning dependencies... No dependencies Building in release mode Checking size .pio/build/lpc1768/firmware.elf Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" DATA: [= ] 5.3% (used 3441 bytes from 65536 bytes) PROGRAM: [= ] 6.5% (used 34148 bytes from 524288 bytes) Configuring upload protocol... AVAILABLE: blackmagic, cmsis-dap, jlink, mbed CURRENT: upload_protocol = mbed Looking for upload disk... Use manually specified: /media/komatsu/MBED Uploading .pio/build/lpc1768/firmware.bin Firmware has been successfully uploaded. (Some boards may require manual hard reset) ===== [SUCCESS] Took 7.96 seconds ===== Terminal will be reused by tasks, press any key to close it.

MBEDストレージに書き込めない(uploadできない)場合

実際に体験したが、該当のストレージがRead-Onlyになりuploadできなくなったことがある。この場合、該当のMBEDストレージを初期化する。

[参考]mbedのFAQからの抜粋:
・mbedに書き込みができなくなった
・ファイルを消しても空き容量が小さくなってしまっている
・mbed内に消せないファイルがあって困っている

mbedをフォーマットしてしまうことで解決できます

稀にmbedのストレージエリアに書き込みができない/ファイルを消せない問題が起こることがあります.また不可視ファイルが溜まっていって,空き容量が少なくなってしまうこともあります.
このような場合は,mbedをフォーマットしてしまう方法があります.
フォーマットしても「MBED.HTM」は電源の再投入(USBの抜き差しなど)で再び現れます

フォルダ構成

デフォルトの設定では、home/Documents/PlatformIO/Projectsのなかにプロジェクト名のフォルダが生成される。

参考URL

A new generation ecosystem for embedded development
mbed NXP LPC1768評価キット

備考

usbmountはアンインストールしたほうが良いようだ。本件の書き込みにおいて、アクセス権限が強化されたりして不便なことが多い気がする。
uploadの選択肢としてcmsis-dapがあるが、ストレージにファームウェアが書き込むmbedのほうがハードウェア依存性が少ないようで安定して書き込める気がする。

以上

続きを読む "NXP LPC1768 mbed開発ツール"

| | コメント (0)