gnuk/ChibiOS_2.0.2/docs/html/article__eclipse2.html

223 lines
14 KiB
HTML
Raw Normal View History

2010-08-10 03:11:02 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ChibiOS/RT: Embedded development using Eclipse</title>
<link href="custom.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<table style="text-align: center; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 80px;"><img alt="ChibiOS/RT Logo" src="logo_small.png"></td>
<td><big><big>ChibiOS/RT</big></big><br><br>Architecture - Reference Manual - Guides</td>
<td style="width: 80px;"></td>
</tr>
</tbody>
</table>
<hr size="1">
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="navpath"><a class="el" href="main.html">ChibiOS/RT</a>&nbsp;&raquo;&nbsp;<a class="el" href="articles.html">Articles and Code Samples</a>&nbsp;&raquo;&nbsp;<a class="el" href="page__general.html">General</a>
</div>
</div>
<div class="contents">
<h1><a class="anchor" id="article_eclipse2">Embedded development using Eclipse </a></h1><p>Compiling and debugging ChibiOS/RT applications using Eclipse.</p>
<p>This article will explain how to use an Eclipse based toolchain (see <a class="el" href="article__eclipse.html">Setting up a free embedded IDE</a>) to develop ChibiOS/RT based applications. This guide will allow you to:</p>
<ul>
<li>Importing ChibiOS/RT demos into the Eclipse environment.</li>
<li>Edit and reformat your source code.</li>
<li>Compile and examine errors and warnings.</li>
<li>Upload your program on the target board.</li>
<li>Debug your code on the target board both in high level language and assembler.</li>
<li>Develop embedded applications with or without ChibiOS/RT.</li>
</ul>
<h2>What this guide does not cover</h2>
<p>This guide assumes knowledge in following areas:</p>
<ul>
<li>OpenOCD setup is not covered by this guide because the setup changes depending on the JTAG probe used, the target MCU and also the target board. The guide will show the setup for a specific JTAG probe and a specific target, a valuable source for the OpenOCD setup is the <a href="http://forum.sparkfun.com/viewforum.php?f=18" target="_blank">dedicated forum</a>, most questions you may have about OpenOCD have most likely already been answered there.</li>
<li>Hardware setup.</li>
</ul>
<p>In general this guide is not a replacement for the Eclipse, GCC, Make, binutils, newlib, GDB, OpenOCD user manuals, the guide simply aims to give you a faster start.</p>
<h2>Article Index</h2>
<ul>
<li><a class="el" href="article__eclipse2.html#eclipse2_requirements">Required Components</a></li>
<li><a class="el" href="article__eclipse2.html#eclipse2_importing">Importing existing ChibiOS/RT demos into Eclipse</a></li>
<li><a class="el" href="article__eclipse2.html#eclipse2_creating">Creating a new ChibiOS/RT application</a></li>
<li><a class="el" href="article__eclipse2.html#eclipse2_compiling">Compiling and Cleaning applications</a></li>
<li><a class="el" href="article__eclipse2.html#eclipse2_configuring">Preparing for Debug</a><ul>
<li><a class="el" href="article__eclipse2.html#eclipse2_configuring_gdb">Creating a GDB Debug Configuration</a></li>
<li><a class="el" href="article__eclipse2.html#eclipse2_configuring_openocd">Configuring and running OpenOCD</a></li>
</ul>
</li>
<li><a class="el" href="article__eclipse2.html#eclipse2_debugging">Debugging</a><ul>
<li><a class="el" href="article__eclipse2.html#eclipse2_debugging_start">Starting a Debug Session</a></li>
<li><a class="el" href="article__eclipse2.html#eclipse2_debugging_stop">Stopping a Debug Session</a></li>
</ul>
</li>
</ul>
<h2><a class="anchor" id="eclipse2_requirements">
Required Components</a></h2>
<p>This guide requires:</p>
<ul>
<li>An Eclipse/GCC/OpenOCD based toolchain, as example the one described in the article <a class="el" href="article__eclipse.html">Setting up a free embedded IDE</a>.</li>
<li>An Olimex ARM-USB-OCD JTAG probe, this guide applies to any other ARM JTAG probe as long it is supported by OpenOCD.</li>
<li>An Olimex STM32-P103 target board, this guide applies to any other ARM target except for the OpenOCD setup part.</li>
<li>A terminal emulator for capturing the board serial output, Windows users may use Hyper Terminal, Linux and MAC OS-X users may use <a href="http://cutecom.sourceforge.net/" target="_blank">CuteCom</a>. All ChibiOS/RT demos generate on the serial port a test report when a button on the target board is pressed, other demos may activate a command shell on the serial port, in both cases a terminal emulator is required.</li>
</ul>
<h2><a class="anchor" id="eclipse2_importing">
Importing existing ChibiOS/RT demos into Eclipse</a></h2>
<p>The first step is to import a project into the Eclipse environment. ChibiOS/RT demos do not include Eclipse project files but just a normal Makefile. Eclipse is able to import a Makefile project and create its own project file so this is not a problem. This is how it is done:</p>
<ul>
<li>Open you Eclipse environment and select the workspace created into the ChibiOS/RT project directory.</li>
<li>From within Eclipse select "File-&gt;New-&gt;C_Project", a dialog box will show.</li>
<li>Select "Makefile_project-&gt;Empty_Project" in the "Project type:" box.</li>
<li>Select "-- Other Toolchain --" in the "Toolchains:" box.</li>
<li>Unselect the "Use default location" check box.</li>
<li>Select the demo directory using the "Browse..." button. Something like "C:\Projects\ChibiOS-RT\demos\ARMCM3-STM32F103-GCC" will appear in the "Location:" box.</li>
<li>In the project name box put the same name of the directory containing the demo, ARMCM3-STM32F103-GCC in this example. <br/>
<br/>
<div align="center">
<img src="eclipse003.jpg" alt="eclipse003.jpg"/>
</div>
<br/>
</li>
<li>Press the "Finish" button and the project will be created and shown in the "Project Explorer".</li>
<li>Right click on the imported project and select "Index-&gt;Rebuild", this will make Eclipse build its internal symbols database.</li>
<li>Repeat the above steps for each ChibiOS/RT demo you want to import in Eclipse, all the demos that have a makefile can be imported.</li>
</ul>
<h2><a class="anchor" id="eclipse2_creating">
Creating a new ChibiOS/RT application</a></h2>
<p>If you want to create a new application it is recommended that you create a Makefile project first then you can import it into eclipse using the above procedure. Makefile projects have the advantage that can be compiled everywhere even without Eclipse. Creation steps:</p>
<ul>
<li>Create your own development directory under the ChibiOS/RT installation directory, as example "chibios/myprojects".</li>
<li>Copy an existing demo, of course choose a demo using your same target, under the new directory and rename it, as example "chibios/myprojects/myapplication".</li>
<li>Customize the Makefile if needed, usually you just need to do this if your application is composed by more than one source file. You may also want to remove the ChibiOS/RT test code from your application.</li>
<li>Once your makefile is ready, import the project under the Eclipse workspace using the procedure described in <a class="el" href="article__eclipse2.html#eclipse2_importing">Importing existing ChibiOS/RT demos into Eclipse</a>.</li>
</ul>
<h2><a class="anchor" id="eclipse2_compiling">
Compiling and Cleaning applications</a></h2>
<p>Once imported, an application can be compiled by using the "Build All" in the toolbar or by right clicking on the project and selecting "Build
Project". In order to clean a project (removing all the temporary and binary files) right click on the project and select "Clean Project". <br/>
<br/>
</p>
<div align="center">
<img src="eclipse004.jpg" alt="eclipse004.jpg"/>
</div>
<p> <br/>
The compilation result is visible as a complete log in the "Console" window, the detail of all errors an warnings is available in the "Problems" window. <br/>
<br/>
</p>
<div align="center">
<img src="eclipse005.jpg" alt="eclipse005.jpg"/>
</div>
<p> <br/>
The build process produces the binary files specified in the Makefile, all the ChibiOS/RT demos produce binary files named ch.elf, ch.bin and/or ch.hex. The image must be loaded on the target board in order to execute it. The build process usually creates also some other useful files containing details about the built application (usually named ch.map and ch.dmp).</p>
<h2><a class="anchor" id="eclipse2_configuring">
Preparing for Debug</a></h2>
<p>In order to debug your application a debug configuration must be created. The configuration instructs GDB (the source debugger used by Eclipse) on how to load the image, load the symbols and place the initial breakpoint in the make function. Note that GDB performs its function by connecting to a "GDB server", the DGB server implements the low level communication with the target device through the JTAG probe. In our scenario the GDB server functionality is performed by OpenOCD, this mean that OpenOCD must be running while performing a debug session within Eclipse.</p>
<h3><a class="anchor" id="eclipse2_configuring_gdb">
Creating a GDB Debug Configuration</a></h3>
<p>A target specific debug configuration is required in order to:</p>
<ul>
<li>Establish a connection with the GDB server.</li>
<li>Stop and reset the target.</li>
<li>Upload the binary code in Flash or RAM.</li>
<li>Set an initial breakpoint in the main function.</li>
<li>Start the target (which will immediately stop on the breakpoint).</li>
</ul>
<p>The first thing to do is to open the "Debug Configurations..." dialog: <br/>
<br/>
</p>
<div align="center">
<img src="eclipse006.jpg" alt="eclipse006.jpg"/>
</div>
<p> <br/>
The configuration dialog will appear, we must create a native Zylin configuration: <br/>
<br/>
</p>
<div align="center">
<img src="eclipse007.jpg" alt="eclipse007.jpg"/>
</div>
<p> <br/>
Now we must give the configuration a name, "ARMCM3-STM32F103-GCC (flash and
run)" in this example, then setup the various configuration pages as follow: <br/>
<br/>
The "Main" tab: </p>
<div align="center">
<img src="eclipse008.jpg" alt="eclipse008.jpg"/>
</div>
<p> <br/>
<br/>
The "Debugger" tab: </p>
<div align="center">
<img src="eclipse009.jpg" alt="eclipse009.jpg"/>
</div>
<p> <br/>
<br/>
The "Commands" tab: </p>
<div align="center">
<img src="eclipse010.jpg" alt="eclipse010.jpg"/>
</div>
<p> <br/>
Note that the "Commands" tab contains the part that changes depending on the target. The complete commands sequence (it is not fully visible in the image) for STM32 is: </p>
<div class="fragment"><pre class="fragment"> monitor soft_reset_halt
monitor wait_halt
monitor poll
monitor flash probe 0
monitor stm32x mass_erase 0
monitor flash write_bank 0 ch.bin 0
monitor soft_reset_halt
symbol-file ch.elf
thbreak main
<span class="keywordflow">continue</span>
</pre></div><p> <br/>
<br/>
The "Common" tab: </p>
<div align="center">
<img src="eclipse011.jpg" alt="eclipse011.jpg"/>
</div>
<p> <br/>
Now the debug configuration is complete.</p>
<h3><a class="anchor" id="eclipse2_configuring_openocd">
Configuring and running OpenOCD</a></h3>
<p>OpenOCD must be run, with appropriate parameters, before starting your debug session. Please refer to the OpenOCD documentation in order to properly launch it for your target. <br/>
**To be completed**</p>
<h2><a class="anchor" id="eclipse2_debugging">
Debugging</a></h2>
<p>Now we are ready to debug an application on the target. Note that Eclipse have a mechanism called "Perspectives", you edit and compile your source code while you are in the "C/C++ perspective" while the debugging is performed in the "Debug perspective". You can switch perspective at any time, even while there is an active debug session. If you install more of the many Eclipse extension plugins (there are thousands) you may have even more perspectives available.</p>
<h3><a class="anchor" id="eclipse2_debugging_start">
Starting a Debug Session</a></h3>
<p>In order to start a debugging session first make sure that OpenOCD is running then press the drop down menu on the right side of the debug icon in the toolbar (the small green bug) and select your debug configuration (we created just one but you may have multiple debug configurations in your project, as example I usually create another debug configuration that just starts the target without uploading the code). <br/>
<br/>
</p>
<div align="center">
<img src="eclipse012.jpg" alt="eclipse012.jpg"/>
</div>
<p> <br/>
The debugger will be initialized, you will see the operation in progress on the console then Eclipse will switch to the debug perspective and you will see your program stopped on the default breakpoint in the main function. <br/>
<br/>
</p>
<div align="center">
<img src="eclipse013.jpg" alt="eclipse013.jpg"/>
</div>
<p> <br/>
From there you can perform all the usual debugging tasks, set breakpoints, single step execution, variables, memory and registers inspection etc. Please refer to the Eclipse documentation about those "normal" operations. Note that if the debugging start procedure hangs then there is probably an error in your configuration or problems with the target, read the console log and/or the OpenOCD output in order to understand where the problem is.</p>
<h3><a class="anchor" id="eclipse2_debugging_stop">
Stopping a Debug Session</a></h3>
<p>From the debug perspective press the stop button (small red square) in the debug window, the target will be stopped and you may both return to the C/C++ perspective or start it again. </p>
</div>
<hr size="1"><address style="text-align: right;"><small>
Generated on Sun Jul 11 13:13:09 2010 for ChibiOS/RT by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.6.3</small></address>
</body>
</html>