LPCXpresso-LPC1769 組込みプログラミング [標準ライブラリ編1]

■きっかけ
LPCXpresso で HELLO WORLD (1)
http://www.eleki-jack.com/arm/2010/04/lpcxpresso-hello-world-1.html

上記のページでstdio標準関数を利用して、IDE上のコンソールに表示するサンプル・ソースコードが紹介されている。

■ビルド時の問題
printf関数を使用するソースコードを実際に作成しビルドを試みたが、
リンカー実行時にエラーが発生する。

(作成したソースコード)

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include
#include
#include

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

int main(void) {
    volatile static int i = 0 ;
    while(1) {
       printf("hello %d\n", i++);
    }
    return 0 ;
}

■上記トラブルの解決方法
プロジェクトの設定に問題があったようだ。設定方法を以下に示す。
① LPCXpresso IDE上でビルド対象のProjectをアクティブにする

② 右クリックのポップアップ・メニューから"propaties"を選択する

③ "propaties"ウィンドウの左欄の"C/C++ build"→"Settings"

④ 同ウィンドウの"MCU Linker"→"Target"を選択する。

⑤ 同ウィンドウの Use C Libraryの項目を"Redlib(none)からRedlib(semihost)に変更する

(設定完了) ※分かりづらい場合は下図参照。

■参考URL
詳細は下記のページを参考して頂きたい。

Using printf in your applications (Semihosting)
http://support.code-red-tech.com/CodeRedWiki/UsingPrintf

7.1.1. What is semihosting?
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0205f/Bgbjjgij.html