现在有一个项目,使用
STM32F030R8
单片机,外挂W5500 TCP/IP协议栈,开发环境使用MDK5.14;单片机已更换过,或者单独运行有异常的代码,问题还是存在的;
单片机ROM为64K,内存8K,MDK使用默认设置;
项目编译后,调试运行到结构体赋值时产生了HardFault异常,找不到原因!
############MAP文件的信息#######################
==============================================================================
Code (inc. data) RO Data RW Data ZI Data Debug
28704 1750 4984 172 3580 367126 Grand Totals
28704 1750 4984 172 3580 367126 ELF Image Totals
28704 1750 4984 172 0 0 ROM Totals
==============================================================================
Total RO Size (Code + RO Data) 33688 ( 32.90kB)
Total RW Size (RW Data + ZI Data) 3752 ( 3.66kB)
Total ROM Size (Code + RO Data + RW Data) 33860 ( 33.07kB)
==============================================================================
######################代码#########################
下面是代码:
头文件中的结构体定义:
typedef struct _RIP_MSG
{
uint32 xid;
uint8 op;
uint8 htype;
uint8 hlen;
uint8 hops;
uint16 secs;
uint16 flags;
uint8 ciaddr[4];
uint8 yiaddr[4];
uint8 siaddr[4];
uint8 giaddr[4];
uint8 chaddr[16];
uint8 sname[64];
uint8 file[128];
uint8 OPT[312];
}RIP_MSG;
---------------------------------------------------------------------------------------------------------------------
C文件中的代码:
uint8 EXTERN_DHCPBUF[1024];//定义数组
RIP_MSG * pRIPMSG = (RIP_MSG*)EXTERN_DHCPBUF; //定义结构体指针
---------------------------------------------------------------------------------------------------------------------
产生异常的代码(如果注释掉这些代码,整个工程就可以正常运行):
memset((void*)pRIPMSG,0,sizeof(RIP_MSG)); // 发生异常 将结构体初始化为0 ,
或:
pRIPMSG->op = DHCP_BOOTREQUEST;//没异常
pRIPMSG->htype = DHCP_HTYPE10MB;//没异常
pRIPMSG->hlen = DHCP_HLENETHERNET;//没异常
pRIPMSG->hops = DHCP_HOPS;//没异常
temp= (unsigned int *)pRIPMSG->xid; //没异常
*temp= htonl(DHCP_XID); //发生异常 这里htonl(DHCP_XID)的数值=0x78563412;
调试时的汇编代码:
99: temp= (unsigned int *)pRIPMSG->xid;
0x08005FB6 489F LDR r0,[pc,#636] ; @0x08006234
0x08005FB8 6800 LDR r0,[r0,#0x00]
0x08005FBA 6805 LDR r5,[r0,#0x00]
100: *temp= htonl(DHCP_XID);
0x08005FBC 489E LDR r0,[pc,#632] ; @0x08006238
0x08005FBE 6800 LDR r0,[r0,#0x00]
0x08005FC0 F7FFFBFC BL.W htonl (0x080057BC)
0x08005FC4 6028 STR r0,[r5,#0x00] //在这里发生异常
---------------------------------------------------------------------------------------------------------------------
麻烦各位,帮忙看看哪里有问题?
一周热门 更多>