--- title: Lab6: Hardware toc: no ... 預期目標 ------- - 實際體驗 STM32 硬體操作 - 以 [STM32F4-Discovery](http://www.st.com/internet/evalboard/product/252419.jsp) 為參考硬體,探討相關的軟體開發工具與流程 - Unit Test 概念的落實 開發工具介紹與準備 ---------------- - GNU Toolchain: 同之前 Lab - ICE = In-Circuit Emulator - [Remote Debugging using GDB](http://www.codeproject.com/Articles/14983/Remote-Debugging-using-GDB) .. code-block:: prettyprint sudo apt-get install automake* libtool libusb-1.0-0-dev git clone http://github.com/texane/stlink.git cd stlink ./autogen.sh ./configure --prefix=/usr make sudo make install sudo cp 49-stlinkv2.rules /etc/udev/rules.d/ - 取得 OpenOCD 原始程式碼 .. code-block:: prettyprint git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd * 或者 [openocd-d2f61e1a4592449188305164b27f495f78dca00a.tar.bz2](/embedded/Lab6/openocd-d2f61e1a4592449188305164b27f495f78dca00a.tar.bz2) - 編譯 OpenOCD .. code-block:: prettyprint cd openocd ./bootstrap ./configure --prefix=/opt/openocd \ --enable-jlink \ --enable-amtjtagaccel \ --enable-buspirate \ --enable-stlink \ --disable-libftdi echo -e "all:\ninstall:" > doc/Makefile make sudo make install Programming STM32 F2, F4 ARMs under Linux ------------------------------------------ - [A Tutorial from Scratch](http://www.triplespark.net/elec/pdev/arm/stm32.html) * Introduction STM32, STM32F2, STM32F4 * Obtaining and Setting Up OpenOCD * Setting up the Hardware: STM32F4Discovery with integrated ST-Link/V2 * The Minimalistic Hello-World Program * Running the Minimalistic Hello-World Program * Debugging * Automating the Steps 工作環境 ------- - 取得最新 Labs 內容 (與之前 [Lab3](/embedded/Lab3) 操作相似): .. code-block:: prettyprint git clone git://gitcafe.com/embedded2012/Labs.git cd Labs/Lab-6 或是 .. code-block:: prettyprint cd Labs/Lab-6 git fetch labs git merge labs/master HEAD 具備互動操作的 USB serial 實做 ---------------------------- - http://www.sparetimelabs.com/usbcdcacm/ (文末提到與之前指定作業相關的技術議題) - USB list: /var/lib/usbutils/usb.ids * ArchLinux: /usr/share/hwdata/usb.ids - neocon 離開方法: ``~.`` * neocon /dev/ttyACM0 - http://wiki.openmoko.org/wiki/NeoCon - http://wiki.openmoko.org/wiki/CDC_ACM 示範程式碼 -------- .. code-block:: prettyprint cd Labs/Lab-6/discoveryF4 make cd discovery_demo make flash cd ../serialUSB/ make flash Unit Test --------- - 「在以往我們常常不停地改寫程式,在這個過程中,有意無意地常常會有東西被改壞掉還不知道,而我們檢查的方式可能很常是透過一直修改程式碼或輸入的資料來測試 - 但是當程式越來越大,我們測試時只專注在一個地方,此時所要測試的程式越來越多,不小心出錯的可能也越來越多,每改寫一次就是一次昂貴的人力檢查,最後程式就像一艘漏水的船,補了這裡,那裡卻又多了一個洞,船員像無頭蒼蠅一樣四處補洞,這樣的情況就是 Unit Test 能解決的問題 - 透過Unit Test,每次寫的程式碼都交給程式自動測試,一來測試的速度很快,不管是一百次還是一千次,總比人工測試來得快速、正確、廣範,但這不是免費的,代價就是程式設計師要寫很多 Unit Test 的程式碼,還要想要如何寫 Unit Test 的程式 - 進一步的還有測試導向的開發模式(Test-driven development),程式是在Unit Test寫完之後才開始寫,這樣一來迫使程式設計師在一開始就得把設計想好」 * http://blog.ez2learn.com/2009/01/21/try-google-unit-test-framework/ - http://www.dotblogs.com.tw/hatelove/archive/2012/05/08/unit-test-introduction.aspx - http://teddy-chen-tw.blogspot.tw/2011/11/unit-tests.html - Android CTS: http://source.android.com/compatibility/cts-intro.html - CUnit: A Unit Testing Framework for C * http://cunit.sourceforge.net/screenshots.html * sudo apt-get install libcunit1-dev + 如果找不到該套件,請先行執行 sudo apt-get update * make check - 參考輸出: .. code-block:: prettyprint ./unit-test CUnit - A Unit testing framework for C - Version 2.1-0 http://cunit.sourceforge.net/ Suite: Suite_1 Test: test of fprintf() ... passed Test: test of fread() ... passed --Run Summary: Type Total Ran Passed Failed suites 1 1 n/a 0 tests 2 2 2 0 asserts 5 5 5 0 作業 ---- - 透過 OpenOCD 對 STM32F4Discovery 內建的 ST-Link/V2 介面,設計一個驗證硬體的 unit test 環境 * 可參照 Group Presentation 的週邊測試方式 * 至少需要包含 USB, ADC, RTC - 藉由 OpenOCD + GDB,實做 firmware download 程式,可視為 boot loader - 一旦系統藉由特製的 boot loader 載入於 STM32F4-Discovery 硬體並啟動後,可監控系統運作並執行特定的 unit test 程式 - 驗證方式: ``cd Labs/Lab-6 && make all check`` 參考資訊 ------- - [STM32F4-Discovery 繁體中文簡易操作](http://cms.mcuapps.com/products/stm32f4-discovery/README.html) - [OpenOCD 繁體中文簡易操作](http://cms.mcuapps.com/techinfo/toolchains/openocd/)