打印
[ZLG-ARM]

晚上睡不着,玩了一下LPC1000的JTAG/SWD编程

[复制链接]
4428|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 Simon21ic 于 2010-5-27 02:46 编辑

不到4个小时就搞定了,当然,没有做并行优化算法。

5个patch搞定。
最终优化速度以及原理看8楼。

看一下效果,JTAG(560KHz):
H:\MyProject\Versaloon\vsprog\vcproj\Debug>vsprog -slpc1000 -mj -oe -owf -ovf -I ..\..\..\test\LPC1700Test.hex
VSProg 1.0 MSVC:0000
CopyRight(c) 2008-2010 by SimonQian
URL: http://www.SimonQian.com/en/Versaloon
Info:   Versaloon(0x15)by Simon(compiled on May 21 2010)
Info:   Chip name undefined, try auto-detecting.
Info:   JTAG_ID: 0x4BA00477.                             <<<<==== JTAT 接口
Info:   AHB-AP_ID: 0x24770011
Info:   ROM_ADDRESS: 0xE00FF003
Info:   CFG: 0x00000000, Small-endian
Info:   CORTEX-M3 processor detected
Info:   CPUID: 0x412FC230
Info:   Bootloader Version: 4.1
Info:   Serian Number: F50000044AA989275355117D17170D1F
Info:   Chip-id read is 0x26013F33.
Info:   Auto-detect signature is 0x26013F33
Info:   lpc1766 found
Info:   JTAG_ID: 0x4BA00477.
Info:   AHB-AP_ID: 0x24770011
Info:   ROM_ADDRESS: 0xE00FF003
Info:   CFG: 0x00000000, Small-endian
Info:   CORTEX-M3 processor detected
Info:   CPUID: 0x412FC230
Info:   Bootloader Version: 4.1
Info:   Serian Number: F50000044AA989275355117D17170D1F
Info:   Chip-id read is 0x26013F33.
Info:   erasing flash
erasing flash |========================================%100| 0.13s used
Info:   flash erased
Info:   JTAG_ID: 0x4BA00477.
Info:   AHB-AP_ID: 0x24770011
Info:   ROM_ADDRESS: 0xE00FF003
Info:   CFG: 0x00000000, Small-endian
Info:   CORTEX-M3 processor detected
Info:   CPUID: 0x412FC230
Info:   programming flash
writing flash |========================================%100| 5.94s used
Info:   flash programmed for 98304bytes(16.17KB/s)
Info:   verifying flash
reading flash |========================================%100| 3.16s used
Info:   flash verified for 98304bytes(30.42KB/s)

SWD:
H:\MyProject\Versaloon\vsprog\vcproj\Debug>vsprog -slpc1000 -ms -oe -owf -ovf -I ..\..\..\test\LPC1700Test.hex
VSProg 1.0 MSVC:0000
CopyRight(c) 2008-2010 by SimonQian
URL: http://www.SimonQian.com/en/Versaloon
Info:   Versaloon(0x15)by Simon(compiled on May 21 2010)
Info:   Chip name undefined, try auto-detecting.
Info:   SWJ_ID read is 0x2BA01477.                             <<<<==== SWD 接口
Info:   AHB-AP_ID: 0x24770011
Info:   ROM_ADDRESS: 0xE00FF003
Info:   CFG: 0x00000000, Small-endian
Info:   CORTEX-M3 processor detected
Info:   CPUID: 0x412FC230
Info:   Bootloader Version: 4.1
Info:   Serian Number: F50000044AA989275355117D17170D1F
Info:   Chip-id read is 0x26013F33.
Info:   Auto-detect signature is 0x26013F33
Info:   lpc1766 found
Info:   SWJ_ID read is 0x2BA01477.
Info:   AHB-AP_ID: 0x24770011
Info:   ROM_ADDRESS: 0xE00FF003
Info:   CFG: 0x00000000, Small-endian
Info:   CORTEX-M3 processor detected
Info:   CPUID: 0x412FC230
Info:   Bootloader Version: 4.1
Info:   Serian Number: F50000044AA989275355117D17170D1F
Info:   Chip-id read is 0x26013F33.
Info:   erasing flash
erasing flash |========================================%100| 0.13s used
Info:   flash erased
Info:   SWJ_ID read is 0x2BA01477.
Info:   AHB-AP_ID: 0x24770011
Info:   ROM_ADDRESS: 0xE00FF003
Info:   CFG: 0x00000000, Small-endian
Info:   CORTEX-M3 processor detected
Info:   CPUID: 0x412FC230
Info:   programming flash
writing flash |========================================%100| 4.88s used
Info:   flash programmed for 98304bytes(19.69KB/s)
Info:   verifying flash
reading flash |========================================%100| 2.34s used
Info:   flash verified for 98304bytes(40.96KB/s)

有一点觉得不爽,执行IAP一定需要指定CCLK。
好像其他的CM3都不需要吧?
下次哪天睡不着的时候,顺便把LM和AT的CM3都搞定了。。。
评分
参与人数 2威望 +11 收起 理由
hotpower + 10
HotWC3 + 1

相关帖子

沙发
Simon21ic|  楼主 | 2010-5-22 04:53 | 只看该作者
本帖最后由 Simon21ic 于 2010-5-22 05:00 编辑

同样560K速度下,STM32的编程速度(并行算法):
Info:   CPUID: 0x411FC231
Info:   programming flash
writing flash |========================================%100| 1.06s used
Info:   flash programmed for 24064bytes(22.13KB/s)
Info:   verifying flash
reading flash |========================================%100| 0.78s used
Info:   flash verified for 24064bytes(30.09KB/s)

SWD接口:
Info:   CPUID: 0x411FC231
Info:   programming flash
writing flash |========================================%100| 0.80s used
Info:   flash programmed for 24064bytes(29.49KB/s)
Info:   verifying flash
reading flash |========================================%100| 0.58s used
Info:   flash verified for 24064bytes(40.66KB/s)

使用特权

评论回复
评分
参与人数 2威望 +11 收起 理由
hotpower + 10
HotWC3 + 1
板凳
Simon21ic|  楼主 | 2010-5-23 03:10 | 只看该作者
LPC也优化了一下(精简算法+并行处理):
560KHz JTAG:
Info:   Chip-id read is 0x26013F33.
Info:   erasing flash
erasing flash |========================================%100| 0.04s used
Info:   flash erased
Info:   programming flash
writing flash |========================================%100| 3.36s used
Info:   flash programmed for 98304bytes(28.55KB/s)
Info:   verifying flash
reading flash |========================================%100| 3.12s used
Info:   flash verified for 98304bytes(30.77KB/s)

SWD:
Info:   Chip-id read is 0x26013F33.
Info:   erasing flash
erasing flash |========================================%100| 0.04s used
Info:   flash erased
Info:   programming flash
writing flash |========================================%100| 2.29s used
Info:   flash programmed for 98304bytes(41.90KB/s)
Info:   verifying flash
reading flash |========================================%100| 2.33s used
Info:   flash verified for 98304bytes(41.25KB/s)

使用特权

评论回复
地板
Simon21ic|  楼主 | 2010-5-23 03:26 | 只看该作者
有没有其他的JTAG/SWD工具的速度测试PK一下?

使用特权

评论回复
5
god_like| | 2010-5-23 23:11 | 只看该作者
楼主很厉害啊,晚上还这么有激情

使用特权

评论回复
6
hotpower| | 2010-5-24 05:53 | 只看该作者
致敬~~~

使用特权

评论回复
7
xuyiyi| | 2010-5-24 06:21 | 只看该作者
菜农真勤劳,起的真早!

使用特权

评论回复
8
Simon21ic|  楼主 | 2010-5-24 18:26 | 只看该作者
本帖最后由 Simon21ic 于 2010-5-24 18:59 编辑

晚上思路清晰。。。。。。效率高啊。。。。。

最高速度:
Info:   erasing flash
erasing flash |========================================%100| 0.04s used
Info:   flash erased
Info:   programming flash
writing flash |========================================%100| 1.34s used
Info:   flash programmed for 98304bytes(71.64KB/s)
Info:   verifying flash
reading flash |========================================%100| 1.08s used
Info:   flash verified for 98304bytes(88.89KB/s)

优化原理:
一般的下载算法:
LPCARM的Flash下载很简单,只是通过USB接口下载一个FlashLoader和Flash数据到RAM,包括IAP命令和参数,然后,设置相应的寄存器(R0,R1,SP,LR,PC,下载寄存器需要先Halt)并设置中断后运行内核,这个是OpenOCD里用的标准算法,我这里测试可以达到5Kb/s左右的速度(560KHz JTAG)。

优化下载算法:
1. JTAG接口优化,一般使用内部4M RC的时候,最高的JTAG速度是650KHz(CCLK / 6,CortexM3标准)。
优化JTAG的实现方式后,一般可以超过这个限制,我这里测试在4500KHz和9000KHz下都可以正常操作。
优化原理:这个速度限制是由于总线访问的时候的限制,如果JTAG写完数据,在CortexM3总线访问时,加入一些等待时钟,就可以提高速度了。JTAG本省硬件上类似移位寄存器,是可以得到非常高的速度的。
使得可以得到超过70KB/s的Flash下载速度。
2. 乒乓操作(tick-tock)
CortexM3在操作Flash(写,擦除)是,JTAG接口仍旧可以访问SRAM,这样就可以简单实现乒乓操作。
芯片一边写Flash,一边通过JTAG下载下一次的数据。
从前面的数据来看,加入乒乓操作后,速度基本上一下子提升80%。
3. Flash Loader优化
由于一般的算法中,每次都要Halt内核,下载LPC的IAP命令,设置相应的寄存器和中断系统,然后在启动运行。这个过程会占用一些时间。
优化后,每次操作,都不需要Halt内核,不需要设置寄存器,不需要设置中断系统,直接写完LPC的IAP命令就可以了。
FlashLoader只需要在初始化的时候,下载一次即可。
核心FlashLoader:
static uint8_t iap_code[] = {
       // wait_start:
0x15, 0x48,    // ldr  r0, [PC, #XX]  // load sync
0x00, 0x28,    // cmp  r0, #0
0xFC, 0xD0,    // beq   wait_start
0x00, 0x00,
       // init:
0x05, 0x4A,    // ldr  r2, [PC, #XX]  // laod address of iap_entry
0x06, 0x48,    // ldr  r0, [PC, #XX]  // load address of command
0x06, 0x49,    // ldr  r1, [PC, #XX]  // load address of result

0x90, 0x47,    // blx  r2                  // call iap_entry
0x00, 0x00,
0x06, 0x48,    // ldr  r0, [PC, #XX]  // load address of sync
0x4F, 0xF0, 0x00, 0x01, // mov  r1, #0
0x01, 0x60,    // str  r1, [r0, #0]    // clear sync
0xF1, 0xE7,    // b  wait_start
0xFE, 0xE7,    // b  $
0, 0,     // fill
       // parameter
0, 0, 0, 0,    // address of iap_entry
0, 0, 0, 0,    // address of command
0, 0, 0, 0,    // address of result
(LPC1000_IAP_SYNC_ADDR >> 0) & 0xFF, // address of aync
(LPC1000_IAP_SYNC_ADDR >> 8) & 0xFF,
(LPC1000_IAP_SYNC_ADDR >> 16) & 0xFF,
(LPC1000_IAP_SYNC_ADDR >> 24) & 0xFF,
0, 0, 0, 0,    // reserved0
0, 0, 0, 0,    // reserved1
0, 0, 0, 0,    // reserved2
0, 0, 0, 0,    // reserved3

0, 0, 0, 0,    // command
0, 0, 0, 0,    // param[0]
0, 0, 0, 0,    // param[1]
0, 0, 0, 0,    // param[2]
0, 0, 0, 0,    // param[3]
0, 0, 0, 0,    // param[4]

0, 0, 0, 0,    // sync
                   // when write iap command, write command(6 DWORD) + sync(set to 1, 1 DWORD)
                   // when read result, read sync(1DWORD) + result(5 DWORD), sync = 0 means ready

0, 0, 0, 0,    // result
0, 0, 0, 0,    // reply[0]
0, 0, 0, 0,    // reply[1]
0, 0, 0, 0,    // reply[2]
0, 0, 0, 0    // reply[3]
};

使用特权

评论回复
评分
参与人数 2威望 +11 收起 理由
hotpower + 10
HotWC3 + 1
9
hulan1985| | 2010-5-24 21:30 | 只看该作者
致敬!

使用特权

评论回复
10
OLIVERR| | 2010-5-24 22:47 | 只看该作者
楼主,很厉害啊~~~

使用特权

评论回复
11
xiaoxin1986| | 2010-5-25 16:13 | 只看该作者
像楼主学习

使用特权

评论回复
12
没水的壶| | 2010-5-26 12:45 | 只看该作者
楼主很凶猛啊

使用特权

评论回复
13
五谷道场| | 2010-5-26 21:55 | 只看该作者
并行优化后怎样?

使用特权

评论回复
14
mcu123AD| | 2010-6-4 10:03 | 只看该作者
顶顶。。牛人。

使用特权

评论回复
15
Simon21ic|  楼主 | 2010-6-5 22:48 | 只看该作者
LPC1100系列也已经测试通过,可以正常支持。
不过LPC1100系列由于SRAM有限,无法实现乒乓操作.

使用特权

评论回复
16
gainst| | 2010-7-9 11:03 | 只看该作者
ding....

使用特权

评论回复
17
HotWC3| | 2010-7-9 17:04 | 只看该作者
技术交流才是提高自己的硬道理~~~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

266

主题

2597

帖子

104

粉丝