2011-12-02 208 views
1

使用uvision IDE進行STM32開發,我想在啓動時有一些計時器變量未初始化。我曾嘗試:STM32:非初始化變量?

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

__attribute__((zero_init)) volatile int system_timer; 

,但似乎沒有任何工作。根據來自其他地方的提示,我另外在選項/目標/ IRAM1上檢查了NoInit。 但是,復位後變量設置爲零。

任何人都可以幫忙嗎?

回答

3

你必須檢查從.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'; 
} 

我希望它可以幫助解決你的問題。

3

您需要執行以下步驟。如下 聲明你的變量:

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) 
    } 
}