搜索
bottom↓
回复: 7

[请教] 再回 linux - gcc - openocd - jlink - stm32 | 关于openocd下载目标代码时H

[复制链接]

出0入0汤圆

发表于 2011-6-18 15:23:46 | 显示全部楼层 |阅读模式
开发环境: Fedora 15
交叉编译工具链: arm-none-eabi-gcc (Sourcery G++ Lite 2011.03-42) 4.5.2
仿真器: JLink  v7
开发工具: openocd 0.4.0

用的libmaple的库,范例代码main.cpp,网站:leaflabs.com
本来问题是发到他们论坛上的,暂时也没有人回,就直接粘过来了,莫太见怪额 :P



Hi, I am attracted by the architecture of libmaple, so planning to try it on my board (stm32f103rbt6). However, it comes up with a Handler HardFault while downloading use openocd.
Here is my steps:
--------------------------------------------------
$ git clone git://github.com/leaflabs/libmaple.git
$ cd libmaple
$ cp main.cpp.example main.cpp
$ make flash
--------------------------------------------------

Because I am using jlink, then I modified support/openocd/flash_0.4.cfg as:
$ git diff
diff --git a/support/openocd/flash_0.4.cfg b/support/openocd/flash_0.4.cfg
index 32c06c6..d99c48c 100644
--- a/support/openocd/flash_0.4.cfg
+++ b/support/openocd/flash_0.4.cfg
@@ -1,9 +1,10 @@
# script for stm32

-interface ft2232
-ft2232_device_desc "Olimex OpenOCD JTAG"
-ft2232_layout olimex-jtag
-ft2232_vid_pid 0x15ba 0x0003
+interface jlink
+#interface ft2232
+#ft2232_device_desc "Olimex OpenOCD JTAG"
+#ft2232_layout olimex-jtag
+#ft2232_vid_pid 0x15ba 0x0003

After that, do
$ openocd -f support/openocd/flash_0.4.cfg

Results below is printed
------------------------
Open On-Chip Debugger 0.4.0 (2011-02-09-04:28)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.berlios.de/doc/doxygen/bugs.html
1000 kHz
jtag_nsrst_delay: 100
jtag_ntrst_delay: 100
srst_only separate srst_gates_jtag srst_open_drain
Info : J-Link initialization started / target CPU reset initiated
Info : J-Link ARM V7 compiled Jun 30 2009 11:05:27
Info : JLink caps 0xb9ff7bbf
Info : JLink hw version 70000
Info : JLink max mem block 9152
Info : Vref = 3.377 TCK = 1 TDI = 0 TDO = 1 TMS = 0 SRST = 0 TRST = 0

Info : J-Link JTAG Interface ready
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
Warn : stm32.cpu -- clearing lockup after double fault
Halting...
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)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08007844 msp: 0x20005000
Unlocking flash...
Info : device id = 0x20036410
Info : flash size = 128kbytes
cleared protection for sectors 0 through 127 on flash bank 0
Erasing...
erased address 0x08000000 (length 131072) in 0.040999s (3122.027 kb/s)
Flashing image...
wrote 13136 bytes from file build/maple.bin to flash bank 0 at offset 0x00000000 in 0.924966s (13.869 kb/s)
Verifying image...
verified 13136 bytes in 0.529968s (24.205 kb/s)
Checksum verified, resetting chip
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)
Warn : stm32.cpu -- clearing lockup after double fault
target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x01000003 pc: 0x08007064 msp: 0x20004fe0
Daemon shutdown
shutdown command invoked
------------------------

So, I don't know what on earth resulted in this. Something wrong about using openocd? Or linkerscripts? Need maple-bootloader? Any ideas?

Thanks a lot.
Support your excellent works as before. :P


I tried to download flash step by step with openocd:

========================================================================
> init
> targets
TargetName Type Endian TapName State
-- ------------------ ---------- ------ ------------------ ------------
0* stm32.cpu cortex_m3 little stm32.cpu running
> reset halt
JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080000d4 msp: 0x20000100
> flash erase_address 0x08000000 0x20000
erased address 0x08000000 (length 131072) in 0.038003s (3368.155 kb/s)
> flash write_image maple.bin 0x08000000 bin
not enough working area available(requested 16384, free 16336)
wrote 13136 bytes from file maple.bin in 1.157949s (11.078 kb/s)
> verify_image maple.bin 0x08000000 bin
verified 13136 bytes in 0.528980s (24.251 kb/s)
> reset halt
JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08007844 msp: 0x20005000
> resume
stm32.cpu -- clearing lockup after double fault
target state: halted
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x01000003 pc: 0x08007064 msp: 0x20004fe0
>

------------------------------------------------------------------------

in maple.map:

.text 0x08007060 0x60 build/./libmaple/exc.o
0x08007060 __exc_nmi
0x08007064 __exc_hardfault
0x08007068 __exc_memmanage
0x0800706c __exc_busfault
0x08007070 __exc_usagefault

...

.text 0x08007844 0x10 ./support/ld/libcs3_stm32_med_density.a(start.o)
0x08007844 _start
.text 0x08007854 0x108 ./support/ld/libcs3_stm32_med_density.a(start_c.o)
0x08007854 __cs3_start_c
========================================================================

According to above information, I find that after "flash write_image" & "verify_image", "reset halt", the "pc: 0x08007844" is no problem, exactly the "_start" entry point.
But just after that I try "resume" or "reset run", it went into HardFault straight forward.

????

--------------
原帖链接:
http://forums.leaflabs.com/topic.php?id=872&replies=2#post-5337

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2011-6-18 15:40:09 | 显示全部楼层
把源码包发上来..
已经编译通过的ourdev_649998SIPYFL.zip(文件大小:5.35M) (原文件名:libmaple.zip)

出0入0汤圆

 楼主| 发表于 2011-6-18 15:44:44 | 显示全部楼层
咦~?我选的stm32啊,怎么跑雕刻机电去了

辛苦老斑了,帮移一下 嘿嘿

出0入0汤圆

 楼主| 发表于 2011-6-18 16:32:49 | 显示全部楼层
再补充一下,下载完程序之后,reset halt,然后step单步也会跑到Handler HardFault

还是不清楚是怎么回事,和原源码包唯一的区别就是之前在openocd的配置里interface是ftdi,我改成了jlink

出0入0汤圆

 楼主| 发表于 2011-6-18 21:32:25 | 显示全部楼层
解决了,是linker script的原因

应该用make jtag 而不是make flash

“jtag”这个标签用到的linker script才指定的0x08000000这个地址

否则Handler HardFault就是因为访问到了不是放代码的地方

出0入134汤圆

发表于 2011-6-18 23:35:26 | 显示全部楼层
为什么我的arm-none-eabi-gcc  +  Eclipse  代码编译,但编译的代码不能用啊

出0入0汤圆

 楼主| 发表于 2011-6-19 14:01:35 | 显示全部楼层
回复【5楼】elecfun  熊
为什么我的arm-none-eabi-gcc  +  eclipse  代码编译,但编译的代码不能用啊
-----------------------------------------------------------------------

“不能用”具体指什么呢? 是编译通过了之后写不进去还是写进去运行不了?还是别的什么问题?

可以单步调试,能看到每一步pc指针的位置,再对照反汇编出来的代码就能知道是哪种类型的异常,我猜多半最后会是HardFault

没猜错的话,估计还是链接脚本的原因,程序没有在放代码的地方运行

出0入0汤圆

 楼主| 发表于 2011-6-19 14:02:57 | 显示全部楼层
回复【楼主位】librae8226  
-----------------------------------------------------------------------

顺便再贴上leaflabs管理员对原帖的回复:

glad you solved your problem. Make JTAG will treat your code as totally first class and link it against the base address of 0x00,
which means whatever goes into a make jtag binary gets located in memory right at 0x0.
Whereas with make ram and make flash your binary will be offset by some amount, to leave room for the bootloader.
The bootloader is then responsible for jumping out to this offset.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-20 17:58

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表