本帖最后由 junsi 于 2011-9-7 16:48 编辑
以前正常的程序,突然出现重启问题,编译器才换了V4.21,最后跟踪在以下函数出问题:void BlockTransStart(u16 count,u32 ms)
{
WaitTransOver();//等待usb发送不忙
TrBuf[0] = 11;
TrBuf[1] = TYPE_ORDER;
TrBuf[2] = TYPE_ORDER_STARTBULK;
*((u32 *)(&TrBuf[3])) = (u32)count;
*((u32 *)(&TrBuf[7])) = ms;
BlockTrans(11);
} 程序在红色处重启,汇编码如下:
67: void BlockTransStart(u16 count,u32 ms)
0x08008C62 2140 MOVS r1,#0x40
0x08008C64 48D6 LDR r0,[pc,#856] ; @0x08008FC0
0x08008C66 F7FFBF5F B.W Trans (0x08008B28)
68: {
0x08008C6A B570 PUSH {r4-r6,lr}
0x08008C6C 4604 MOV r4,r0
0x08008C6E 460D MOV r5,r1
69: WaitTransOver();//等待usb发送不忙
0x08008C70 F7FFFF4C BL.W WaitTransOver (0x08008B0C)
70: TrBuf[0] = 11;
0x08008C74 4AD2 LDR r2,[pc,#840] ; @0x08008FC0
0x08008C76 200B MOVS r0,#0x0B
71: TrBuf[1] = TYPE_ORDER;
0x08008C78 2320 MOVS r3,#0x20
0x08008C7A 7010 STRB r0,[r2,#0x00]
0x08008C7C 7053 STRB r3,[r2,#0x01]
72: TrBuf[2] = TYPE_ORDER_STARTBULK;
73: *((u32 *)(&TrBuf[3])) = (u32)count;
74: *((u32 *)(&TrBuf[7])) = ms;
0x08008C7E 7093 STRB r3,[r2,#0x02]
0x08008C80 1CD2 ADDS r2,r2,#3
0x08008C82 C230 STM r2!,{r4-r5}
75: BlockTrans(11);
76: }
把程序改为:
void BlockTransStart(u16 count,u32 ms)
{
WaitTransOver();//等待usb发送不忙
TrBuf[0] = 11;
TrBuf[1] = TYPE_ORDER;
*((u32 *)(&TrBuf[3])) = (u32)count;
TrBuf[2] = TYPE_ORDER_STARTBULK;
*((u32 *)(&TrBuf[7])) = ms;
BlockTrans(11);
} 编译后问题才得以解决,汇编码如下:
67: void BlockTransStart(u16 count,u32 ms)
0x08008C62 2140 MOVS r1,#0x40
0x08008C64 48D7 LDR r0,[pc,#860] ; @0x08008FC4
0x08008C66 F7FFBF5F B.W Trans (0x08008B28)
68: {
0x08008C6A B570 PUSH {r4-r6,lr}
0x08008C6C 4604 MOV r4,r0
0x08008C6E 460D MOV r5,r1
69: WaitTransOver();//等待usb发送不忙
0x08008C70 F7FFFF4C BL.W WaitTransOver (0x08008B0C)
70: TrBuf[0] = 11;
0x08008C74 4AD3 LDR r2,[pc,#844] ; @0x08008FC4
0x08008C76 200B MOVS r0,#0x0B
71: TrBuf[1] = TYPE_ORDER;
0x08008C78 2320 MOVS r3,#0x20
0x08008C7A 7010 STRB r0,[r2,#0x00]
0x08008C7C 7053 STRB r3,[r2,#0x01]
72: *((u32 *)(&TrBuf[3])) = (u32)count;
0x08008C7E F8C24003 STR r4,[r2,#0x03]
73: TrBuf[2] = TYPE_ORDER_STARTBULK;
0x08008C82 7093 STRB r3,[r2,#0x02]
74: *((u32 *)(&TrBuf[7])) = ms;
0x08008C84 F8C25007 STR r5,[r2,#0x07]
75: BlockTrans(11);
76: }
我不懂汇编,请高手看看是否是编译器的问题?如何避免类似的问题出现? 对了程序中 Trbuf 为全局变量 u8 Trbuf[64]; 我也改成vu8 Trbuf[64] 但问题依旧.
编译优化等级:default;Use Cross-Module Optimization;Use MicroLIB |
|