STM32:非初始化变量?

问题描述:

使用uvision IDE进行STM32开发,我想在启动时有一些计时器变量未初始化。我曾尝试:STM32:非初始化变量?

volatile unsigned int system_time __attribute__((section(".noinit"))); 

__attribute__((zero_init)) volatile int system_timer; 

,但似乎没有任何工作。根据来自其他地方的提示,我另外在选项/目标/ IRAM1上检查了NoInit。 但是,复位后变量设置为零。

任何人都可以帮忙吗?

你必须检查从.MAP文件中变量的地址,并使用该关键字

可以让你在你的C源文件未初始化的变量指定的地址。该

下面的例子演示了如何使用 keyword.for例如找到几种不同的变量类型......

struct link { 
    struct link idata *next; 
    char  code *test; 
}; 

struct link idata list _at_ 0x40;  /* list at idata 0x40 */ 
char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */ 
int xdata i1   _at_ 0x8000; /* int at xdata 0x8000 */ 
char far ftext[256] _at_ 0x02E000; /* array at xdata 0x03E000 */ 

void main (void) { 
    link.next = (void *) 0; 
    i1  = 0x1234; 
    text [0] = 'a'; 
    ftext[0] = 'f'; 
} 

我希望它可以帮助解决你的问题。

您需要执行以下步骤。如下 声明你的变量:

volatile unsigned int system_time __attribute__((section(".noinit"),zero_init)); 

然后,你必须使用分散文件中声明与NOINIT属性的执行部分,并与连接器使用。 示例分散文件:

LR_IROM1 0x08000000 0x00080000 { ; load region size_region 
    ER_IROM1 0x08000000 0x00080000 { ; load address = execution address 
     *.o (RESET, +First) 
     *(InRoot$$Sections) 
     .ANY (+RO) 
    } 
    RW_IRAM1 0x20000000 UNINIT 0x00000100 { ;no init section 
     *(.noinit) 
    } 
    RW_IRAM2 0x20000100 0x0000FFF0 {    ;all other rw data 
     .ANY(+RW +ZI) 
    } 
}