Using PHYTEC FlashTools 3 and the Keil µVision2 Software
Evaluation Development Tool Chain
Note: The PHYTEC Spectrum CD includes the electronic version of
the English phyCORE-XC161 Hardware Manual
Edition: July 2003
A product of a PHYTEC Technology Holding company
phyCORE-XC161 with XC161CJQuickStart Instructions
In this manual are descriptions for copyrighted products that are not explicitly
indicated as such. The absence of the trademark ( ) and copyright () symbols
does not imply that a product is not protected. Additionally, registered patents and
trademarks are similarly not expressly indicated in this manual.
The information in this document has been carefully checked and is believed to be
entirely reliable. However, PHYTEC Meßtechnik GmbH assumes no
responsibility for any inaccuracies. PHYTEC Meßtechnik GmbH neither gives any
guarantee nor accepts any liability whatsoever for consequential damages resulting
from the use of this manual or its associated product. PHYTEC Meßtechnik
GmbH reserves the right to alter the information contained herein without prior
notification and accepts no responsibility for any damages which might result.
Additionally, PHYTEC Meßtechnik GmbH offers no guarantee nor accepts any
liability for damages arising from the improper usage or improper installation of
the hardware or software. PHYTEC Meßtechnik GmbH further reserves the right
to alter the layout and/or design of the hardware without prior notification and
accepts no liability for doing so.
Copyright 2003 PHYTEC Meßtechnik GmbH, D-55129 Mainz.
Rights - including those of translation, reprint, broadcast, photomechanical or
similar reproduction and storage or processing in computer systems, in whole or in
part - are reserved. No reproduction may occur without the express written
consent from PHYTEC Meßtechnik GmbH.
EUROPENORTH AMERICA
Address:PHYTEC Technologie Holding AG
Robert-Koch-Str. 39
D-55129 Mainz
GERMANY
Ordering
Information:
Technical
Support:
Fax:+49 (6131) 9221-331 (206) 780-9135
Web Site:http://www.phytec.dehttp://www.phytec.com
+49 (800) 0749832
order@phytec.de
+49 (6131) 9221-31
support@phytec.de
PHYTEC America LLC
203 Parfitt Way SW, Suite G100
Bainbridge Island, WA 98110
USA
• general information on the PHYTEC phyCORE-XC161 Single
Board Computer (SBC),
•an overview of Keil’s µVision2 software development tool chain
evaluation version, and
• instructions on how to run example programs on the
phyCORE-XC161, mounted on the PHYTEC phyCORE
Development Board HD200 2.5V, in conjunction with Keil
software tools
Please refer to the phyCORE-XC161 Hardware Manual for specific
information on such board-level features as jumper configuration,
memory mapping and pin layout. Selecting the links on the electronic
version of this document links to the applicable section of the
phyCORE-XC161 Hardware Manual.
Introduction
1.1 Rapid Development Kit Docume ntation
This "Rapid Development Kit" (RDK) includes the following
electronic documentation on the enclosed "PHYTEC Spectrum
CD-ROM":
• the PHYTEC phyCORE-XC161 Hardware Manual
• controller User's Manuals and Data Sheets
• this QuickStart Instruction with general "Rapid Development Kit"
description, software installation hints and three example programs
enabling quick out-of-the box start-up of the phyCORE-XC161 in
conjunction with the Keil µVision2 software development tool
chain evaluation version
This QuickStart Instruction gives a general "Rapid Development Kit"
description, as well as software installation hints and three example
programs enabling quick out-of-the box start-up of the
phyCORE-XC161 in conjunction with Keil µ Vision2. It is structured
as follows:
1) The "Getting Started" section uses two example programs:
Blinky and Hello to demonstrate the download of user code to
the Flash device using PHYTEC FlashTools 3.
2) The "Getting More Invloved" section provides step-by-step
instructions on how to modify both examples, create and build
new projects and generate and download output files to the
phyCORE-XC161 using the Keil tools and FlashTools 3.
3) The "Debugging" section provides a third example
program - "Debug" - to demonstrate simple debug functions
using the Keil µVision2 debug environment.
In addition to dedicated data for this Rapid Development Kit, the
PHYTEC Spectrum CD-ROM contains supplemental information on
embedded microcontroller design and development.
The phyCORE-XC161 represents an affordable yet highly functional
Single Board Computer (SBC) solution in sub-miniature dimensions
(60 x 53 mm). It is intended for use in memory-intensive applications
running within a CAN bus system. The standard board is populated
with an Infineon XC161CJ controller as well as a Real-Time Clock
which can be buffered by an external battery.
All applicable data/address lines and signals extend from the
underlying logic devices to two high-density Molex SMT pin header
connectors (pin width is 0.635 mm/25 mil) lining the circuit board
edges. This enables the phyCORE-XC161 to be plugged like a "big
chip" into target hardware.
The standard module runs at a 40 MHz internal clock speed
(delivering 25 ns instruction cycle) and offers 512 kByte (up to
1.5 MByte) SRAM and 256 kByte (up to 2 MByte) Flash on-board for
DATA and CODE storage.
The module communicates by means of 2 RS-232 transceiver and
2 CAN bus interfaces. The optional CS8900A 10Base-T Ethernet
controller enables implementation of the module in embedded
Internet devices. The phyCORE-XC161 operates within a standard
industrial range of 0 to +70°C and requires only a 220 mA power
source.
PHYTEC FlashTools 3 enables easy on-board download of user
programs.
The phyCORE Development Board HD200 2.5V, in EURO-card
dimensions (160 x 100 mm) is fully equipped with all mechanical and
electrical components necessary for the speedy and secure insertion
and subsequent programming of most PHYTEC phyCORE highdensity series Single Board Computers. Simple jumper configuration
readies the Development Board’s connection to the
phyCORE-XC161, which plugs into the receptacle contact strips
mounted on the Developm ent Board HD200 2.5V.
phyCORE Development Board HD200 2.5V Technical Highlights
• Reset signal controlled by push button or RS-232 control line
CTS0
• Boot signal controlled by push button or RS-232 control line
DSR0
• low voltage socket for supply with regulated input voltage 5 VDC
• additional supply voltage 2.5 VDC
• two DB-9 sockets (P1A, P1B) configurable as RS-232 interfaces
• two additional DB-9 plugs (P2A, P2B) configurable as
CAN interfaces
• simple jumper configuration allowing use of the
phyCORE Development Board HD200 2.5V with various
PHYTEC phyCORE high-density SBC’s
• RJ45 Ethernet transformer module
• one control LED D3 for quick testing of user software
• 2 x 160-pin Molex connector (X2) enabling easy connectivity to
1.5 The Keil µVision2 Software Developm ent Tool Chain
Keil µ Vision2 fully supports the entire Infineon C166 microcontroller
family. This includes a C compiler, macroassembler, Linker/Locator
and the Simulator and Target Monitor within the µVision2 IDE.
Specific chips supported are the 161, 163, 164-CI, 165, 166, 167Cx
and XC16x. Future derivatives are easily accommodated due to the
flexible Keil C compiler design.
µ Vision2 supports all in-circuit emulators that adhere to the Infineon
OMF166 debugging specification. The Keil OH166 Object-to-Hex
converter converts an absolute object file into an Intel hexfile that is
suitable for programming into an EPROM device or downloading into
external Flash on the PHYTEC phyCORE-XC161 target board.
µVision2 consists of the following executables:
Introduction
• C Compilerc166.exe
• Assemblera166.exe
• Linkerl166.exe
• Converteroh166.exe
• µVision2Uv2.exe (a Windows-based application)
Once installed, the default destination location for the DOS based
files is the C:\Keil\C166\bin directory while µVision2 is in
C:\Keil\Uv2. Access to these programs from Windows is
accomplished with µVision2. The entire tool set can be run from
µVision2 or directly from DOS with batch files. The evaluation
version is limited to 4 kByte of object code. Other than these
restrictions, all features operate normally.
µVision2 IDE
µVision2 is a Windows-based Graphical User Interface for the
C compiler and assembler. All compiler, assembler and linker options
are set with simple mouse clicks. µVision runs under
Windows 95/98/Me, NT, 2000 and XP. This Integrated Development
Environment (IDE) has been expressly designed with the user in mind
and includes a fully functional editor.
All IDE commands and functions are accessible via intuitive pulldown menus with prompted selections. An extensive Help utility is
included. External executables can be run from within µVision2, in-
cluding emulator software.
C166 C Compiler for the Entire Infineon 166/167 Family
The C166 ANSI compiler and A166 assembler are designed
specifically for the Infineon 161, 163, C164CI, 165,166, 167, 167Cx,
XC16x and future derivatives. The C166 compiler easily integrates
into the Keil RTOS and interfaces and passes debug information to
the µVision2 Simulator and all in-circuit emulators. Extensions
provide access to on-chip peripherals.
The Keil C166 compiler provides the fastest and smallest code using
industry benchmarks.
A166 Macroassembler
The Professional Kit (PK) macroassembler is included with the
PK Compiler package or is available separately. It is DOS-based or
can be run from µVision2 and includes all utilities needed to complete
your project.
µVision2 contains a software simulator supporting debugging either
via software on a host-PC or in target hardware. When operated in
conjunction with the Keil Monitor resident in target hardware
µVision2 enable the following debugging functions:
• run/halt,
• set breakpoints,
• examine/change memory,
• view the stack,
• view/set peripheral information
• apply virtual external signals.
µ Vision2 has a performance analysis feature to ensure your code runs
efficiently. In addition, µVision2 has a disassembler/assembler that
allows the modification of user code without recompiling. The
evaluation version of µVision2 is restricted to a 8 kByte in
manipulable code. Other than this restriction the evaluation tool chain
(EK) functions exactly as does the full (PK) version. The evaluation
version does not have a starting address restriction and produces
useful object code. This allows you to fully evaluate the features and
power of Keil products on the PHYTEC target board. The PK full
version has no restrictions and is fully ANSI compliant.
Introduction
FR166 Full-Function RTOS for the Infineon C166 Family
The FR166 is a multi-tasking real-time operating system for the
Infineon 166 family. You can manage multiple tasks on a single CPU
making your programs much easier to develop. The RTX166 Full
includes CAN libraries. The RTX166 Tiny is a subset of the RTX166
Full and is included with all C166 C Compiler Kits. The EK version
of the tool chain does not include an RTOS.
The RTX166 Full RTOS supports CAN controllers with the included
libraries. The CAN libraries are sold with the RTOS and support
11- and 29-bit message identifiers. Keil 166 and 8051 C compilers
interface with the RTOS and CAN libraries. Keil supports all CAN
microcontrollers based on the Infineon C505C, C515C, C164-CI,
C167Cx and XC16x. Future CAN products based on these 8051 or
C16x families are easily supported due to the flexible Keil Compiler
design.
What you will learn with this Getting Started example:
• installing Rapid Development Kit software
• starting PHYTEC’s FlashTools 3 download utility
• interfacing the phyCORE-XC161, mounted on the Development
Board, to a host-PC
• downloading example user code in hexfile format from a host-PC
to the external Flash memory using FlashTools 3
2.1 Installing Rapid Development Kit Software
When you insert the PHYTEC Spectrum CD into the CD-ROM drive
of your host-PC, the PHYTEC Spectrum CD should automatically
launch a setup program that installs the software required for the
Rapid Development Kit as specified by the user. Otherwise the setup
program start.exe can be manually executed from the root directory of
the PHYTEC Spectrum CD.
• After accepting the Welcome window and license agreement select
the destination location for installation of Rapid Development Kit
software and documentation.
The default destination location is C:\PHYBasic. All path and file
statements within this QuickStart Instruction are based on the
assumption that you accept the default install paths and drives. If you
decide to individually choose different paths and/or drives you must
consider this for all further file and path statements.
We recommend that you accept the default destination location.
• In the next window select your Rapid Development Kit of choice
from the list of available products. By using the Change button,
advanced users can select in detail which options should be
installed for a specific product.
Getting Started
All Kit-specific content will be installed to a Kit-specific subdirectory
of the Rapid Development Kit root directory that you have specified
at the beginning of the installation process.
All software and tools for this phyCORE-XC161 RDK will be
installed to the \PHYBasic directory on your hard-drive.
• In the next dialog you must choose whether to copy the selected
documentation as *.pdf files to your hard drive or to install a link
to the file on the Spectrum CD.
If you decide not to copy the documentation to your hard-drive you
will need the PHYTEC Spectrum CD-ROM each time you want to
access these documents. The installed links will refer to your
CD-ROM drive in this case.
If you decide to copy the electronic documentation to your hard-drive,
the documentation for this phyCORE-XC161 Kit will also be
installed to the Kit-specific subdirectory.
• Setup will now add program icons to the program folder, named
PHYTEC.
• In the next window, choose the Keil EK166 Software
Development Tool Chain.
Getting Started
The applicable Keil tool chain must be installed to ensure successful
completion of this QuickStart Instruction. Failure to install the proper
software could lead to possible version conflicts, resulting in
functional problems.
We recommend that you install the Keil EK166 resp. µ Vision2 from
the Spectrum CD-ROM even if other versions of µVision2 are already
installed on your system. These QuickStart Instructions and the demo
software included on the CD-ROM have been specifically tailored for
use with one another.
• After accepting the Welcome window and license agreement select
the destination location for installation of the Development Tool
Chain.
The applicable Keil µ Vision2 evaluation development tool chain will
be installed to your hard-drive. Additional software, such as Adobe
Acrobat Reader, will also be offered for installation.
In the following windows you can decide to install FlashTools 3
software and the Acrobat Reader.
The applicable FlashTools 3 software must be installed to ensure
successful completion of this QuickStart Instruction. Failure to install
the proper software could lead to possible version conflicts, resulting
in functional problems.
• Click on Yes and complete the FlashTools 3 Setup program.
Connecting the phyCORE-XC161, mounted on the phyCORE
Development Board HD200 2. 5V, to your computer is simple.
• As shown in the figure below, if the phyCORE module is not
already pre-installed, mount it connector side down onto the
Development Board’s receptacle footprint (X6).
Ensure that pin 1 of the phyCORE-connector (denoted by the hash
stencil mark on the PCB) matches pin 1 of the receptacle on the
phyCORE Development Board HD200 2.5V.
Ensure that there is a solid connection between the Molex connector
on the module and the Development Board receptacle.
D3
Figure 1:phyCORE Development Board HD200 2.5V Overview
• Simultaneously press the Reset (S2) and Boot (S1) buttons on the
phyCORE Development Board HD200 2.5V, first releasing the
Reset and then, two or three seconds later, release the Boot button.
This sequence of pressing and releasing the Reset (S2) and Boot (S1)
buttons renders the phyCORE-XC161 into the Bootstrap mode. Use
of FlashTools 3 always requires the phyCORE-XC161 to be in
Bootstrap mode. See section 5.1, “ FlashTools 3” for more details.
The phyCORE module should now be properly connected via the
phyCORE Development Board HD200 2.5V to a host-PC and power
supply. After executing a Reset and rendering the board in Flash
programming mode, you are now ready to program the
phyCORE-XC161. This phyCORE module/phyCORE Development
Board HD200 2.5V combination is also referred to as "target
hardware".
2.3 Starting PHYTEC F l ashTools 3
FlashTools 3 for Windows is a utility program that allows download
of user code in Intel *.hex or *.h86 file format from a host-PC to a
PHYTEC SBC via an RS-232 connection.
Proper connection of a PHYTEC SBC to a host-PC enables the
software portion of FlashTools 3 to recognize and communicate to the
Bootstrap loader on the phyCORE-XC161.
• You can start FlashTools 3 by selecting it from the Programs
menu using the Window s Start button.
It is recommended that you drag the FlashTools 3 icon onto the
desktop of your PC. This enables easy start of FlashTools 3 by
double-clicking on the icon.
Always ensure that the phyCORE-XC161 is in Bootstrap mode before
pressing the Connect button (see section 2.2)
• Now click the Connect button to establish connection to the target
hardware.
The microcontroller tries to automatically adjust to the baud rate
selected within the baud rate pull-down menu. However, it may occur
that the selected baud rate can not be attained. This results in a connection error. In this case, try other baud rates to establish a connection. Before attempting each connection, be sure to reset the target
hardware and render it into Bootstrap mode as described in
section 2.2.
Returning to the FlashTools 3 tabsheet window, you will see tabs for
the following:
To use the option Disconnect and hardware reset the handshake
signals on the Development Board must be connected to the host-PC.
This requires closing Jumpers JP22 and JP23 at position 2+3.
Download downloads specified hexfiles to the target hardware:
Protected Areas Info shows protected areas of Flash memory:
The "Blinky" example downloads a program to the Flash that, when
executed, manipulates the LED D3 on the phyCORE Development
Board HD200 2.5V that is located above the jumper field
(refer to Figure 1).
• Returning to the FlashTools 3 tabsheet, choose the Download tab
and click on the Open button.
The hexfile has already been installed to your hard drive during the
installation procedure.
• Browse to the correct drive and path for the phyCORE-XC161
Demo folder (default location
C:\PHYBasic\pC-XC161\Demos\Keil\Blinky\Blinky.h86) and
click Open.
• The FlashTools 3 Download window will re-appear. Now select
the Erase needed sectors checkbox in the lower left corner.
FlashTools 3 will then erase the required Flash sectors first before
downloading the specified hexfile.
• Click on the Start button in the lower right corner. You can watch
the status of the Flash erasure and code download of Blinky.h86
into external Flash memory in the lower right corner of the
Download window.
• The individual steps of the Flash download procedure can be
viewed in the status bar at the bottom of the FlashTools 3 window.
Wait until the status check finishes before returning to work with
the board. Once you see the Ready message in the lower left
corner, the downloaded code can be executed.
• Returning to the Connect tab, click on the Disconnect button and
exit FlashTools 3.
• Press the Reset button (S2) on the phyCORE Development
Board HD200 2.5V to reset the target hardware and to start
execution of the downloaded software.
• Successful execution of the program will flash the LED D3 with
The "Hello" example downloads a program to the Flash that, when
executed, performs an automatic baud rate detection and sends a
character string from the target hardware back to the host-PC. The
character string can be viewed with a terminal emulation program.
This example program provides a review of the FlashTools 3
download procedure. For detailed commentary on each step,
described below in concise form, refer back tosections 2.3
through 2.4.1.
• Ensure that the target hardware is properly connected to the
host-PC and a power supply.
• Reset the target hardware and force it into Bootstrap mode by
simultaneously pressing the Reset (S2) and Boot (S1) buttons on
the phyCORE Development Board HD200 2.5V and then releasing
first the Reset and, two or three seconds later, the Boot button.
Getting Started
• Start FlashTools 3.
• At the Connect tab of the FlashTools 3 tabsheet, select the
phyCORE-XC161 and click the Connect button in the lower left
corner to establish connection to the target hardware.
• Returning to the FlashTools 3 tabsheet, choose the Download tab
and click on the Open button.
The demo hexfile has already been installed to your hard drive during
the installation procedure.
• Browse to the correct drive and path for the phyCORE-XC161
Demo folder (default location
C:\PHYBasic\pC-XC161\Demos\Keil\Hello\Hello.h86)
and click Open.
• The FlashTools 3 Download window will re-appear. Now select
the Erase needed sectors checkbox in the lower left corner.
FlashTools 3 will then erase the required Flash sectors first before
downloading the specified hexfile.
• Click on the Start button. You can watch the status of the Flash
erasure and code download of Hello.h86 into the external Flash
memory in the lower right corner of the Download window.
• The individual steps of the Flash download procedure can be
viewed at the bottom of the FlashTools 3 window. Wait until the
status check finishes before returning to work with the board.
Once you see the Ready message in the lower left corner, the
downloaded code can be executed.
• Returning to the Connect tab, click on the Disconnect button and
• Selecting OK advances you to the COM Direct–HyperTerminal
monitoring window. Notice the connection status report in the
lower left corner of the window.
Getting Started
• Resetting the phyCORE Development Board HD200 2.5V (at S2)
will execute the Hello.h86 file loaded into the Flash.
• Successful execution will send the character string "Hello World"
from the target hardware to the HyperTerminal window.
• Click the disconnect icon in HyperTerminal toolbar and exit
HyperTerminal.
• If no output appears in the HyperTerminal window check the
power supply, the COM parameters and the RS-232 connection.
The code within the demo application Hello.h86 initializes the serial
port of your phyCORE-XC161 to 9600 baud. The initialization values
are based on the assumption that the microcontroller runs at a 40 MHz
internal clock frequency. Please note that an oscillator with a
frequency of 16 MHz populates the phyCORE-XC161. Using the
internal PLL (Phase Locked Loop) device results in an internal
40 MHz CPU frequency. If your phyCORE-XC161 is equipped with a
different speed oscillator, the demo application might transmit using
another baud rate. This may lead to incoherent characters appearing in
the HyperTerminal window following execution of code.
• how to configure the µVision2 IDE (Integrated Development
Environment)
• how to modify the source code from our examples, create a new
project and build and download an output *.h86 file to the target
hardware
3.1 Starting the µVision2 Tool Chain
The µVision2 evaluation software development tool chain should
have been installed during the install procedure, as described in
section 2.1.
Getting More Involved
You can also manually install µVision2 by executing ek166v427.exe
from within the \Software\Keil\µVision2.30 directory of your
PHYTEC Spectrum CD.
Note:
It is necessary to use the Keil tool chain provided on the
accompanying Spectrum CD in order to complete this QuickStart
Instruction successfully. Use of a different version could lead to
possible version conflicts, resulting in functional problems.
Start the tool chain by selecting KeilµVision2 from within the
programs group.
After you start µVision2, the window shown below appears. From
this window you can create projects, edit files, configure tools,
assemble, link and start the debugger. Other 3rd party tools such as
emulators can also be started from here.
• In the text field ‘File name’, enter the file name of the project you
are creating. For this tutorial, enter the name Blinky2.uv2 and
click on Save.
• The Select Device for Target ’Target1’ will automatically appear.
Double click on Infineon as manufacturer for the CPU within the
Getting More Involved
next window which opens automatically
1
. The phyCORE-XC161
is equipped with a XC161CJ CPU. Choose on of this controller
type from the list as shown below. This selection sets necessary
tool options for the XC161CJ device and simplifies in this way the
tool configuration.
1
:The same window opens by choosing Select Device for Target from the Project menu.
At this point you have created a project called Blinky2.uv2 and added
an existing C source file called Blinky2.c and an existing Assembler
file called Start-pc-XC161.a66. The next step is to modify the C
source before building your project. This includes compiling, linking,
locating and creating the hexfile.
3.3 Modifying the Source Code
• Double click on Blinky2.c to open it in the source code editor.
• Locate the following code section. Modify the section shown
below (the values shown in bold and italic) from the original
(100,000) counts to the indicated values:
do { /* loop forever */
P9_0 = 0; /* output to LED port */
for (i=0; i<
P9_0 = 1; /* output to LED port */
for (i=0; i<
}
while(1);
• Save the modified file by choosing File|Save or by clicking the
floppy disk icon.
3.5 Setting Options for Target
Keil includes a Make utility that can control compiling and linking
source files in several programming languages. Before using the
Make utility, macroassembler, C compiler or linker you must configure the corresponding options. Most of the options are set when
specifying the target device for the project. Only the external memory
and output options must be set.
Enter the changes as indicated below and leave all other options set to
their default values. µVision2 allows you to set various options with
mouse clicks and these are all saved in your project file.
• Click with the right mouse key in the "Project" window to open a
local menu. Choose the option Options for Target‘phyCORE-XC161’.
You are now ready to run the compiler and linker using the Make
utility.
• Click on the Build Target iconfrom the µVision2 tool bar
or press <F7>.
• If the program specified (Blinky2.c) contains any errors, they will
be shown in an error dialog box on the screen.
• If there are no errors, the code is assembled and linked and the ex-
ecutable code is ready to be downloaded to the board. This is
shown in the Output Window, which indicates "Blinky2" –0 Errors, 0 Warnings. The code to be downloaded to the board will
be the name of the project with .h86 as filename extension (in this
case Blinky2.h86).
• If a list of errors appears, use the editor to correct the error(s) in the
source code and save the file and repeat this section.
• Ensure that the target hardware is properly connected to the
host-PC and a power supply.
• Reset the target hardware and force it into Bootstrap mode by
simultaneously pressing the Reset (S2) and Boot (S1) buttons on
the phyCORE Development Board HD200 2.5V and then releasing
first the Reset and, two or three seconds later, the Boot button.
• Start FlashTools 3.
• At the Connect tab of the FlashTools 3 tabsheet, select the
phyCORE-XC161 and click the Connect button in the lower left
corner to establish connection to the target hardware.
• Returning to the FlashTools 3 tabsheet, choose the Download tab
and click on the Open button.
•Choose the Download tab, and click on the Open button.
Getting More Involved
• Browse to the correct drive and path for the phyCORE-XC161
• The FlashTools 3 Download window will re-appear. Now select
the Erase needed sectors checkbox in the lower left corner.
FlashTools 3 will then erase the required Flash sectors first before
downloading the specified hexfile.
• Click on the Start button. You can watch the status of the Flash
erasure and code download of Blinky2.h86 into the external Flash
memory in the lower right corner of the Download window.
• The individual steps of the Flash download procedure can be
viewed at the bottom of the FlashTools 3 window. Wait until the
status check finishes before returning to work with the board.
Once you see the Ready message in the lower left corner, the
downloaded code can be executed.
• Returning to the Connect tab, click on the Disconnect button and
exit FlashTools 3.
• Press the Reset (S2) button on the Development Board.
If the modified hexfile properly executes, the LED should now flash
in a different mode with different on and off durations.
You have now modified source code, recompiled the code, created a
modified downloadable hexfile, and successfully executed this
modified code.
3.8 "Hello"
A return to the "Hello" program allows a review of how to modify
source code, create and build a new project, and download the
resulting output file from the host-PC to the target hardware. For
detailed commentary on each step, described below in concise form,
refer back to the “Blinky2” example starting atsection 3.2.
3.8.1 Creating a New Project
• Open the Project menu and create a new project called Hello2.uv2
within the existing project folder
C:\PHYBasic\pC-XC161\Demos\Keil\Hello2
(default location) on your hard-drive. Select the Infineon
XC161CJ in the CPU vendor database list.
• Add Hello2.c and Start-pc-XC161.a66 from within the project
• Ensure that the target hardware is properly connected to the
host-PC and a power supply.
• Reset the target hardware and force it into Bootstrap mode by
simultaneously pressing the Reset (S2) and Boot (S1) buttons on
the phyCORE Development Board HD200 2.5V and then releasing
first the Reset and, two or three seconds later, the Boot button.
• Start FlashTools 3.
• At the Connect tab of the FlashTools 3 tabsheet, select the
phyCORE-XC161 and click the Connect button in the lower left
corner to establish connection to the target hardware.
• Returning to the FlashTools 3 tabsheet, choose the Download tab
and click on the Open button.
•Choose the Download tab, and click on the Open button.
Getting More Involved
• Browse to the correct drive and path for the phyCORE-XC161
• The FlashTools 3 Download window will re-appear. Now select
the Erase needed sectors checkbox in the lower left corner.
FlashTools 3 will then erase the required Flash sectors first before
downloading the specified hexfile.
• Click on the Start button. You can watch the status of the Flash
erasure and code download of Hello2.h86 into the external Flash
memory in the lower right corner of the Download window.
• The individual steps of the Flash download procedure can be
viewed at the bottom of the FlashTools 3 window. Wait until the
status check finishes before returning to work with the board.
Once you see the Ready message in the lower left corner, the
downloaded code can be executed.
• Returning to the Connect tab, click on the Disconnect button and
This Debugging section provides a basic introduction to the debug
functions included in the Keil µ Vision2 evaluation tool chain. Using
an existing example, the more important features are described. For a
more detailed description of the debugging features, please refer to
the appropriate manuals provided by Keil.
The µVision2 Debugger offers two operating modes that can be
selected in the Project|Options for Target phyCORE-XC161 dialog:
• The Simulator allows PC-based microcontroller simulation of
most features of the 166/ST10 microcontroller family without
actually having target hardware. You can test and debug your
embedded application before the hardware is ready. µVision2
simulates a wide variety of peripherals, including the serial port,
external I/O, and timers. The peripheral set is selected when you
select a CPU from the device database for your target.
Debugging
•Advance GDI drivers, like the Keil Monitor 166 or OCDS Driver
for XC16x interface, allow target-based debugging. With the
Advanced GDI interface you may connect directly to the target
hardware. Debugging on the target hardware also enables testing
peripheral components of the application.
The following examples utilize the Keil Monitor 166 environment.
4.1 Creating a Debug Project and Preparing the Debugge r
4.1.1 Creating a New Project
• Start the Keil µVision2 environment and close all projects that
might be open.
• Open the Project menu and create a new project called Debug.uv2
within the existing project directory
C:\PHYBasic\pC-XC161\Demos\Keil\Debug
(default location) on your hard drive. Select the Infineon XC161CJ
in the CPU vendor data base list.
•Rename the target of your project within the Project Window –
Files tab into phyCORE-XC161.
•Rename the file group Source Group 1 within the Project
Window – Files tab into User and add an additional file group
named System Files.
•Add Debug.c to the file group User and
Start_pC-XC161_debug.a66 to the file group System Files from
within the project folder.
• Your project should now look like this:
• Save the project.
At this point you have created a project called Debug.uv2, consisting
of a C source file called Debug.c and the assembler file
Start_pC-XC161_debug.a66.
The Start_pC-XC161_debug.a66 startup file differs from the standard
startup file as included in the Blinky(2) and Hello(2) demo projects in
terms of its BUSCON1 settings. The Keil monitor maps RAM to the
controller’s address space starting at address 00:0000h. In contrast,
ROM/Flash would be assigned to this address range for all projects
that are created for "out-of-Flash" execution. Furthermore, RAM is
accessed via /CS1 and mapped to an address range starting at
20:0000h for "out-of-Flash" execution. These address ranges are
configured within the Start-pC-XC161.a66 startup file. BUSCON1 is
disabled in the Start-pC-XC161_debug.a66 startup file since RAM is
already mapped to start address 00:0000h by the Keil monitor (also
refer to Abstract.txt located in theKeil\C166\Monitor\Phytec pC-XC161 folder for details).
4.1.2 Setting Options for Target
Debugging
• Open the Project|Options for Target’phyCORE-XC161’ menu
and change the default settings to the correct values as shown in
the figure below. This includes settings for the clock frequency of
your phyCORE-XC161, the memory model and the off-chip
memory.
• Select the Output tabsheet and enable the Browse Information
checkbox. This will include additional browser information into
the object files that can be viewed with the Source Browser
included in Keil µVision2.
Compiling of the Debug.c program can be controlled with the two
define statements MONITOR166 and INTERRUPT. Setting the
define MONITOR166 reserves space for the serial interrupt and
disables the configuration of the serial interface by the Debug.c
program. This is necessary to avoid overwriting the configuration
done by the monitor kernel. The defineINTERRUPT disables all
serial output of the Debug.c program. If debugging is controlled with
the serial interrupt, (see settings for the Keil Monitor-166 Driver insection 4.1.3) any serial input and output of the user application
conflicts with the communication of the monitor program. Such serial
communication functions cannot be active in user code to ensure
proper debugging.
4.2 Preparing the Target Hardware to Communicate with
the Debugger
• Ensure that the target hardware is properly connected to the
host-PC and a power supply
• Reset the target hardware and force it into Bootstrap mode by
simultaneously pressing the Reset (S2) and Boot (S1) buttons on
the phyCORE Development Board HD200 and then releasing first
the Reset and, two or three seconds later, the Boot button.
Since the required microcontroller portion to communicate with the
Keil Monitor 166 will be automatically downloaded using the
Bootstrap mode there is no further preparation required for the target
system.
Debugging
4.3 Starting the Debugger
• To start the µVision2 debug environment, click on the debugger
icon
indicating that this is an evaluation version. Click on OK.
• You will see a blue status bar from left to right at the bottom of
your screen indicating the download process of the debug
program.
on the µVision2 toolbar. A pop-up window will appear
If a problem occurs during data transfer, the following window will
appear:
Click on Settings and verify the COM port and the baud rate
(9600 baud). Reset the target hardware, force it into Bootstrap mode
(refer to section 4.2) and click on Try Again.
If the data transfer was successful, a screen similar to the one shown
below will appear. The Project window changed to the Register page.
The debug toolbar is also displayed. In the lower part of the debug
screen you will see the Command and Watch/Stack window.
You may need to open, resize and /or move some windows to make
your screen look similar to the screen capture. You can open inactive
windows by choosing the desired window from the Vi ew pull-down
menu. The following screen capture has Workbook Mode enabled to
allow easy access to various overlapped windows with tabs.
The debugger will run to the ’main’ function and stop automatically.
Notice the yellow arrow pointing to the first command in the ’main’
function. Also notice the program counter (PC $) within the ProjectWindow – Register page showing the start address of the ’main’
function.
4.4 Keil µVision2 Debug Features
• The Debugger window toolbar gives access to the following
debug commands: Reset, Run, Stop, Step Into, Step Over, Step Out
and Run to Cursor line .
Debugging
Reset
Run
Stop
Step Into
Step Over
Step Out
Run to Cursor lin e
• The first button on the debugger toolbar is the Reset
button.
The Reset command sets the program counter to 0.
• The button to the right of the Reset button starts the Run
comma nd.
Clicking this button runs the program without active debug
functions. To stop program execution at a desired point, a
breakpoint can be placed before the Run button is pushed.
• The next button on the debugger toolbar is the Stopbutton.
The Stop button interrupts and stops the running program at an
undetermined location.
• The first button allowing exact control of the program execution is
the Step Into button.
The Step Into command performs the execution of the command
line to which the Current-Statement Arrow points. This can be a C
command line or a single assembler line, depending on the current
display mode. If the command line is a function call, Step Into
jumps to the C function or subroutine, enabling you to explore the
code contained in the accessed subroutine.
• The StepOver button is next on the debugger toolbar.
The StepOver command executes the command line, to which the
Current-Statement Arrow points. This can be a C command line
or a single assembler line, depending on the current display mode.
If the command line is a function call, the function will be
executed without single stepping into the function.
•The next button is the Step Out button..
Step Out is used to exit a function you are currently in. Step Out is
very useful if you find yourself in a function you are not interested
in and need to return quickly to your intended function.
•The last button on the debugger toolbar performs the Run to
Cursor line command.
The Run to Cursor line command executes the program to the
current cursor position within the code window. This allows use of
the cursor line as a temporary breakpoint.
•Click on Insert/Remove Breakpointto set a breakpoint here.
The red marker on the left-hand side of the selected line indicates
the breakpoint. You can also set a breakpoint by double-clicking
in the desired code line.
•Click on the Ru nicon and the program will run and stop at
the breakpoint.
•Notice that the LED (D3) on the Development Board now
illuminates. This is because the led(1) function call has been
executed and the status of the LED is shown in the Serial
window.
•Click again on Insert/Remove Breakpointto remove the
• Click on the Step Intoicon to enterthe ’for’ loop.
• The Watch window automatically shows the value of the local
variable i. In order to change the number base from hexadecimal
to decimal, right-click on the variable.
•Click Step Overseveral times and watchthe value of i count up.
Debugging
•As you can see in the source code, the for{} loop will end if i
becomes equal to the first element of the constant field rhythm[]
which has the value of 160,000. To leave the wait function,
change the value of i by typing i=159996 in the command line and
pressing <Enter>. Now repeat clicking on Step Over until you
leave the wait function.
•Click in the source code line blink++ and choose Run to Cursor
line from the debug toolbar. Your program will be executed until
it reaches this line.
•Notice that the LED D3 on the Development Board is off now and
the new status of the LED is shown in the Serial window.
• As a last example, the constant "rhythm[]" will be evaluated. Go
to the source code line where the constant "rhythm[]" is declared.
Right-click on "rhythm[]" and choose the "ADD rhythmtowatch window" -> #1 option. Select the "Watch #1" tabsheet at
the bottom of the watch window. The constant is shown with its
address and a smallsign in front which indicates that
"rhythm[]" is an array with a group of array elements. Click the
sign to expand the view and to see all array elements of
"rhythm[]".
4.6 Running, Stopping and Resetting
• To run your program without stopping at any time, delete all
breakpoints by clicking on thebutton.
• Click the Runbutton.
The LED now blinks and its current status is displayed in the Serial
window.
You can use of the Stopbutton to stop program execution at any
time.
The monitor kernel runs on the target hardware. A debugger reset sets
the IPC to zero and performs other initialization routines if no user
application was started. This type of reset is not as complete as a
hardware-reset (pressing push button S2 on the Development Board).
The best method to stop a running application is to click on the Halt
button rather than using the Reset CPU in monitor mode. Halt tries to
stop a running application when the ’Serial interrupt or NMI’ option
is enabled. If this option is not enabled, a dialog box is displayed in
which you can select further options. This has the advantage of
detecting any ’infinite loop’ in which your program might be stuck.
With reset you start again at address 0.
Debugging
Debugger in Simulator mode:
When you are using the simulator (i.e. no connection to target
hardware), pressing the Reset CPUicon does not cause a
running simulation to stop at the current point of execution. ResetCPU starts the application from the start address (0x0) again. Press
the Halt buttonto halt a program under normal conditions.
Hardware NMI:
The phyCORE Development Board HD200 does not provide a
hardware NMI button. A NMI is the most reliable way to stop a
running program. This is even more important when you are using the
Bootstrap version of the monitor because it is difficult to resynchronize the debugger and the kernel. For example, it is not
possible for the debugger to re-synchronize automatically by pressing
the hardware reset button (S1) if the monitor has been downloaded
with the Bootstrap Loader. It must be restarted manually by restarting
the debugger.
After successfully debugging the program, next change the project
and the target settings in order to create an Intel hexfile. This can then
be downloaded to and executed out of the Flash memory on the
phyCORE-XC161.
•Exit the current debug session by selecting Debug\Start/Stop
Debug Session.
• Within the Project Window – Files tab remove the startup file
that was used for the debug session as described in section 4.1.1.
First highlight the Start_pC-XC161_debug.a66 file. Then rightclick in the Project Window – Files to open a new window.
Choose the option Remove File ’Start_pC-XC161_debug.a66’.
• Now add the Start_pC-XC161.a66 to the file group System Files.
This will add the applicable startup code to the debug demo when
running out of Flash as opposed to debugging code in RAM as
described in sections 4.1 through 4.6. Refer back to section 4.1.1
• Open the Project|Options for Target’phyCORE-XC161’ menu
and change the settings for off-chip memory to the new values as
shown in the figure below. The start address for RAM, accessed
via Chip Select signals /CS1, is 0x200000 which is also
configured in the BUSCON1 register (see start_pC-XC161.a66file).
This section provides advanced information for successful operation
of the phyCORE-XC161 with the µVision2 software tool chain.
5.1 FlashTools 3
Flash is a highly functional means of storing non-volatile data. One of
its advantages is the possibility of on-board programming. Flash
programming tools for the phyCORE-XC161 are provided in the form
of executable and binary files that run under
Windows 9x/Me/NT/2000/XP. These tools make use of the Bootstrap
mode to transfer executable code to the phyCORE-XC161 that, in
turn, download user code into the Flash. Additionally, the reprogrammable Flash device on the phyCORE-XC161 enables easy
update of user code and the target application in which the
phyCORE-XC161 has been implemented.
Advanced User Information
Currently the phyCORE-XC161 can be populated with four different
sized Flash devices: a 29F200 with 256 kByte, a 29F400 with
512 Byte, a 29F800 with 1 MByte or a 29F160 with 2 MByte.
FlashTools 3 always uses the Bootstrap mode to transfer the required
microcontroller firmware to the phyCORE-XC161. Hence, there is no
restriction in using the Flash memory for storing user code.
Before Flash programming FlashTools 3 will adjust the internal
Chip Select Unit and the bus configuration of the microcontroller
during the Bootstrap download. This results in the following
programming memory model:
• Flash bank using /CS0 addressable at 000000H-1FFFFFH
(up to 2 MByte Flash)
• RAM bank 1 using /CS1 addressable at 200000H-27FFFFH
(up to 512 KByte RAM)
• RAM bank 2 using /CS3 addressable at 300000H-3FFFFFH
Using the Bootstrap mode to transfer the required microcontroller
firmware to the phyCORE-XC161 ensures that FlashTools 3 maintains its independent Flash programming capability.
5.2 Start-pc-XC161.a66
The code within the assembly file start-pc-XC161.a66 is responsible
for the initial controller configuration and the startup initialization of
your C project. This includes adjusting the properties of the external
bus signals and Chip Select signals, setting of the system stack,
initialization of variables and clearing of memory areas.
It is very important that this code will execute prior to the execution
of user code. To ensure this, it is recommended that the startup code
occupies the reset vector of the application, which is the location
where the microcontroller starts execution after reset (0x0000). After
performing the initialization steps your individual main() function is
called by the startup code.
Since some of the settings are hardware-dependent, we recommend
use of the prepared start-pc-XC161.a66 from within the default
location C:\PHYBasic\pC-XC161\Tools\Startup\Keil. The properties
of the external bus interface are already configured for the
phyCORE-XC161. You may want to change the values for the Chip
Select Unit.
To accommodate the startup code to the needs of your application
copy it from the directory described above to your project directory.
You can then edit, modify and compile it using the Keil macroassembler.
Since the startup code will usually be implicitly taken into
consideration from the default runtime libraries, you must now
explicitly tell your linker to instead consider your individual startup
object file. To do this we recommend adding your modified
start-pc-XC161.a66 file to your project. Be sure that it is always
included in the Link/Lib process of your project (see options within
the Project window of the Keil tool chain).
The Linker has to combine several re-locatable object modules
contained in object files and/or libraries to generate a single absolute
object.
In addition the Linker must locate several segments of code type,
constants and data to fixed address locations within the address range
of the microcontroller: This ensures the natural or explicitly declared
properties of these segments.
Data segments must always be located in Random Access Memory
(e.g. RAM), code and constant segments should be located in any
kind of non-volatile memory (e.g. Flash). The C166 family has a von
Neumann architecture which uses the same read signal to fetch data
and also code or constants. To distinguish between non-volatile and
modifiable memory, physically different memory devices must be
addressable within different address ranges.
Advanced User Information
To enable easy accommodation of the linking process the Linker
collects segments of equal type to classes.
The Keil tool chain distinguishes the following classes:
xCODE:code for several addressing modes
(x = N, I, F, H or X)
xDATA:not initialized data for several addressing modes
(x = N, I, F, H or X)
xDATA0:pre-initialized data for several addressing modes
(x = N, I, F, H or X)
xCONST:constant for several addressing modes
(x = N, I, F, H or X)
It is required that all xDATA and xDATA0 classes segments are
located to any internal RAM of the XC161CJ or to any external RAM
on the phyCORE-XC161.
All xCODE and xCONST classes must also be located to any internal
non-volatile memory (e.g. Flash, OTPROM) of the XC161CJ or the
external Flash memory of the phyCORE-XC161.
A near address data area (NDATA, NDATA0) must reside in one data
page (16 kByte). A near address code area (NCODE, NCONST) must
reside in one code segment (64 kByte).
To ensure proper execution of your application you must take the
runtime memory model into account when linking and locating. This
means that you must instruct the Linker where to assume external
RAM for locating data classes and Flash for locating code and
constant classes.
The recommended operating mode of the phyCORE-XC161 allows
the use of the Chip Select Unit of the XC161CJ to define the physical
memory layout. By modifying the file start-pc-XC161.a66 as part of
your project you can adapt the memory layout to your needs.
The external use of the Chip Select signals is predefined by the
hardware in the following way:
• Flash Bank uses /CS0 (up to 2 MByte Flash)
• RAM Bank uses /CS1 (up to 512 kByte RAM)
The default configuration of the phyCORE-XC161 has 1 MByte Flash
(/CS0) and 512 kByte fast SRAM (/CS1) (order code
PCM-020-0020E).
Caution:
You will see multiple mirrors of a memory device that has a physical
smaller address range than the associated address range of the Chip
Select signal. For instance if you adjust Chip Select signal /CS1 to be
active within an address range of 1 MByte and the actual memory size
populating the phyCORE is just 512 kByte, you will get one mirrored
image of your RAM.
We recommend that you generate a *.m66 map file for your project
and inspect the memory map information within this file. Compare
this information with the physical memory model resulting from your
settings selected within the start-pc-XC161.a66 file.
Whenever you decide to use the µVision2 target debugger or Mon166
target Monitor to debug your application, some special precautions
must be taken into consideration to ensure proper code execution of
your application.
Your application and the Keil Monitor kernel contained in the files
boot and monitor must share some memory locations within the target
system. If you do not consider the physical Memory-Model already
claimed by the kernel and the memory requirements of the kernel, you
may get conflicts in memory use. This typically leads to variables
containing not their assigned value, functions returning bad results
and modified code.
We recommend the use of the start-pc-XC161_debug.a66 within the
default destination C:\PHYBasic\pC-XC161\Tools\Mon\Keil if you
want to debug your application using the Monitor kernel. This file
will adjust the external bus properties and the Chip Select Unit in
exactly the same manner as did the Monitor kernel.
Advanced User Information
To obtain information about the memory requirements of the Monitor,
the corresponding memory map file monitor.m66 is made available
together with the monitor executable file. This file contains a detailed
memory map of the Monitor and is also located in the default
destination mentioned above.
You must link your application to prevent any overlapping memory
ranges. Since the Monitor also uses some special interrupts for
communication with the host-PC at runtime, you should add a
Reserve: statement for 0x008 – 0x011, 0x0AC – 0x0AF to the
L166Misc tab of your Options for Target option to reserve at least
You should always ensure that segments of your application do not
reach or overlap the segments of the Monitor. The Monitor segments
will usually be linked to the top of the memory, leaving you the most
possible memory space for the application code.
The Monitor is linked under the assumption of maximum memory
upgrading for Flash bank and RAM bank. Remember that you will
have multiple additional mirrors of the physical devices actually
mounted on the phyCORE-XC161 if their capacity is less than the
maximum value of 1 MByte.
For instance if you have 512 kByte of RAM mounted on the
phyCORE-XC161 you will have one additional mirror image of the
RAM within the reserved 1 MByte range. Note that in this case all
associated address ranges of 0x80000 – 0xFFFFF will actually
address the same physical device address range of
0x00000 – 0x7FFFF. This means that exactly the same physical
memory location can be addressed using two different internal
addresses. This must be taken into consideration when verifying your
memory mappings.
5.5 Demo for the Optional Ethernet Controller CS8900A-CQ
As an option, the Crystal LAN CS8900A-Q Ethernet Controller can
populate the phyCORE-XC161 at position U16. The PHYTEC
Spectrum-CD, included in the phyCORE-XC161 Rapid Development
Kit, contains an example program that demonstrates the use of a tiny
webserver. This example program can be found in the folder:
C:\PHYBasic\pC-XC161\Demos\Keil\easy-WEB\)
This tiny web server was taken from the magazine ’Design &Elektronik’, special issue ’Embedded Internet’. It can be downloaded
from the following web site: www.elektroniknet.de/extraheft. This
software has been modified to work with a PHYTEC
phyCORE-XC161 board and the Keil C166 C Compiler.
Advanced User Information
All modifications in the source code are marked with ’// Keil:’ and
‘//Phytec:´.
The web page shows the values of two analog inputs (AN0 and AN1).
This tiny webserver needs very few resources and therefore has some
restrictions:
only one active TCP session at a given time
no support for fragmented IP datagrams
no buffer for TCP datagrams received in wrong order
only one web page, no GIF/JPG graphics possible
The IP address can be modified in the tcpip.h header file in order to
match your existing LAN (see MYIP_x).
The easyWEB project is set up for two different targets:
• pC-XC161:Settings for PHYTEC phyCORE-XC161 module
• Simulation:Settings for simulation.
Note:
The Ethernet controller cannot be simulated.
If µ Vision2 communication to the target system is not successful, an
error window will appear as shown below. If this should occur, check
if the correct serial port is selected or try other baud rates. The correct
transmission rate is 9600 baud. Click on Try Again after correcting
the communication parameters and forcing the target system into
Bootstrap mode again.
Appendices
The serial FIFO buffer in MS Windows95 can cause transmission
problems. µVison2 debugger may have problems completing the
communication initialization process. This can be intermittent. The
FIFO can be disabled under Settings/Control Panel|System|DeviceManager|Port Settings|Advanced. Make sure Use FIFO buffers is not
activated in this menu.
If the Monitor 166 kernel download is not successful, an error
window “MONITOR Configuration Error” will appear as shown
below. If this should occur, make sure that the correct target hardware
is selected under Options for Target|Debug|Settings|Monitorconfiguration. This step is crucial to ensure proper communication
between the target hardware and debug environment.