刚上手ucosII 写了一个ucosII程序,程序进入了hard fault Hanlder死掉了,调试和排查后找到表象是一个全局数组导致系统进入异常,因为我注释掉这一句之后系统就正常运行,但是我调试的时候,程序执行顺利走过这一句代码,到整个调用函数完毕才死掉,很奇怪。而且我也检查了数组指针并没有溢出。求大神帮忙分析。
异常代码处:buf
= high_byte<<16 | mid_byte<<8 | low_byte;(Read_A_Conversion()函数中)
整个系统大概框架是:
任务:
void Task_Cs5524Run(void *p_arg)
{
// OS_CPU_SR cpu_sr;
while(1)
{
// OS_ENTER_CRItiCAL();
Read_CS5524();
// OS_EXIT_CRITICAL();
if(D_value[0]!=0){
LedRun_Inversion();
}
else
LedErr_Inversion();
OSTimeDlyHMSM(0,0,0,100);
}
}
Read_CS5524函数部分:
void Read_CS5524(void)
{
Read_A_Conversion(0x88,4,c***uf);//8setup
// Delay_Ms(2);
AI_Process();
AI_Filter();
Whatwrong();
}
Read_AConversion函数:
void Read_A_Conversion(char command, char channel, unsigned int *buf)
{
unsigned char i = 0;
static unsigned char high_byte = 0, mid_byte = 0, low_byte = 0;
/*start conversion*/
SPI1_CS_LOW;
SPI_ReadWriteByte(command);//0xB8-µ¥ÖÜÆÚ8setup
do{ }while(GPIO_ReadInputDataBit(GPIOX_SPI1, GPIO_SPI1_MISO) != 0);//µÈ´ýת»»½áÊø
SPI_ReadWriteByte(0xff);
for(i=0; i
{
high_byte = SPI_ReadWriteByte(0x00);
mid_byte = SPI_ReadWriteByte(0x00);
low_byte = SPI_ReadWriteByte(0x00);
// Recbuf= high_byte<<16 | mid_byte<<8 | low_byte;
buf = high_byte<<16 | mid_byte<<8 | low_byte;
}
SPI1_CS_HIGH;
}
最后是buf指针所指向的是一个全局的unsigned int 数组:
unsigned int c***uf[20]={0};
当我用Recbuf替换掉buf时系统正常运行。Recbuf也是一个全局得得unsigned int 数组:
unsigned int Recbuf[8];
有没有ucos大神出来帮忙分析分析啊!