mbed cliの使い方
プロジェクトの作り方
まず、mbed のオフライン環境でプロジェクトを作る。
$ mbed new F446_test
書き込みたいマイコンをつなぎmbed detect
とすると検出される。
$ mbed detect [mbed] Working path "/path/to/F446_test" (program) [mbed] Detected NUCLEO_F446RE, port /dev/ttyACM0, mounted /path/to/NODE_F446RE, interface version 0221: [mbed] Supported toolchains for NUCLEO_F446RE | Target | mbed OS 2 | mbed OS 5 | uARM | IAR | ARM | GCC_ARM | ARMC5 | |---------------|-----------|-----------|-----------|-----------|-----------|-----------|-------| | NUCLEO_F446RE | Supported | Supported | Supported | Supported | Supported | Supported | - | Supported targets: 1 Supported toolchains: 4
その後書き込みたいtarget
とtoolchain
を設定する。
$ cd /path/to/F446_test
$ mbed target NUCLEO_F446RE
$ mbed toolchain GCC_ARM
main.cpp
を作成してコンパイルする。
/*main.cpp*/ #include "mbed.h" Serial pc(USBTX, USBRX); int i =0; int main(){ while(1){ pc.printf("i=%d\n\r", i); i++; wait(1); } }
$ mbed compile
その後書き込む。
$ lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 004: ID 8087:0a2b Intel Corp. Bus 001 Device 003: ID 5986:054c Acer, Inc Bus 001 Device 008: ID 0411:0110 BUFFALO INC. (formerly MelCo., Inc.) Bus 001 Device 006: ID 0483:374b STMicroelectronics ST-LINK/V2.1 Bus 001 Device 002: ID 056e:0107 Elecom Co., Ltd Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub $ df ファイルシス 1K-ブロック 使用 使用可 使用% マウント位置 dev 4026244 0 4026244 0% /dev run 4034656 1372 4033284 1% /run /dev/sda3 116064204 71743696 44320508 62% / tmpfs 4034656 36180 3998476 1% /dev/shm tmpfs 4034656 0 4034656 0% /sys/fs/cgroup tmpfs 4034656 4 4034652 1% /tmp /dev/sda1 523248 65376 457872 13% /boot tmpfs 806928 40 806888 1% /run/user/1000 /dev/sdc1 3979456 914368 3065088 23% /run/media/name/5480-6D35 /dev/sdb 540 8 532 2% /run/media/name/NODE_F446RE $ cp BUILD/NUCLEO_F446RE/GCC_ARM/F446_test.bin /run/media/name/NODE_F446RE/
デバッグ方法
再度コンパイルし、かきこむ
$ mbed compile --profile debug
$ cp BUILD/NUCLEO_F446RE/GCC_ARM-DEBUG/F446_test.bin /run/media/name/NODE_F446RE/
gdb-serverをたてる
$ sudo pyocd-gdbserver
$ arm-none-eabi-gdb BUILD/NUCLEO_F446RE/GCC_ARM-DEBUG/F446_test.elf GNU gdb (GDB) 8.2.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from BUILD/NUCLEO_F446RE/GCC_ARM-DEBUG/F446_test.elf...done. (gdb) target remote :3333 Remote debugging using :3333 warning: while parsing target memory map (at line 3): Required element <memory> is missing hal_sleep () at ./mbed-os/targets/TARGET_STM/sleep.c:142 142 core_util_critical_section_exit(); (gdb) load Loading section .text, size 0x13988 lma 0x8000000 Loading section .ARM.exidx, size 0x8 lma 0x8013988 Loading section .data, size 0xb78 lma 0x8013990 Start address 0x80074d0, load size 83208 Transfer rate: 8 KB/sec, 1891 bytes/write. (gdb) p i $1 = 327 (gdb)