2016-03-03 48 views
2

我在Eclipse中編寫STM32F100x的程序。爲方便起見,我使用this template class進行引腳控制。使用-O0優化的靜態變量的未定義引用[stm32 template Pins]

而且我有這樣的代碼:

... 
Pin<'C', 6>  temp_ok; 
Pin<'C', 7>  temp_fail; 
... 
int main() 
{ 
    ... 
    if(temperature > 30) 
    { 
     temp_ok.Off(); 
     temp_fail.On(); 
    } 
    else 
    { 
     temp_fail.Off(); 
     temp_ok.On(); 
    } 
    ... 
} 

當我與-O3優化是編譯OK編譯,但顯然我不能調試我的程序(Eclipse中寫道:「沒有源avaible主()0X。 ......「

要調試,我應該使用-O0優化,但是當我嘗試-O0標誌編譯我的錯誤是這樣的:

不確定REF erence到`引腳<(炭)67,11,(炭)72> :: GPIOx

使用谷歌我發現this post。閱讀後我明白了,我需要明確聲明GPIOx靜態變量。

於是我開始尋找GPIOx靜態變量Pin class,我發現這一點:

template<char port, int pin_no, char activestate> 
struct Pin 
{ 
    enum { GPIOx_BASE = port_gpio_t<port>::GPIOx_BASE }; 
    enum { IDR_BB_ADDR = PERIPH_BB_BASE + (GPIOx_BASE + offsetof(GPIO_TypeDef, IDR) - PERIPH_BASE) * 32 + pin_no * 4 }; 
    enum { ODR_BB_ADDR = PERIPH_BB_BASE + (GPIOx_BASE + offsetof(GPIO_TypeDef, ODR) - PERIPH_BASE) * 32 + pin_no * 4 }; 
    static struct 
    { 
     GPIO_TypeDef* operator->() { return (GPIO_TypeDef*)GPIOx_BASE; } 
    }GPIOx; 
... 
...other code 

但我不明白,我應該寫什麼代碼初始化無名結構?


編譯器:臂皮質-EABI-G ++ V4.7.2

調試器:臂-NONE-EABI-GDB v7.10.1 + OpenOCD的+ JLINK

IDE:的Eclipse CDT +

OS: Linux Mint的17.3

回答

0

就在鏈接的頭頂部:

USAGE: 
* 
* I. Declare pin typedef: 
* typedef Pin<'A', 5, 'H'> PA5; // PA5, active level = high 
* typedef Pin<'A', 6> PA6;   // PA6, active level = high ('H' is default parameter) 

所以,嘗試宣告這種方式:

typedef Pin<'C', 6>  temp_ok; 
typedef Pin<'C', 7>  temp_fail; 
+0

沒有幫助:( –