遇到奇怪问题:调试时设置断点,100%进入HardFault_Handler;而全速跑没问题,功能正常。
折腾了一天,头大了。
芯片用的是STM32F103VCT6,uCOS-II 的版本是V2.91。没进行移植,直接用野火uCOS-II模板。
部分源代码:
void AppTaskAppMgr(void *p_arg)
{
INT8U err;
APPMSG_MSG_STRUCT_Def *pmsg;
(void)p_arg;
BeepDrvInit();
LampDrvInit();
ClockDrvInit();
AppMgrClock(OS_TRUE);
BeepDrvBeep(1,1);
while(OS_TRUE)
{
pmsg = (APPMSG_MSG_STRUCT_Def*)NULL;
pmsg = OSQPend(gpOSEventAppMgr,OS_TICKS_PER_SEC*50/1000,&err);
if(OS_ERR_NONE == err)
{
if(APPMSG_SYMBOL_WIFI == pmsg->symbol)
AppMgrNetAnalyse(pmsg);
else if (APPMSG_SYMBOL_APPMGR == pmsg->symbol)
AppMgrMsgAnalyse(pmsg);
else if(APPMSG_SYMBOL_PERIPHERAL == pmsg->symbol)
{
if(PERIPHERAL_DEV_ADDR_SendCard == pmsg->type)
AppMgrMsgSendCardAnalyse((void*)pmsg);
else if(PERIPHERAL_DEV_ADDR_GetCard == pmsg->type)
AppMgrMsgGetCardAnalyse((void*)pmsg);
else if(PERIPHERAL_DEV_ADDR_Gate == pmsg->type)
AppMgrMsgGateAnalyse((void*)pmsg);
else
AppMsgFreeMsg((void*)pmsg);
}
else
AppMsgFreeMsg((void*)pmsg);
}
BeepDrv();
LampDrv();
}
屏蔽掉红色的代码可随便函数内部设置断点,单步、全速运行都正常。没屏蔽设置断点后再全速跑则进入HardFault_Handler错误。单步跟在任务切换死掉。仔细检查了程序,未能发现内存溢出的可能。指针指向错误也未没发现。
OS_EVENT *gpOSEventAppMgr;
#define APPMGR_Q_NUM_MAX 20
static void *gpAppMgrQMsg[APPMGR_Q_NUM_MAX];
//创建管理事件消息队列
do
{
gpOSEventAppMgr=OSQCreate(gpAppMgrQMsg,APPMGR_Q_NUM_MAX);
}while(NULL == gpOSEventAppMgr); |