--- title: Lab24: Hardware toc: no ... 預期目標 ------- * 學習使用 STM32F4-Discovery 硬體 * 接觸 ARM Cortex-M 環境 * 學習 GNU Toolchain 與相關 open source 工具 硬體資訊 -------- * STM32F4 (168 MHz, up to 210 MIPS) - 32-bit ARM Cortex-M4F core - 1 MB Flash - 192 KB RAM - LQFP100 package * STM32F1 (on-chip debugger) - Firmware: STM32F1 -> hardware debug -> JTAG ---> STM32F4 * 內建 ST-LINK/V2, 可實現單線 USB 開發 (同時供電與除錯),免去購買其他 JTAG 裝置 * STM32 的 Discovery 系列電路板都附有 ST-LINK (V1/V2),可透過接腳選擇,切換使用自身或外部 debugger JTAG (Joint Test Action Group) -------------------------------- * 為了要驗證電路,因此提供有點像「後門」的機制以便檢查電路是否有問題 * 也提供了一個嵌入式系統的偵錯機制,當使用一些偵錯工具,像電路內模擬器用 JTAG 當作訊號傳輸的機制,使得程式設計師可以經由 JTAG 讀取整合在 CPU 上的偵錯模組 * 偵錯模組可以讓程式設計師偵錯嵌入式系統中的軟體 http://en.wikipedia.org/wiki/Joint_Test_Action_Group 開發工具介紹與準備 ---------------- - 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 或者 http://sourceforge.net/projects/openocd/files/openocd/0.7.0/ - 編譯 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 USB 相關程式 ------------------ * https://hackpad.com/2013-Week-4-EtkoJumoBlU * 自動繪製方框的 USB mouse: https://gitcafe.com/KuoE0/DiscoveryF4-USB * 自動繪製圓形的 USB mouse: https://github.com/netspehre/Circle * AutoSign 自動簽名: https://github.com/shengwen1997/AutoSign 「作業系統之前的程式 for stm32f4discovery」系列文章 -------------------------------------------------------------------------- * [打造 Linux 開發環境](http://descent-incoming.blogspot.tw/2013/04/for-stm32f4discovery-0-linux.html) - [1+2+3...+10 (ARM 組合語言版本)](http://descent-incoming.blogspot.tw/2013/04/for-stm32f4-discovery-1-10-asm-version.html) * [點亮 LED](http://descent-incoming.blogspot.tw/2013/04/for-stm32f4discovery-2-led-c-version.html) * [USART](http://descent-incoming.blogspot.tw/2013/04/for-stm32f4discovery-3-usart.html) Reference --------------- * [Lab6](/embedded/Lab6)