一般的なトラブルシューティング
OpenOCD の問題
OpenOCD に接続できない - “Error: open failed”
症状
デバイスとの新しい接続を確立しようとすると、次のようなエラーが表示されます:
$ openocd -f (..)
(..)
Error: open failed
in procedure 'init'
in procedure 'ocd_bouncer'
原因
デバイスが接続されていない(または正しく接続されていない)か、正しい ST-LINK インターフェース設定が使われていません。
対処方法
Linux:
lsusbを使って USB 接続を確認してください。- デバイスを開くための権限が不足している可能性があります。
sudoを付けて再試行してください。 それで動作する場合は、root 権限なしで OpenOCD を動かすために these instructions を利用できます。 - ST-LINK に対して誤ったインターフェース設定を使っている可能性があります。
interface/stlink-v2-1.cfgの代わりにinterface/stlink-v2.cfgを試してください。
Windows:
- ST-LINK USB ドライバーが不足している可能性があります。インストール手順は here を参照してください。
OpenOCD に接続できない - “Polling again in X00ms”
症状
デバイスとの新しい接続を確立しようとすると、次のようなエラーが表示されます:
$ openocd -f (..)
(..)
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
Info : Previous state query failed, trying to reconnect
原因
マイクロコントローラーが何らかのタイトな無限ループに陥っているか、継続的に例外を発生させている可能性があります。たとえば、例外ハンドラー自体が例外を発生させている場合です。
対処方法
- OpenOCD が実行中であれば終了する
- リセット(黒い)ボタンを押したままにする
- OpenOCD コマンドを実行する
- その後、リセットボタンを離す
OpenOCD の接続が切れた - “Polling again in X00ms”
症状
実行中の OpenOCD セッションで、突然次のようなエラーが発生します:
# openocd -f (..)
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
Info : Previous state query failed, trying to reconnect
原因
USB 接続が切断されました。
対処方法
- OpenOCD を終了する
- USB ケーブルを抜いて、再度接続する。
- OpenOCD を再起動する
デバイスに書き込めない - “Ignoring packet error, continuing…”
症状
デバイスへの書き込み中に、次のように表示されます:
$ arm-none-eabi-gdb $file
Start address 0x8000194, load size 31588
Transfer rate: 22 KB/sec, 5264 bytes/write.
Ignoring packet error, continuing...
Ignoring packet error, continuing...
原因
ITM に「出力」しているプログラムの実行中に itmdump を閉じました。この場合、現在の GDB セッションは ITM 出力がないことを除けば通常どおり動作しているように見えますが、次の GDB セッションでは前のセクションに示したメッセージでエラーになります。
または、monitor tpiu を発行した後に itmdump を呼び出したため、OpenOCD が書き込んでいたファイル / 名前付きパイプを itmdump が削除してしまいました。
対処方法
- GDB、OpenOCD、
itmdumpを終了/強制終了する itmdumpが使用していたファイル / 名前付きパイプを削除する(たとえば、itm.txt)。- OpenOCD を起動する
- 次に、
itmdumpを起動する - 次に、
monitor tpiuコマンドを実行する GDB セッションを開始する。
OpenOCD に接続できない - “Error: couldn’t bind [telnet] to socket: Address already in use”
症状
デバイスとの新しい接続を確立しようとすると、次のようなエラーが表示されます:
$ openocd -f (..)
(..)
Error: couldn't bind telnet to socket: Address already in use
原因
OpenOCD がアクセスを必要とするポート 3333、4444、6666 のうち 1 つ以上が、別のプロセスによって使用されています。これらの各ポートにはそれぞれ別の用途があり、3333 は gdb、4444 は telnet、6666 は TCL へのリモートプロシージャコール(RPC)コマンドに使われます。
対処方法
この問題を解決するには 2 つの方法があります。A) それらのポートを使用しているプロセスを停止する。B) OpenOCD が使用する空いている別のポートを指定する。
解決方法 A
Mac:
sudo lsof -PiTCP -sTCP:LISTENを実行して、ポートを使用しているプロセスの一覧を取得する- 重要なポートを塞いでいるプロセスの pid を確認し、それぞれについて
kill [pid]を実行して停止する。(そのプロセスがマシン上で重要な処理を実行していないことを確認できる場合に限ります!)
解決方法 B
All:
- OpenOCD の起動時に設定詳細を渡して、各プロセスのいずれかについてデフォルトとは異なるポートを使うようにする。
- たとえば、telnet 機能をデフォルトの 4444 ではなく 4441 で使うには、
openocd -f interface/stlink-v2-1.cfg -f target/stm32f3x.cfg -c "telnet_port 4441"を実行します - OpenOCD の Configuration Stage の詳細は、公式オンラインドキュメントの official docs online を参照してください。
Cargo の問題
“can’t find crate for core”
症状
Compiling volatile-register v0.1.2
Compiling rlibc v1.0.0
Compiling r0 v0.1.0
error[E0463]: can't find crate for `core`
error: aborting due to previous error
error[E0463]: can't find crate for `core`
error: aborting due to previous error
error[E0463]: can't find crate for `core`
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Build failed, waiting for other jobs to finish...
error: Could not compile `r0`.
To learn more, run the command again with --verbose.
原因
nightly-2018-04-08 より古いツールチェーンを使っており、rustup target add thumbv7em-none-eabihf の実行を忘れています。
対処方法
nightly を更新し、thumbv7em-none-eabihf ターゲットをインストールしてください。
$ rustup update nightly
$ rustup target add thumbv7em-none-eabihf