2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pyOCDによるarm Flash ROMの書き込み

Last updated at Posted at 2022-04-18

はじめに

この記事はarm CPU core を組み込んだ SoC (System On Chip)のちSWDコネクタを持つボードのプログラムを開発するとき、Flash ROMの書き込み/消去/読出し/デバッグを行う方法を記します。
方法としては、様々な方法がありました。
ここではpyOCDというPython packageを用いCMSIS-DAP仕様のDebuggerをSWDワイヤで接続して書き込む方法を書きます。

Debuggerの用意

DSC_0005.JPG
写真は(株)日昇テクノロジーが販売しているMulutiTOOL3 (以下iTOOL3) Debuggerです。SWD用に2個の異なる形状のコネクタがありますがここでは5Pを使いました。
arm SWDは様々な機械仕様のコネクタが使われていますが、電気仕様は同一ですのでアダプタを作ってTarget bouardに接続します。
DSC_0023.JPG
5P接続は電源が供給されないので別途接続します。今回はUSBから取りました。

ソフトウエアの準備

Windows 11のPower ShellにPython3を導入します。
https://www.python.jp/install/windows/install.html

pyOCDをinstallします

 pip install pyocd

使用するarm SoCの仕様をDFP (Device Family Pack) databaseからDLします。
取得した *.pack をダブルクリックすると解凍するか尋ねるのでその通りにします。
pyOCDに取得したSoCの仕様を取り込みます。
まず、サポートされているSoCを検索します。

PS C:\Users\mac> pyocd pack find s6e2gm
  Part       Vendor    Pack           Version   Installed
-----------------------------------------------------------
  S6E2GM6H   Cypress   Keil.FM4_DFP   1.6.0     True
  S6E2GM6J   Cypress   Keil.FM4_DFP   1.6.0     True
  S6E2GM8H   Cypress   Keil.FM4_DFP   1.6.0     True
  S6E2GM8J   Cypress   Keil.FM4_DFP   1.6.0     True

もし、見つからなければ前の手順のDFP組み込みに失敗してますので、やり直します。
DFPを組み込みます。

PS C:\Users\mac> pyocd pack install s6e2gm
Downloading packs (press Control-C to cancel):
    Keil.FM4_DFP.1.6.0
Downloading descriptors (001/001)

試しに消去してみます。

PS C:\Users\mac> pyocd erase --chip
  #   Probe                       Unique ID
--------------------------------------------------------------------
  0   Cypress Cypress CMSIS-DAP   RND-8540413381570778512647434064
  1   GINGKO GINGKO-CMSIS-DAP     888888888888

Enter the number of the debug probe or 'q' to quit> 0
0010944 W Generic 'cortex_m' target type is selected by default; is this intentional? You will be able to debug most devices, but not program  flash. To set the target type use the '--target' argument or 'target_override' option. Use 'pyocd list --targets' to see available targets types. [board]
0011088 I Erasing chip... [eraser]
0011088 I Done [eraser]

別のDebuggerを繋ぐ

同じ日昇テクノロジーのOpenLinkもやってみました。
img132.jpg
最初からやるなら全く同じ手順です。先にiTOOL3を繋いだなら、OpenLink用のアダプタを作って接続するだけです。ハードウエアの違いはpyOCDに吸収されPCを操作している限り見えません。優秀な抽象化レイヤーです。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?