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
沒有幫助:( –