はじめに
前回はPlatformIOでLチカの実行までしたので、デバッグ方法調べる。
pio debug
特にplatform.iniを書き換えたりする必要もなく次のコマンドでデバッグを開始できる。
$ pio debug --interface=gdb Warning! Please install `99-platformio-udev.rules`. Mode details: https://docs.platformio.org/en/latest/faq.html#platformio-udev-rules SEGGER J-Link GDB Server V6.52 Command Line Version JLinkARM.dll V6.52 (DLL compiled Sep 27 2019 17:53:31) Command line: -singlerun -if JTAG -select USB -speed 1000 -jtagconf -1,-1 -device FE310 -port 2331 -----GDB Server start settings----- GDBInit file: none GDB Server Listening port: 2331 SWO raw output listening port: 2332 Terminal I/O port: 2333 Accept remote connection: yes Generate logfile: off Verify download: off Init regs on start: off Silent mode: off Single run mode: on Target connection timeout: 0 ms ------J-Link related settings------ J-Link Host interface: USB J-Link script: none J-Link settings file: none ------Target related settings------ Target device: FE310 Target interface: JTAG Target interface speed: 1000kHz Target endian: little Connecting to J-Link... Reading symbols from /home/mickey/work/pio/hifive1_revb/.pio/build/hifive1-revb/firmware.elf... (gdb) J-Link is connected. Firmware: J-Link OB-K22-SiFive compiled Aug 22 2019 14:12:56 Hardware: V1.00 S/N: 979001361 Checking target voltage... Target voltage: 3.30 V Listening on TCP/IP port 2331 Connecting to target... J-Link found 1 JTAG device, Total IRLen = 5 JTAG ID: 0x20000913 (RISC-V) Connected to target Waiting for GDB connection...
ここまで表示されたあと、Enterを押すとgdbのプロンプトが表示される。
次のコマンドでターゲットに接続すればデバッグが可能になる。
(gdb) target remote :2331 (gdb) mon reset (gdb) load
たとえば、前回のプログラムであれば次のような感じ。
(gdb) l 18 put32(GPIO_OUTPUT_EN, LED_RGB); 19 put32(GPIO_OUT_XOR, LED_RGB); 20 put32(GPIO_PORT, LED_RGB); 21 22 while (1) { 23 put32(GPIO_PORT, LED_RGB); 24 for (rx = 0; rx < 2000000; rx++) dummy(rx); 25 put32(GPIO_PORT, 0); 26 for (rx = 0; rx < 2000000; rx++) dummy(rx); 27 }
ブレークポイントを貼る。
(gdb) b 23
実行状態にする。
(gdb) c
main.cの23行目の部分でブレークすればOK。
99-platformio-udev.rulesの警告
実行時に下記の警告が表示されることがあるが、問題なくターゲットと接続できている場合は無視して良い。
Warning! Please install `99-platformio-udev.rules`. Mode details: https://docs.platformio.org/en/latest/faq.html#platformio-udev-rules
ターゲットとうまく接続できない場合はudevのルールをインストールすると良い。 詳細はメッセージにあるURLに書いてあるとおり。
$ 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
まとめ
PlatformIOではデバッグが簡単に開始できる。