renesas technology america inc. 1 m16c seminars lab 3 creating projects using hew4 14 march 2005...
TRANSCRIPT
1
Renesas Technology America Inc.
M16C SeminarsM16C Seminars
Lab 3 Lab 3
Creating Projects Using HEW4Creating Projects Using HEW4
Last Updated:14 March 200514 March 2005
2HEW4 M16C/Tiny Tutorial 2
14 March 2005
OverviewOverview
In this lab, you will create new projects for the M16C using two
different methods.
The first method uses the SKP project generator, that will create an
empty project.
The second method will provide step by step instructions on creating
a project with existing source files.
Specific examples are shown throughout this tutorial using the
SKP16C26A. The SKP16C28 and SKP16C29-CL are similar in all
respects.
3HEW4 M16C/Tiny Tutorial 2
14 March 2005
Starting HEWStarting HEW
1. From the Windows Start menu, click onPrograms > Renesas > High-performance Embedded Workshop > High-performance Embedded Workshop
4HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project Creating a New Project using the SKP Project Generatorusing the SKP Project Generator
1. Select ‘Create a new project workspace’ when the “Welcome!” dialog box appears.
2. Click <OK>
21
5HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project with the Creating a New Project with the SKP project generatorSKP project generator
1. Verify the Tool Chain is
“Renesas M16C
Standard”
2. Verify the CPU family is
“M16C”.
3. Select the Project type
“M16C/26A Starter kit
Plus”.
4. Enter “Tutor2_pg” for
the Workspace Name.
5. Click <OK>
1
2
3
4
5
6HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project with the Creating a New Project with the SKP project generator (Cont.)SKP project generator (Cont.)
1. Select “Empty Project”.
2. Click <Finish>
3. Click <OK>
Note: The other project selections (Verify SKP and Sample Code) allow you to test the SKP and evaluate the MCU peripherals and features using pre-built sample code.
1
2
7HEW4 M16C/Tiny Tutorial 2
14 March 2005
SKP Project Generator - SummarySKP Project Generator - Summary
The following is a summary of what happens when creating a new project using the SKP project generator Empty Project:
1. The following files are created in the workspace or project directory (in this example, under C:\Workspace\Tutor2_pg\Tutor2_pg): A copy of the user startup code (ncrt0_26Askp.a30 and
sect30_26askp.inc). A .c file (main_26askp_template.c) that contains the main
function. Copies of the SKP header files (sfr26A.h, skp_bsp.h, and
skp_lcd.h) A copy of the sfr_26a_labels.a30 file so SFR labels are visible in
the debugger.2. Creates a debug session for using the FoUSB ICD.3. Links the startup files first as shown in the “Linking the startup files
first” slides. 4. Adds the phase to generate a hex file when building the project as
shown in the slide “Generate a hex file for the Programmer”.
8HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project EnvironmentCreating a New Project Environment
The SKP project generator greatly simplifies the creation of a new project. BUT, the only way you will understand this is if you have to build a project from scratch. (Wow. Better you then me…)
Ok, my boss made me give you a little help, we are going to give you the original source files. The following slides will walk you through the project creation process:
• Create a new workspace from scratch• Add source files• Setup the software development environment including the linker, build, debugger, and programming configuration
9HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 1 of 9) Creating a New Project (Page 1 of 9)
1. From the pull down menu, select
“File -> New Workspace”.
2. Verify the Tool Chain is “Renesas
M16C Standard”
3. Verify the CPU family to “M16C”.
4. Select the Project type
“Application”.
5. Click on Browse to and surf to C:\
Renesas\SKP16C26A\
Sample_Code
6. Enter “Tutor2” for the Workspace
Name.
7. Click <OK>
2
3
5
6
7
4
10HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 2 of 9)Creating a New Project (Page 2 of 9)
1. Verify the Toolchain Version
is “5.30.02”.
2. Change the CPU Series to
“M16C/Tiny”.
3. Click <Next>
1
2
3
11HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 3 of 9)Creating a New Project (Page 3 of 9)
1. Change the Target type to
“M16C/Tiny”.
2. Change the Startup file type
to “USER”
3. Click <Next>
1
2
3
12HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 4 of 9)Creating a New Project (Page 4 of 9)
1. Unselect ‘Use Heap Memory’
2. Where asked about
generating a main() function,
change to ‘None’ (we will be
giving you a main() function).
3. Select ‘Use FoUSB’
4. Click <Next>
1
2
3
4
13HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 5 of 9)Creating a New Project (Page 5 of 9)
The stack settings are grayed out
because the USER startup file
was selected on page 3 of 8. If
DEFAULT startup file had been
selected, these settings would
have been available.
1. Click <Next>
1
14HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 6 of 9)Creating a New Project (Page 6 of 9)
1. Select the Target
‘M16C_R8C_FoUSB/UART’
2. Click <Next>
1
2
15HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 7 of 9)Creating a New Project (Page 7 of 9)
1. Click <Next>
1
16HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 8 of 9)Creating a New Project (Page 8 of 9)
We already have the source files
and selected USER startup files
(see Creating a New Project
Pages 3 and 4), so there are no
source files that will be generated.
1. Click <Finish>
Did anyone notice we went
from x/6 to x/7 in the titles?1
17HEW4 M16C/Tiny Tutorial 2
14 March 2005
Creating a New Project (Page 9 of 9)Creating a New Project (Page 9 of 9)
A project summary is displayed to
indicate a successful creation of
the new project, tutor2.
1. Click <OK>
18HEW4 M16C/Tiny Tutorial 2
14 March 2005
HEWHEWAfter creating the project, HEW will look similar to the figure below.
19HEW4 M16C/Tiny Tutorial 2
14 March 2005
Default and User (SKP) Startup FilesDefault and User (SKP) Startup Files
Default startup files (ncrt0.a30 and sect30.inc) are included with HEW.
Typically the user will need to edit these files depending on which MCU
you are using. Customized startup files are included with the SKP’s. For
the /26A SKP the files are called ncrt0_26askp.a30 and
sect30_26askp.inc.
In many cases users can use these startup files for their target
applications with no modification. If you did not purchase a starter kit, but
wish to obtain these files, visit our SKP website at: www.renesas.com/skp
20HEW4 M16C/Tiny Tutorial 2
14 March 2005
Adding Source Files (Page 1 of 2)Adding Source Files (Page 1 of 2)
1. From the ‘Project’ Pull
Down Menu select ‘Add
Files…’.
2. Change the Look in
directory to: ‘C:\Renesas\
SKP16C26A\
Sample_Code\Tutor2_src’.
3. Select the two files
‘main_tutor2.c’ and
‘ncrt0_26askp_tutor2.a30’.
4. Click on ‘Add’.
2
3
4
21HEW4 M16C/Tiny Tutorial 2
14 March 2005
Adding Source Files (Page 2 of 2)Adding Source Files (Page 2 of 2)
After adding the source files, HEW’s
workspace will look like this.
If your workspace looks slightly
different, configure the view to make
it the same. (Right click in the project
Window to get this option.)
Displaying the source file
dependencies this way makes it
easier to verify if the header files are
included before building a project.
22HEW4 M16C/Tiny Tutorial 2
14 March 2005
M16C Linkage OrderM16C Linkage OrderAfter checking dependencies, HEW4 must be setup to link the startup files first. The startup files contain information on memory addresses and sections which the linker uses to place the code at the correct addresses. Note if the startup file is named “Ncrt0.a30”, HEW4 will automatically link it first.
If you configure the Project Windowto show the files in time order, you will see the files in the order that they will be sent to the linker.
If you go through the Tutor2 code in the order it will be linked, the first code that is linked defines the section information.(You will find it in the include file, sect30_26askp_tutor2.inc, starting on line 118.)
23HEW4 M16C/Tiny Tutorial 2
14 March 2005
Link OrderLink Order(M16C Toolchain Version 5.30.02 and later)(M16C Toolchain Version 5.30.02 and later)
By default, HEW links the Project files in
alphabetical order. BUT, when using M16C
toolchain version 5.30.02 and HEW 4.0 (or
latter), you have the ability to manually
control the link order!
To manually control the link order, select
“Build -> Linkage Order”
24HEW4 M16C/Tiny Tutorial 2
14 March 2005
Linking the Startup File First Linking the Startup File First 1. Check the box ‘Use custom linkage
order’2. Select the file
‘ncrt0_26askp_tutor2.r30’3. Click ‘Move to top’This configuration is done, lets copy it to the rest of the configurations4. Click <Copy to…>5. Use the up and down arrows to
select another configuration (these are just below the down arrow that you can see)
6. Click <OK>7. Repeat for the remaining
configurations.8. Close the Linkage Order Window
1
2 3
4
25HEW4 M16C/Tiny Tutorial 2
14 March 2005
Defining an Include DirectoryDefining an Include DirectoryFor this SKP, files that are common to all the sample code are kept in a directory named “\Common” under “\Sample_Code”. An example is the register definition file “sfr.h” that is included for all the projects, yet never needs to be modified. Because of this, we need to setup HEW so it knows where to look for these files during compile time.
1. From the ‘Build’ pull down menu, select ‘Renesas M16C Standard Toolchain’
2. Change the Configuration to “All Configurations”
3. Click <Add>4. Set the Relative to: option to
‘Custom directory’ and the Directory: to‘C:\Renesas\SKP16C26A\Sample_Code\Common’
5. Click <OK>6. Click <OK>
2
3
4
5
26HEW4 M16C/Tiny Tutorial 2
14 March 2005
Building (compile & link) the ProgramBuilding (compile & link) the Program
1. Click on the ‘Build’ icon.
2. Look in the Build tab of the Output
Window.
3. If there are No Errors or Warnings,
skip to page 30.
4. If there are Warnings, look at the
note on the next page.
5. If there are Errors, you did
something wrong. You will need to
trace back your steps to see where
you went wrong.
27HEW4 M16C/Tiny Tutorial 2
14 March 2005
If You Get WarningsIf You Get Warnings
If you only got 1 Warning, verify that it was associated with the linker
limiting the output to 64K (> 60 days). If this is the case, go to the next
page:
If you get more than 1 Warnings when you compile, you probably did
not define the link order correctly. Go back to page 26 and define the
linkage order.
28HEW4 M16C/Tiny Tutorial 2
14 March 2005
OptimizationOptimization
By default all optimization is turned off. Lets compare code size when optimization is turned off, to when it is on.
Scroll up in the Build Tab of the Output window and find the code size.
Non-optimized code size = ________________Bytes
Now lets turn on optimization.
From the ‘Build’ menu, select ‘Renesas M16C Standard tool chain’
29HEW4 M16C/Tiny Tutorial 2
14 March 2005
OptimizationOptimization
1. Select ‘All configurations’
2. Select ‘Tutor2’ Files
3. Change the Category to
‘Optimize’
4. Enable Optimization Level:
‘[-O3]’
5. Enable ‘Size or Speed:’
6. Click <OK>
1
2
34
5
6
30HEW4 M16C/Tiny Tutorial 2
14 March 2005
OptimizationOptimization
Re-Build the now that optimization is on.
Scroll up in the Build Tab of the Output window and find the code size.
Optimized code size = ________________Bytes
NOTE: The NC30 compiler also includes an advance optimization utility, ‘utl30.exe’ (see the NC30 manual).
31HEW4 M16C/Tiny Tutorial 2
14 March 2005
Generate a hex file for the ProgrammerGenerate a hex file for the ProgrammerAfter building a program, a file with an .x30 extension is generated. For this example, ‘tutor2.x30’ is generated. This file contains information for the debugger and are downloaded using HEW. However, device programmers, including the E8 and FoUSB programmers, use hex files in Motorola or Intel format. Lets setup HEW to automatically generate a .mot file during a build.
With the feature enabled, a hex (.mot) file is created when building the project. Look for a Tutor2.mot file in the C:\Renesas\SKP16C26A\Sample_Code\Tutor2\ Tutor2\Debug’ folder.
1. From the ‘Build Menu’,
select ‘Build Phases’
2. Make sure the ‘M16C Load
Module Converter’ is
enabled.
3. Click <OK>
32HEW4 M16C/Tiny Tutorial 2
14 March 2005
End of Lab 3End of Lab 3