init
__no_init 是给编译器linker使用,为禁止系统启动时初始化,是定义在不初始化的区域。可用于硬件复位或看门狗异常复位标记状态,但是在系统上电复位时为不定值。
__no_init unsigned int ram_val1;
__no_init unsigned int ram_val2 @0x20000400;
int main(void)
{
printf("ram_val1:%d, addr:0x%08x\r\n", ram_val1, (unsigned int *)&ram_val1);
printf("ram_val2:%d, addr:0x%08x\r\n", ram_val2, (unsigned int *)&ram_val2);
ram_val1++;
ram_val2++;
while (1)
{
}
return 0;
}
上面代码为一个简单的程序应用逻辑,ram_val1地址由编译器分配,ram_val2为指定地址0x20000400(@为指定地址)。
软件复位:
ram_val1:1026533183, addr:0x2001c620
ram_val2:-1862674153, addr:0x20000400
//复位
ram_val1:1026533184, addr:0x2001c620
ram_val2:-1862674152, addr:0x20000400
//复位
ram_val1:1026533185, addr:0x2001c620
ram_val2:-1862674151, addr:0x20000400
上电复位:
ram_val1:489399103, addr:0x2001c620
ram_val2:-1862543081, addr:0x20000400
//上电复位
ram_val1:489399167, addr:0x2001c620
ram_val2:-1866868457, addr:0x20000400
//上电复位
ram_val1:489400127, addr:0x2001c620
ram_val2:-1862674153, addr:0x20000400
系统上电复位时ram_val1和ram_val2为不定值,软件复位可不被系统启动初始化,维持其值不变。