您的位置:首页 > 其它

RealView MDK 编译器,程序无故跑飞问题

2012-11-23 10:50 148 查看
在开发的时候发现自己的程序无故跑飞,下面是程序的代码:

View Code

int main()
{

nmeaINFO info;
char buff[2048];

int gen_sz;
int it;

uart_init();

nmea_zero_INFO(&info);

info.sig = 3;
info.fix = 3;

info.lat = nmea_degree2ndeg(23.15382796209);
info.lon = nmea_degree2ndeg(113.3404131815);

info.satinfo.inuse = 0;
info.satinfo.inview = 4;
info.satinfo.sat[0].id = 1;
info.satinfo.sat[0].sig = 50;
info.satinfo.sat[1].id = 2;
info.satinfo.sat[1].sig = 50;
info.satinfo.sat[2].id = 3;
info.satinfo.sat[2].sig = 50;
info.satinfo.sat[3].id = 4;
info.satinfo.sat[3].sig = 50;

for (it = 0; it < 10; ++it)
{
gen_sz = nmea_generate(buff, 511, &info, GPGSV | GPRMC);

buff[gen_sz] = 0;

info.speed += .1;

uart_send_buffer(&uart_fifo, buff, gen_sz);

delay_ms(1000);
}

while (1)
;

}


当我把

nmeaINFO info;
char buff[2048];

这两个局部变量放到main函数外面,让它们变成全局变量时,程序能够正常运行。这问题看起来非常诡异,经过一番摸索之后,终于发现了问题的根本:Stack(栈)设置不合理。

因为局部变量存放于Stack(栈)中,而我们的Stack(栈)空间设置太小的时候,就会导致程序崩溃。

解决办法:

打开启动文件“SAM7.s”,找到

USR_Stack_Size EQU 0x0000400

把它修改为

USR_Stack_Size EQU 0x00001400

这样就可以调整Stack(栈)的大小了,需要根据自己的需要修改。

当用mallc函数申请空间容易失败时,可能是堆(Heap)的空间设置得太小,可以在启动代码中修改

Heap_Size EQU 0x00000000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: