ラベル JTAG の投稿を表示しています。 すべての投稿を表示
ラベル JTAG の投稿を表示しています。 すべての投稿を表示

2010年12月12日日曜日

LPCXpresso LPC1768にJTAGKey2Pを接続してOpenOCDで楽しむ

先の記事ではLPCXpresso LPC1768のデバッガとターゲットを切り離しました。
ターゲットを独立させたのはJTAGKey2Pを接続して使いたいためです。
ここでは実際にLPCXpresso LPC1768にJTAGKey2Pを接続してみました。
OpenOCDはgitリポジトリから2010年12月12日現在のものを取り出して使用しました。
まずはOpenOCDのビルドです。

JTAGKey2Pではlibftd2xxを使用します。
http://www.ftdichip.com/Drivers/D2XX.htm
2010年12月12日現在のバージョンはlibftd2xx1.0.0.tar.gzです。
ダウンロードして展開しておきます。

tar xvfz libftd2xx1.0.0.tar.gz

次にOpenOCDのソースコードです。

git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
cd openocd
./bootstrap
./configure --enable-ft2232_libftdi --with-ftd2xx-linux-tardir=/path/to/libftd2xx1.0.0
make

ビルドにはautomakeも必要です。
予めビルド環境に入れておいてください。

ビルドできたらmake installして出来上がりです。

ここで試しにsuikanさんがポーティングされたTOPPSER/ASP for LPCのバイナリをOpenOCD経由でフラッシュに書き込んでみましょう。
まずはOpenOCDを起動します。

その前に・・・OpenOCDの設定ファイルを確認します。

openocd.cfgは以下のようにしました。

source [find /usr/local/share/openocd/tcl/interface/jtagkey2p.cfg]
source [find /usr/local/share/openocd/tcl/target/lpc1768.cfg]

jtagkey2p.cfgはgitリポジトリに入っている物と同じです。
lpc1768.cfgについてはSWDを使う設定になっていました。
これについては以下のように修正して使用しました。

# NXP LPC1768 Cortex-M3 with 512kB Flash and 32kB+32kB Local On-Chip SRAM,
# # LPC17xx chips support both JTAG and SWD transports.
# # Adapt based on what transport is active.
# source [find target/swj-dp.tcl]
if { [info exists CHIPNAME] } {
    set _CHIPNAME $CHIPNAME
} else {
    set _CHIPNAME lpc1768
}
# After reset the chip is clocked by the ~4MHz internal RC oscillator.
# When board-specific code (reset-init handler or device firmware)
# configures another oscillator and/or PLL0, set CCLK to match; if
# you don't, then flash erase and write operations may misbehave.
# (The ROM code doing those updates cares about core clock speed...)
#
# CCLK is the core clock frequency in KHz
if { [info exists CCLK ] } {
    set _CCLK $CCLK
} else {
    set _CCLK 4000
}
if { [info exists CPUTAPID ] } {
    set _CPUTAPID $CPUTAPID
} else {
    set _CPUTAPID 0x4ba00477
}
#delays on reset lines
adapter_nsrst_delay 200
jtag_ntrst_delay 200
# LPC2000 & LPC1700 -> SRST causes TRST
reset_config srst_pulls_trst
jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
#swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m3 -chain-position $_TARGETNAME
# LPC1768 has 32kB of SRAM In the ARMv7-M "Code" area (at 0x10000000)
# and 32K more on AHB, in the ARMv7-M "SRAM" area, (at 0x2007c000).
$_TARGETNAME configure -work-area-phys 0x10000000 -work-area-size 0x8000
# LPC1768 has 512kB of flash memory, managed by ROM code (including a
# boot loader which verifies the flash exception table's checksum).
# flash bank (name) lpc2000 (base) (size) 0 0 (target#) (variant) (clock) [calc checksum]
set _FLASHNAME $_CHIPNAME.flash
# flash bank $_FLASHNAME lpc2000 0x0 0x80000 0 0 $_TARGETNAME lpc1700 $_CCLK calc_checksum
flash bank $_FLASHNAME lpc2000 0x0 0x80000 0 0 $_TARGETNAME lpc1700 120000
# Run with *real slow* clock by default since the
# boot rom could have been playing with the PLL, so
# we have no idea what clock the target is running at.
jtag_khz 500
$_TARGETNAME configure -event reset-init {
    # Do not remap 0x0000-0x0020 to anything but the flash (i.e. select
    # "User Flash Mode" where interrupt vectors are _not_ remapped,
    # and reside in flash instead).
    #
    # See Table 612. Memory Mapping Control register (MEMMAP - 0x400F C040) bit description
    # Bit Symbol Value Description Reset
    # value
    # 0 MAP Memory map control. 0
    # 0 Boot mode. A portion of the Boot ROM is mapped to address 0.
    # 1 User mode. The on-chip Flash memory is mapped to address 0.
    # 31:1 - Reserved. The value read from a reserved bit is not defined. NA
    #
    # http://ics.nxp.com/support/documents/microcontrollers/?scope=LPC1768&type=user
    mww 0x400FC040 0x01
}
init
reset init

次にOpenOCDを起動します。

shinta@greenpad:~/Projects/ledblink_lpcxpresso_1768$ sudo openocd 
[sudo] password for shinta: 
Open On-Chip Debugger 0.5.0-dev-00651-gc6e0705 (2010年12月11日-21:58)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.berlios.de/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
adapter_nsrst_delay: 200
jtag_ntrst_delay: 200
none srst_pulls_trst
500 kHz
Info : max TCK change to: 30000 kHz
Info : clock speed 500 kHz
Info : JTAG tap: lpc1768.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Info : lpc1768.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : JTAG tap: lpc1768.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Warn : Only resetting the Cortex-M3 core, use a reset-init event handler to reset any peripherals


無事に起動したらtelnet localhost 4444でOpenOCDと接続します。
halt, flash probe 0, flash write_image erase (バイナリファイル名), resetでLPCXpresso LPC1768上にあるLEDがチカチカする事を確認してみましょう。

shinta@greenpad:~$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
> flash probe 0
flash 'lpc2000' found at 0x00000000
> flash write_image erase /home/shinta/Projects/ledblink_lpcxpresso_1768/asp.bin
auto erase enabled
wrote 32768 bytes from file /home/shinta/Projects/ledblink_lpcxpresso_1768/asp.bin in 5.705619s (5.609 KiB/s)
> reset
JTAG tap: lpc1768.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Only resetting the Cortex-M3 core, use a reset-init event handler to reset any peripherals

OpenOCD側の端末ではクライアントから受けたコマンドの動作が記されていると思います。

target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Info : accepting 'telnet' connection from 4444
flash 'lpc2000' found at 0x00000000
auto erase enabled
wrote 32768 bytes from file /home/shinta/Projects/ledblink_lpcxpresso_1768/asp.bin in 5.705619s (5.609 KiB/s)
Info : JTAG tap: lpc1768.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Warn : Only resetting the Cortex-M3 core, use a reset-init event handler to reset any peripherals

この文書ではLPCXpresso LPC1768をJTAGKey2Pで使用するための狭い範囲のドキュメントとして作成しました。
TOPPERS/ASP for LPCに関するドキュメントはsuikanさんがお書きになった以下のドキュメントも参照してください。

2010年7月20日火曜日

OpenOCDのバグ(レポートとその対応について)

先日STM32の開発環境をUbuntu上に構築する過程で、OpenOCD開発版のバグを2つほど見つけました。OpenOCDのTracにレポートを出しておきましたが、先ほど2つ目のバグも修正されたようです。
  1. gcc 4.4.xでのビルドのために
  2. Amontec JTAGkey2のインターフェースコンフィギュレーションファイルの誤り
1はgcc 4.4.xでビルドが通らないバグ。別のヘッダファイルで定義したものを使うように修正されています。レポートを出した次の日にさっさと直されていたので「だったらお前が直せよ。」ということでしょうか。
2はJTAGkey2Pのコンフィギュレーションが存在しないというもの。「2P版用の新しいコンフィギュレーションファイルinterface/jtagkey2p.cfg」が追加されました。Amontecのラインナップを見ると確かにこちらの対応のほうが良いでしょう。ちょっと名前が紛らわしいのですが。


JTAGkeyは亜種が各種出回っていますし、純正を使っている方は少ないようです。
こういったコンフィギュレーションファイルは、アプリケーションの導入時に重要な役割を果たします。
ある特定の製品の名を名乗る限り、純正品で正しく動作するのが大前提です。
今回のレポートはそういう意味で出しておいて良かったです。
今後世界中の人が自分のコンフィギュレーションファイルを記述しなくて済みますから。
今回レポートした2つのバグ?はいずれも些細な事ですが、「使ってみよう」と思うけど「動かなかったら諦める」 という人にとっては致命的です。特にツールの導入時点でのこの手の障壁は何をやっているのかわからなくなります。今後も是非積極的にプロジェクトに寄与したいところです。

Linux上でJTAGkey2Pを使おうと思ってうまく動作しなかった経験のある方は、最新版をgitリポジトリからダウンロードして再度お試し頂ければと思います。

2010年7月16日金曜日

STM32/Cortex-M3 HOWTO: Development under Ubuntu.

STM32/Cortex-M3の開発環境は有償無償を問わず様々な環境を用意可能です。

最近の国内雑誌はベンダーと手を組んで有償のツールを紹介するような内容が多く見られます。
それはそれで良いのですが、妙な制限が付いていたり、なんだか気持ちの悪いツールを使うように説明してあったりで、手放しに喜んで使う気にはなれないのが現状です。

そこで今回は STM32/Cortex-M3 HOWTO: Development under Ubuntu. を参考にUbuntu 10.04上で環境を構築してみました。


何かの参考になればということで、環境構築用のスクリプトとOpenOCDの設定ファイル、それにLEDチカチカプログラムをまとめてファイルにして置いておきます。
  • JTAGライタにはJTAGKey2を使っています。
  • OpenOCDはgitからソースコードをとってきてコンパイルして使いました。
    • Open On-Chip Debugger 0.5.0-dev-00403-ge8445c9-dirty (2010年07月11日-13:51)
  • DFUは気持ち悪くて使わないので思いっきり上書きしています。
  • LEDチカチカプログラムはSTM32F103VHB6_RevZ_Demo1を使っています。
ダウンロードはこちらから(Download from here)

ほぼ備忘録ですが、これからちょくちょく環境整備についてもまとめていこうと思います。

オープンソースの場合、バージョンによって大きく動作が変わったり、それに伴って情報が断片的になったりします。こういった時、断片的な情報を集めて整理することで問題を突き止める事ができる場合があります。ダウンロード用のファイルもそういった用途のために設置してあります。完全な動作を保証するためのものではありませんのでご了承ください。

2010年7月12日月曜日

Accessing to a STM32 MPU with OpenOCD and JTAGkey2

I tried to run OpenOCD with my JTAGkey2.
  • Getting and Extracting the libftd2xx
    • http://www.ftdichip.com/Drivers/D2XX.htm
    • tar xvfz libftd2xx0.4.16.tar.gz
  • Getting the OpenOCD latest source codes.
    • git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
  • ./bootstrap
  • Configuring the option
    • ./configure --enable-ft2232_libftdi --with-ftd2xx-linux-tardir=/path/to/libftd2xx0.4.16
  • Building...
    • make
  • Editing a interface configuration file.
    • -ft2232_device_desc "Amontec JTAGkey-2"
    • +ft2232_device_desc "Amontec JTAGkey-2P A"
  • Running...
shinta@ubuntu:~/Projects/openocd/openocd/src$ ./openocd -f interface/jtagkey2.cfg -f target/stm32.cfg
Open On-Chip Debugger 0.5.0-dev-00403-ge8445c9-dirty (2010年07月11日-13:51)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.berlios.de/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
Info : max TCK change to: 30000 kHz
Info : clock speed 1000 kHz
Info : JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
Info : JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
Info : stm32.cpu: hardware has 6 breakpoints, 4 watchpoints

    2010年7月9日金曜日

    Amontec JTAGkey-2P

    随分前に購入したAmontec社のJTAGkey-2P。
    今日になってやっと動作確認しました。

    昨日ドライバを導入して動かずに困って問い合わせたところ。
    「今ウェブサイトをアップデートしています。ちょっとアップデートを間違ってたみたい。」
    ということで間違った方のドライバをインストールしていたみたいです。
    Amontec JTAGkey (Channel A)
    2009年11月10日
    2.6.0.0
    正しいのはこっちだと送っていただいたリンク先にあるドライバで更新したところAmontec JTAGkey Demo 060307で認識しました。
    http://www.amontec.com/download/amontec-jtagkey-driver-d2xx-20091124.zip


    ちなみに動かなかったバージョンは
    JTAGkey ( Channel A )
    2005年12月01日
    3.1.2.0
    です。

    AltStyle によって変換されたページ (->オリジナル) /