Introduction
Purpose
This training module provides an overview of debugging
features in H8S Simulator.
Objectives
Understand how to use the Simulator.
Explore various debugging features: CPU status, registers,
memory, breakpoints, and stepping.
Content
21 pages 3 questions
Learning Time
2
© 2008, Renesas Technology America, Inc., All Rights Reserved
H8S Simulator
What is a simulator?
A software development tool that runs on a PC and substitutes for the MCU
Represents the MCU architecture and operating instructions
Advantages of a simulator
Enables debugging when target hardware is not available Helps reduce overall embedded system development time
H8S Simulator functions
CPU instructions Memory access Register access
Complementary HEW features
Help make the H8S Simulator more “hardware-like”
Include simulated I/O, Trigger, and TCL toolkit
Before Debugging Session Begins
1.Begin Project Generation 2.Select the Target CPU
3.Set the Target System for Debugging
Selecting this option
automatically generates a simulator session
4
© 2008, Renesas Technology America, Inc., All Rights Reserved
/********************************************************/ /* TUTORIAL PROGRAM */ /********************************************************/ #include <machine.h>
#include "string.h" #define NAME (short)0 #define AGE (short)1 #define ID (short)2 #define LENGTH 8
const char LED[]={0x12, 0x12, 0x11}; struct namelist {
char name[LENGTH]; short age;
long idcode; };
struct namelist section1[] = {
"Naoko", 17, 1234, "Midori", 22, 8888, "Rie", 19, 7777, "Eri", 20, 9999, "Kyoko", 26, 3333, "", 0, 0 }; int count; void sort(); void main(void) { count = 0; for ( ; ; ){ sort(section1, NAME); count++; sort(section1, AGE); count++; sort(section1, ID); count++; } }
void sort(list, key) struct namelist list[]; short key;
{
short i,j,k; long min; char *name;
struct namelist worklist;
switch(key){
case NAME :
for (i = 0 ; *list[i].name != 0 ; i++){ name = list[i].name; k = i;
for (j = i+1 ; *list[j].name != 0 ; j++){
if (strcmp(list[j].name , name) < 0){ name = list[j].name; k = j; } } worklist = list[i]; list[i] = list[k]; list[k] = worklist; } break; case AGE :
for (i = 0 ; list[i].age != 0 ; i++){ min = list[i].age; k = i;
for (j = i+1 ; list[j].age != 0 ; j++){
if (list[j].age < min){ min = list[j].age; k = j; } } worklist = list[i]; list[i] = list[k]; list[k] = worklist; } break; case ID :
for (i = 0 ; list[i].idcode != 0 ; i++){ min = list[i].idcode; k = i;
for (j = i+1 ; list[j].idcode != 0 ; j++){
if (list[j].idcode < min){ min = list[j].idcode; k = j; } } worklist = list[i]; list[i] = list[k]; list[k] = worklist; } break; } }
Example: Tutorial program with sorting routine is used for simulation
Enter Code
In it ia li z a ti o n M a in S o rtBasic Debugging
6
© 2008, Renesas Technology America, Inc., All Rights Reserved
Basic Debugging: View Menu
View
Debug
Display assembly code
View CPU registers View memory
View peripheral registers View CPU status
View simulated I/O
View/configure simulated interrupts View/configure labels View/modify variables View/modify local variables
Basic Debugging: Debug Menu
View
Debug
Execute code
Reset CPU and execute code
Execute until PC reaches the cursor position Set PC value and execute
Display PC value Step into deeper level Step to the next line
Step out to the higher level
PROPERTIES
On passing, 'Finish' button: Goes to Next Slide
On failing, 'Finish' button: Goes to Slide
Allow user to leave quiz: After user has completed quiz
User may view slides after quiz: After passing quiz
Download Module
1. Right click and select
“Download module” to load module into simulator target
2. After downloading, the Simulator displays starting address for each line of C code
10
© 2008, Renesas Technology America, Inc., All Rights Reserved
View Status
1. Select to view CPU status
2. Status window shows memory and downloaded module information
Disassembly
1. Select “Disassembly” to view corresponding assembly code 2. Right-click on “Disassembly” and select “Set Address” to set the starting address 3. Enter “000800” and click OK12
© 2008, Renesas Technology America, Inc., All Rights Reserved
View Assembly Instructions
4. Disassembly window shows assembly code, starting from
Registers Window
2. Register values can be edited directly in the Registers window
1. Select to open Registers window
14
© 2008, Renesas Technology America, Inc., All Rights Reserved
Watch Window
2. Right-click in Watch window and select “Add Watch”
3. Enter “section1”
and click OK 4. View values of “section1” array in Watch window 1. Select to open
Examine Memory Content
1. Select to view memory content
3. Memory window appears. (Values of “section1” won’t be updated until “Reset Go” is executed)
2. Enter address of “section1” (from Watch window)
16
© 2008, Renesas Technology America, Inc., All Rights Reserved
Set and View Breakpoints
1. Right-click on line, then select “Toggle Breakpoint”
3. Select to open Eventpoint
window
4. See all breakpoints in program
PROPERTIES
On passing, 'Finish' button: Goes to Next Slide
18
© 2008, Renesas Technology America, Inc., All Rights Reserved
Execute Program
1. Select “Reset Go” to begin executing
program 2. Execution stops at breakpoint. (Yellow arrow indicates current position of program counter.)
3. Register values are
updated in Registers window. (Program counter value
corresponds to
position marked by yellow arrow in Edit menu.)
Content of Memory Window
20
© 2008, Renesas Technology America, Inc., All Rights Reserved
Stepping Through the Code
HEW also supports flexible stepping, which is accessible from the “Step . . .” menu option.
Three basic levels of stepping:
Step In
- Takes you deeper into function call - Moves PC to start of sub-function
Step Over
- Executes current line of source code, including all instructions in sub-function - Moves PC to next line
Step Out
- Lets you go back to next-higher level of code; i.e., return from the function call
Step In
2. Arrow in Edit window shows program counter position at the beginning of the called function after stepping Example: 3. Registers window updates program counter value
If source line does not call a function, a Step-In operation is the same as a Step-Over operation.
1. Select “Step In” to go deeper into function call
22
© 2008, Renesas Technology America, Inc., All Rights Reserved
Step Over
2. Arrow in Edit window shows program counter position after stepping
3. Registers window updates program counter value
1. Select “Step Over” to step to the next line
Example:
If source line does not call a function, a Step-In operation is the same as a Step-Over operation.
Step Out
2. Arrow in Edit window shows program counter position at the next line of the calling function after stepping
1. Select “Step Out” to go back to next higher level of code
Example:
3. Registers window updates program counter value
Before Step Out
24
© 2008, Renesas Technology America, Inc., All Rights Reserved
Track Variable in Watch Window
2. “Step Over” to next line
1. Add the variable “count” to Watch window
3. Value of “count” is updated in Watch window
Breakpoint
PROPERTIES
On passing, 'Finish' button: Goes to Next Slide
26
© 2008, Renesas Technology America, Inc., All Rights Reserved
Definition of a simulator
Key features of H8S Simulator
Using H8S features for debugging
Course Summary
Download a free evaluation copy of HEW at: