1. 程式人生 > >IAR問題總結(持續更新)

IAR問題總結(持續更新)

這個帖子持續更新。

一、inline問題

Error[e46]: Undefined external "key_mode_get_key_value" referred in key (xxxx.r87 ) 

用了一個inline函式,結果提示這個,通過查閱資料問題如下:

inline或者#pragma inline建議編譯器對緊隨其後的函式進行inline處理

#pragma inline = forced 強制編譯器對緊隨其後的函式進行inline處理

 

同時這個還和編譯器的優先順序有關係:

也就是說用了inline,在低優先順序下,編譯器不一定就把函式作為inline處理。

 

補充說明:register修飾變數也只是一種建議。

 

二、除錯時候提示:Another EXEC is already running.

IAR for RL78 V1.3用E1調式時候提示這個:

 

插拔E1不行,板子重新上下電也不行,最後把IAR重啟搞定。

 

三、判斷是Debug模式還是Release

NDEBUG
Description This preprocessor symbol determines whether any assert macros you have written in
your application shall be included or not in the built application.
If this symbol is not defined, all assert macros are evaluated. If the symbol is defined,
all assert macros are excluded from the compilation. In other words, if the symbol is:
● defined, the assert code will not be included
● not defined, the assert code will be included
This means that if you write any assert code and build your application, you should
define this symbol to exclude the assert code from the final application.

由上文可知:

NDEBUG  如果定義了,為Release模式,如果沒有定義則為debug模式。

 

四、位域賦值問題
位域賦值時候,是按著從bit0開始對齊到位域寬度:
struct {
uint16_ttBit0   :1;
uint16_t        :7;
uint16_t        :8;
}bit16_t;


uint8_t chTemp;
chTemp          = 0x01;
bit16_t.tBit0   = chTemp;
則賦值後:bit16_t.tBit0為1;

chTemp          = 0xFE;
bit16_t.tBit0   = chTemp;
則賦值後:bit16_t.tBit0為0;



五、BOOL型別變數賦值
bool型別變數賦值,是按著右邊的真假值賦值:
uint8_tchTemp;
boolbTemp;

chTemp = 0x00;
bTemp = chTemp;
則bTemp為false;

chTemp = 0xFE;
bTemp = chTemp;
則bTemp為true;
(以chTemp的真假決定)

 

六、IAR for RL78 模擬軟體復位功能

由於RL78晶片沒有軟體復位功能,但是可以通過復位選項模擬軟體復位。

復位源:

有手冊可知,當執行非法指令0xFF時候就可以產生復位。

有兩種方法,把變數賦值為0xFF,強制轉換為函式指標。

或者用匯編指令:asm("db 0xFF");

 

我用第二種方法,測試可用。

 

七、union的0佔位符問題

我一直以為位域中的0寬度佔位符是不跨位元組的,因此我定義了下面一個結構體:

debug發現,當給tSelectLocdorLed賦值的時候,tSlectItem值並沒有改變,

因此我想是不是0佔位符把後面的bits全佔了。因此把所有的0都修改為本子節

實際未使用數,再debug發現正常了,我查了半天C99,也麼有找到相關說明,

回頭找到了,再發上來。

八、自動獲得工程路徑和安裝路徑

程式配置時候,可以把和工程相關的配置為相對路徑,如:$PROJ_DIR$\linker\lnkr5f100fe.xcl

                          可以把和工具相關的配置為相對路徑,如:$TOOLKIT_DIR$\LIB\