zoukankan      html  css  js  c++  java
  • RealView MDK 编译器,程序无故跑飞问题

    在开发的时候发现自己的程序无故跑飞,下面是程序的代码:

    View Code
     1 int main()
     2 {
     3 
     4     nmeaINFO info;
     5     char buff[2048];
     6 
     7     
     8     int gen_sz;
     9     int it;
    10 
    11     uart_init();
    12 
    13 
    14     nmea_zero_INFO(&info);
    15 
    16     info.sig = 3;
    17     info.fix = 3;
    18 
    19     info.lat = nmea_degree2ndeg(23.15382796209);
    20     info.lon = nmea_degree2ndeg(113.3404131815);
    21 
    22     info.satinfo.inuse = 0;
    23     info.satinfo.inview = 4;
    24     info.satinfo.sat[0].id = 1;
    25     info.satinfo.sat[0].sig = 50;
    26     info.satinfo.sat[1].id = 2;
    27     info.satinfo.sat[1].sig = 50;
    28     info.satinfo.sat[2].id = 3;
    29     info.satinfo.sat[2].sig = 50;
    30     info.satinfo.sat[3].id = 4;
    31     info.satinfo.sat[3].sig = 50;
    32 
    33 
    34     for (it = 0; it < 10; ++it)
    35     {
    36         gen_sz = nmea_generate(buff, 511, &info, GPGSV | GPRMC);
    37 
    38         buff[gen_sz] = 0;
    39 
    40         info.speed += .1;
    41 
    42         uart_send_buffer(&uart_fifo, buff, gen_sz);
    43 
    44         delay_ms(1000);
    45     }
    46 
    47     while (1)
    48         ;
    49 
    50 }

    当我把

        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

  • 相关阅读:
    day_07 深浅拷贝
    day_06 再谈编码
    day_05 字典
    day_04 列表
    day_03 字符串
    HDU 1049 Climbing Worm
    HDU 1720 A+B Coming
    Pascal向C++的跨越
    B-Boxes
    喵哈哈村的狼人杀大战(4)
  • 原文地址:https://www.cnblogs.com/xiangtailiang/p/2783973.html
Copyright © 2011-2022 走看看