高级会员

- 积分
- 541
- 金钱
- 541
- 注册时间
- 2011-7-23
- 在线时间
- 13 小时
|
为什么我的STM32程序在仿真的时候,需要先执行一下程序,然后点击复位按钮,然后再次执行才能正常。是不是第一次程序就跑飞了,需要复位才正常,这是代码的原因还是仿真器的原因?我用的IAR开发环境。
IAR 的DEBUG log栏里显示:
Mon Feb 25 15:59:50 2013: Loaded macro file: C:\Program Files\IAR Systems\Embedded Workbench 5.4\arm\config\flashloader\ST\FlashSTM32F10xxx.mac
Mon Feb 25 15:59:50 2013: JTAG command: ProjectFile = C:\Documents and Settings\Administrator\桌面\程序Light_12.25\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\EWARM\settings\Project_STM32100B-EVAL.jtag, return = 0
Mon Feb 25 15:59:50 2013: JTAG command: device = STM32F10xxC, return = 0
Mon Feb 25 15:59:50 2013: DLL version: V4.14
Mon Feb 25 15:59:50 2013: Firmware: J-Link ARM V8 compiled Sep 20 2012 13:27:01
Mon Feb 25 15:59:50 2013: Selecting SWD as current target interface.
Mon Feb 25 15:59:50 2013: JTAG speed is initially set to: 32 kHz
Mon Feb 25 15:59:50 2013: Found SWD-DP with ID 0x1BA01477
Mon Feb 25 15:59:50 2013: TPIU fitted.
Mon Feb 25 15:59:50 2013: ETM fitted.
Mon Feb 25 15:59:50 2013: FPUnit: 6 code (BP) slots and 2 literal slots
Mon Feb 25 15:59:50 2013: Hardware reset with strategy 0 was performed
Mon Feb 25 15:59:50 2013: Initial reset was performed
Mon Feb 25 15:59:50 2013: -I- execUserFlashInit!
Mon Feb 25 15:59:51 2013: 456 bytes downloaded and verified (1.14 Kbytes/sec)
Mon Feb 25 15:59:51 2013: Loaded debugee: C:\Program Files\IAR Systems\Embedded Workbench 5.4\arm\config\flashloader\ST\FlashSTM32F10xxxRAM32K.out
Mon Feb 25 15:59:51 2013: Target reset
Mon Feb 25 15:59:52 2013: Downloaded C:\Documents and Settings\Administrator\桌面\程序Light_12.25\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\EWARM\STM32100B-EVAL\Exe\Project.out to flash memory.
Mon Feb 25 15:59:52 2013: Found SWD-DP with ID 0x1BA01477
Mon Feb 25 15:59:52 2013: TPIU fitted.
Mon Feb 25 15:59:52 2013: ETM fitted.
Mon Feb 25 15:59:52 2013: FPUnit: 6 code (BP) slots and 2 literal slots
Mon Feb 25 15:59:52 2013: Hardware reset with strategy 0 was performed
Mon Feb 25 15:59:52 2013: 11120 bytes downloaded into FLASH and verified (7.31 Kbytes/sec)
Mon Feb 25 15:59:52 2013: Loaded debugee: C:\Documents and Settings\Administrator\桌面\程序Light_12.25\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\EWARM\STM32100B-EVAL\Exe\Project.out
Mon Feb 25 15:59:52 2013: Found SWD-DP with ID 0x1BA01477
Mon Feb 25 15:59:52 2013: TPIU fitted.
Mon Feb 25 15:59:52 2013: ETM fitted.
Mon Feb 25 15:59:52 2013: FPUnit: 6 code (BP) slots and 2 literal slots
Mon Feb 25 15:59:53 2013: Software reset was performed
Mon Feb 25 15:59:53 2013: Target reset
最会错误定位在这段代码上,
void write(uint16_t addr,uint8_t len)
{
SendBuff[0] = 0xA5;
SendBuff[1] = 0x5A;
SendBuff[2] = len; //指令长度
SendBuff[3] = 0x82; //指令
SendBuff[4] = (addr>>8); //地址
SendBuff[5] = (addr); //地址
SendBuff[6] = 0x00; //读取长度
SendBuff[7] = 0x00; //读取长度
USART1_Send(SendBuff,len+3);
}
void USART1_Send(uint8_t * buf,uint8_t len)
{
for( u16 i=0;i<len;i++)
{
// USART_SendData(USART1,buf); //SendBuff
USART_SendData(USART1,0x55);
//USART_SendData(USART1,SendBuff); //SendBuff
//等待数据发送完毕
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
}>
|
|