IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 ·...

321
IAR Embedded Workbench ® C-SPY ® Debugging Guide for the Renesas RX Family UCSRX-3

Transcript of IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 ·...

Page 1: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

UCSRX-3

IAR Embedded Workbench®

C-SPY® Debugging Guide

for the RenesasRX Family

UCSRX-3

Page 2: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

UCSRX-3

COPYRIGHT NOTICECopyright © 2011–2012 IAR Systems AB.

No part of this document may be reproduced without the prior written consent of IAR Systems AB. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license.

DISCLAIMERThe information in this document is subject to change without notice and does not represent a commitment on any part of IAR Systems. While the information contained herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors or omissions.

In no event shall IAR Systems, its employees, its contractors, or the authors of this document be liable for special, direct, indirect, or consequential damage, losses, costs, charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind.

TRADEMARKSIAR Systems, IAR Embedded Workbench, C-SPY, visualSTATE, The Code to Success, IAR KickStart Kit, I-jet, IAR, and the logotype of IAR Systems are trademarks or registered trademarks owned by IAR Systems AB.

Microsoft and Windows are registered trademarks of Microsoft Corporation.

Renesas is a registered trademark of Renesas Electronics Corporation. RX is a trademark of Renesas Electronics Corporation.

Adobe and Acrobat Reader are registered trademarks of Adobe Systems Incorporated.

All other product names are trademarks or registered trademarks of their respective owners.

EDITION NOTICE

Third edition: May 2012

Part number: UCSRX-3

This guide applies to version 2.x of IAR Embedded Workbench® for the Renesas RX family.

The C-SPY® Debugging Guide for RX replaces all debugging information in the IAR Embedded Workbench IDE User Guide, the C-SPY® Power Debugging Guide for RX, and the IAR C-SPY® Hardware Debugger Systems User Guide for RX.

Internal reference: M12, Too6.4, tut2009.1, IJOA.

Page 3: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Brief contentsTables ...................................................................................................................... 15

Figures .................................................................................................................... 17

Preface .................................................................................................................... 21

The IAR C-SPY Debugger ........................................................................... 27

Getting started using C-SPY ....................................................................... 39

Executing your application ........................................................................... 65

Working with variables and expressions .............................................. 87

Using breakpoints ........................................................................................... 103

Monitoring memory and registers ........................................................ 131

Collecting and using trace data ............................................................... 159

Using the profiler ............................................................................................ 179

Analyzing code performance .................................................................... 189

Debugging in the power domain ............................................................ 197

Code coverage ................................................................................................. 211

Interrupts ............................................................................................................ 215

Using C-SPY macros ................................................................................... 233

The C-SPY Command Line Utility—cspybat ................................... 277

Debugger options ........................................................................................... 291

Additional information on C-SPY drivers .......................................... 301

Index ..................................................................................................................... 309

UCSRX-3

3

Page 4: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

4

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 5: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

ContentsTables ...................................................................................................................... 15

Figures .................................................................................................................... 17

Preface .................................................................................................................... 21

Who should read this guide ............................................................... 21

How to use this guide ........................................................................... 21

What this guide contains ..................................................................... 22

Other documentation ........................................................................... 23

User and reference guides .................................................................. 23

The online help system ...................................................................... 24

Web sites ............................................................................................ 24

Document conventions ........................................................................ 24

Typographic conventions ................................................................... 25

Naming conventions .......................................................................... 25

The IAR C-SPY Debugger ........................................................................... 27

Introduction to C-SPY .......................................................................... 27

An integrated environment ................................................................. 27

General C-SPY debugger features ..................................................... 28

RTOS awareness ................................................................................ 29

Debugger concepts ................................................................................ 30

C-SPY and target systems .................................................................. 30

The debugger ...................................................................................... 31

The target system ............................................................................... 31

The application ................................................................................... 31

C-SPY debugger systems ................................................................... 31

The ROM-monitor program ............................................................... 31

Third-party debuggers ........................................................................ 32

C-SPY plugin modules ....................................................................... 32

C-SPY drivers overview ....................................................................... 32

Differences between the C-SPY drivers ........................................... 33

UCSRX-3

5

Page 6: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

6

The IAR C-SPY Simulator .................................................................. 33

Features .............................................................................................. 33

Selecting the simulator driver ............................................................ 34

The C-SPY E1/E20 driver .................................................................... 34

Communication overview .................................................................. 34

Hardware installation ......................................................................... 35

The C-SPY J-Link driver ...................................................................... 36

Communication overview .................................................................. 36

Hardware installation ......................................................................... 37

Getting started using C-SPY ....................................................................... 39

Setting up C-SPY .................................................................................... 39

Setting up for debugging .................................................................... 39

Executing from reset .......................................................................... 40

Using a setup macro file ..................................................................... 40

Selecting a device description file ..................................................... 41

Loading plugin modules ..................................................................... 41

Starting C-SPY ......................................................................................... 41

Starting the debugger ......................................................................... 42

Loading executable files built outside of the IDE .............................. 42

Starting a debug session with source files missing ............................ 42

Loading multiple images .................................................................... 43

Start debugging a running application ............................................. 44

Adapting for target hardware ........................................................... 45

Modifying a device description file ................................................... 45

Initializing target hardware before C-SPY starts ............................... 46

Running example projects .................................................................. 46

Running an example project .............................................................. 47

Reference information on starting C-SPY ................................... 48

C-SPY Debugger main window ......................................................... 48

Images window .................................................................................. 53

Get Alternative File dialog box .......................................................... 54

Download Emulator Firmware dialog box ......................................... 55

Operating Frequency dialog box ........................................................ 56

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 7: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Contents

Hardware Setup dialog box (E1/E20) ................................................ 57

Hardware Setup dialog box (J-Link) .................................................. 61

External Area dialog box ................................................................... 63

Address Range dialog box ................................................................. 64

Executing your application ........................................................................... 65

Introduction to application execution ........................................... 65

Briefly about application execution ................................................... 65

Source and disassembly mode debugging ......................................... 65

Single stepping ................................................................................... 66

Running the application ..................................................................... 68

Highlighting ....................................................................................... 68

Call stack information ........................................................................ 69

Terminal input and output .................................................................. 70

Debug logging .................................................................................... 70

Reference information on application execution ..................... 70

Disassembly window ......................................................................... 71

Call Stack window ............................................................................. 75

Terminal I/O window ......................................................................... 77

Terminal I/O Log File dialog box ...................................................... 78

Debug Log window ............................................................................ 79

Log File dialog box ............................................................................ 80

Report Assert dialog box .................................................................... 81

Start/Stop Function Settings dialog box ............................................. 82

Select Label dialog box ...................................................................... 84

Autostep settings dialog box .............................................................. 85

ID Code Verification dialog box ........................................................ 85

Working with variables and expressions .............................................. 87

Introduction to working with variables and expressions ...... 87

Briefly about working with variables and expressions ...................... 87

C-SPY expressions ............................................................................. 88

Limitations on variable information .................................................. 90

Procedures for working with variables and expressions ....... 91

Using the windows related to variables and expressions ................... 91

UCSRX-3

7

Page 8: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

8

Viewing assembler variables ............................................................. 91

Reference information on working with variables and expressions ................................................................................................ 92

Auto window ...................................................................................... 93

Locals window ................................................................................... 93

Watch window ................................................................................... 94

Live Watch window ........................................................................... 95

Statics window ................................................................................... 96

Select Statics dialog box .................................................................... 98

Quick Watch window ......................................................................... 99

Symbols window .............................................................................. 100

Resolve Symbol Ambiguity dialog box ........................................... 101

Using breakpoints ........................................................................................... 103

Introduction to setting and using breakpoints ........................ 103

Reasons for using breakpoints ......................................................... 103

Briefly about setting breakpoints ..................................................... 104

Breakpoint types .............................................................................. 104

Breakpoint icons .............................................................................. 106

Breakpoints in the C-SPY simulator ................................................ 106

Breakpoints in the C-SPY hardware drivers .................................... 106

Breakpoint consumers ...................................................................... 107

Procedures for setting breakpoints .............................................. 108

Various ways to set a breakpoint ..................................................... 108

Toggling a simple code breakpoint .................................................. 109

Setting breakpoints using the dialog box ......................................... 109

Setting a data breakpoint in the Memory window ........................... 110

Setting breakpoints using system macros ........................................ 111

Useful breakpoint hints .................................................................... 112

Reference information on breakpoints ....................................... 113

Breakpoints window ........................................................................ 114

Breakpoint Usage dialog box ........................................................... 116

Code breakpoints dialog box ............................................................ 117

Hardware Code Breakpoint dialog box ............................................ 118

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 9: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Contents

Software Code Breakpoint dialog box ............................................. 120

Log breakpoints dialog box .............................................................. 121

Data breakpoints dialog box (simulator) .......................................... 123

Data breakpoints dialog box (E1/E20 and J-Link) ........................... 125

Immediate breakpoints dialog box ................................................... 127

Enter Location dialog box ................................................................ 128

Resolve Source Ambiguity dialog box ............................................ 129

Monitoring memory and registers ........................................................ 131

Introduction to monitoring memory and registers ............... 131

Briefly about monitoring memory and registers .............................. 131

C-SPY memory zones ...................................................................... 133

Stack display .................................................................................... 134

Memory access checking ................................................................. 135

Reference information on memory and registers .................. 135

Memory window .............................................................................. 136

Memory Save dialog box ................................................................. 140

Memory Restore dialog box ............................................................. 141

Fill dialog box .................................................................................. 141

RAM Monitor Setup dialog box ...................................................... 143

Edit RAM monitor block dialog box ............................................... 144

Symbolic Memory window .............................................................. 145

Stack window ................................................................................... 147

Register window .............................................................................. 150

SFR Setup window ........................................................................... 151

Edit SFR dialog box ......................................................................... 154

Memory Access Setup dialog box ................................................... 155

Edit Memory Access dialog box ...................................................... 157

Collecting and using trace data ............................................................... 159

Introduction to using trace .............................................................. 159

Reasons for using trace .................................................................... 159

Briefly about trace ............................................................................ 159

Requirements for using trace ........................................................... 160

UCSRX-3

9

Page 10: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

10

Procedures for using trace ............................................................... 160

Getting started with trace in the C-SPY simulator ........................... 160

Getting started with trace in the C-SPY hardware debugger drivers 161

Trace data collection using breakpoints ........................................... 161

Searching in trace data ..................................................................... 162

Browsing through trace data ............................................................ 162

Reference information on trace ..................................................... 163

Trace Settings dialog box ................................................................. 163

Trace window ................................................................................... 165

Function Trace window ................................................................... 167

Timeline window ............................................................................. 168

Viewing Range dialog box ............................................................... 173

Trace Start breakpoints dialog box .................................................. 174

Trace Stop breakpoints dialog box ................................................... 175

Trace Expressions window .............................................................. 176

Find in Trace dialog box .................................................................. 177

Find in Trace window ...................................................................... 178

Using the profiler ............................................................................................ 179

Introduction to the profiler .............................................................. 179

Reasons for using the profiler .......................................................... 179

Briefly about the profiler .................................................................. 179

Requirements for using the profiler ................................................. 180

Procedures for using the profiler ................................................... 181

Getting started using the profiler on function level ......................... 181

Getting started using the profiler on instruction level ...................... 182

Selecting a time interval for profiling information .......................... 183

Reference information on the profiler ........................................ 185

Function Profiler window ................................................................ 185

Analyzing code performance .................................................................... 189

Introduction to performance analysis ......................................... 189

Reasons for using performance analysis .......................................... 189

Briefly about performance analysis ................................................. 189

Requirements for performance analysis ........................................... 190

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 11: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Contents

Procedures for analyzing performance ....................................... 190

Using performance analysis ............................................................. 190

Reference information on performance analysis .................... 191

Performance Analysis Setup dialog box ......................................... 191

Performance Analysis window ........................................................ 193

Performance Start breakpoints dialog box ....................................... 195

Performance Stop breakpoints dialog box ....................................... 196

Debugging in the power domain ............................................................ 197

Introduction to power debugging .................................................. 197

Reasons for using power debugging ................................................ 197

Briefly about power debugging ........................................................ 197

Requirements for power debugging ................................................. 199

Optimizing your source code for power consumption ........ 199

Waiting for device status .................................................................. 199

Software delays ................................................................................ 199

DMA versus polled I/O .................................................................... 199

Low-power mode diagnostics .......................................................... 200

CPU frequency ................................................................................. 200

Detecting mistakenly unattended peripherals .................................. 201

Peripheral units in an event-driven system ...................................... 201

Finding conflicting hardware setups ................................................ 203

Analog interference .......................................................................... 203

Procedures for power debugging .................................................. 203

Displaying the application’s

power profile and analyzing the result ............................................. 204

Detecting unexpected power usage during application execution ... 205

Reference information on power debugging ............................ 205

Power Setup window ....................................................................... 206

Power Log window .......................................................................... 207

Code coverage ................................................................................................. 211

Introduction to code coverage ....................................................... 211

Reasons for using code coverage ..................................................... 211

Briefly about code coverage ............................................................ 211

UCSRX-3

11

Page 12: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

12

Requirements for using code coverage ............................................ 211

Reference information on code coverage .................................. 212

Code Coverage window ................................................................... 212

Interrupts ............................................................................................................ 215

Introduction to interrupts ................................................................ 215

Briefly about interrupt logging ........................................................ 215

Briefly about the interrupt simulation system .................................. 216

Interrupt characteristics .................................................................... 217

Interrupt simulation states ................................................................ 217

C-SPY system macros for interrupt simulation ............................... 219

Target-adapting the interrupt simulation system ............................. 220

Procedures for interrupts ................................................................. 220

Simulating a simple interrupt ........................................................... 221

Simulating an interrupt in a multi-task system ................................ 222

Reference information on interrupts ........................................... 223

Interrupt Setup dialog box ................................................................ 223

Edit Interrupt dialog box .................................................................. 225

Forced Interrupt window .................................................................. 226

Interrupt Status window ................................................................... 227

Interrupt Log window ...................................................................... 229

Interrupt Log Summary window ...................................................... 231

Using C-SPY macros ................................................................................... 233

Introduction to C-SPY macros ....................................................... 233

Reasons for using C-SPY macros .................................................... 233

Briefly about using C-SPY macros .................................................. 234

Briefly about setup macro functions and files ................................. 234

Briefly about the macro language .................................................... 235

Procedures for using C-SPY macros ............................................ 235

Registering C-SPY macros—an overview ....................................... 236

Executing C-SPY macros—an overview ......................................... 236

Using the Macro Configuration dialog box ..................................... 237

Registering and executing using setup macros and setup files ........ 238

Executing macros using Quick Watch ............................................ 239

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 13: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Contents

Executing a macro by connecting it to a breakpoint ........................ 240

Reference information on the macro language ....................... 241

Macro functions ............................................................................... 241

Macro variables ................................................................................ 242

Macro strings .................................................................................... 242

Macro statements ............................................................................. 243

Formatted output .............................................................................. 244

Reference information on reserved setup macro function names ......................................................................................................... 246

Reference information on C-SPY system macros .................. 247

The C-SPY Command Line Utility—cspybat ................................... 277

Using C-SPY in batch mode ............................................................. 277

Invocation syntax ............................................................................. 277

Output ............................................................................................... 278

Using an automatically generated batch file .................................... 279

Summary of C-SPY command line options .............................. 279

General cspybat options ................................................................... 279

Options available for all C-SPY drivers .......................................... 279

Options available for the simulator driver ....................................... 280

Options available for all C-SPY hardware drivers ........................... 280

Options available for the E1/E20 driver .......................................... 280

Options available for the J-Link driver ............................................ 280

Reference information on C-SPY command line options ... 280

Debugger options ........................................................................................... 291

Setting debugger options .................................................................. 291

Reference information on debugger options ............................ 292

Setup ................................................................................................. 292

Images .............................................................................................. 294

Extra Options ................................................................................... 295

Plugins .............................................................................................. 295

Reference information on C-SPY driver options .................... 297

Setup options for the simulator ....................................................... 297

Communication ............................................................................... 298

UCSRX-3

13

Page 14: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

14

Download ........................................................................................ 298

JTAG Scan Chain ............................................................................ 300

Additional information on C-SPY drivers .......................................... 301

Reference information on the C-SPY driver menus ............. 301

Simulator menu ................................................................................ 301

E1/E20 Emulator menu .................................................................... 303

J-Link menu ..................................................................................... 304

Resolving problems .............................................................................. 306

Write failure during load .................................................................. 306

No contact with the target hardware ................................................ 307

Index ..................................................................................................................... 309

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 15: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Tables1: Typographic conventions used in this guide ......................................................... 25

2: Naming conventions used in this guide ................................................................ 25

3: Driver differences .................................................................................................. 33

4: Restrictions on registers and flags ......................................................................... 82

5: MCU status when the user application starts executing ........................................ 83

6: C-SPY assembler symbols expressions ................................................................ 89

7: Handling name conflicts between hardware registers and assembler labels ......... 89

8: Effects of display format setting on different types of expressions .................... 95

9: Effects of display format setting on different types of expressions .................... 97

10: Available breakpoints in C-SPY hardware drivers ........................................... 107

11: C-SPY macros for breakpoints .......................................................................... 111

12: Device-specific memory zones ......................................................................... 133

13: Supported graphs in the Timeline window ....................................................... 169

14: C-SPY driver profiling support ....................................................................... 181

15: Project options for enabling the profiler ........................................................... 181

16: Project options for enabling code coverage ...................................................... 212

17: Timer interrupt settings ..................................................................................... 222

18: Examples of C-SPY macro variables ................................................................ 242

19: C-SPY setup macros ......................................................................................... 246

20: Summary of system macros .............................................................................. 247

21: __cancelInterrupt return values ......................................................................... 249

22: __disableInterrupts return values ...................................................................... 250

23: __driverType return values ............................................................................... 251

24: __enableInterrupts return values ....................................................................... 251

25: __evaluate return values ................................................................................... 252

26: __isBatchMode return values ........................................................................... 252

27: __loadImage return values ................................................................................ 253

28: __openFile return values ................................................................................... 256

29: __readFile return values ................................................................................... 258

30: __setCodeBreak return values .......................................................................... 262

31: __setDataBreak return values ........................................................................... 264

UCSRX-3

15

Page 16: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

16

32: __setLogBreak return values ............................................................................ 265

33: __setSimBreak return values ............................................................................ 266

34: __setTraceStartBreak return values .................................................................. 267

35: __setTraceStopBreak return values .................................................................. 269

36: __sourcePosition return values ......................................................................... 269

37: __unloadImage return values ............................................................................ 272

38: cspybat parameters ............................................................................................ 277

39: Options specific to the C-SPY drivers you are using ........................................ 291

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 17: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Figures1: C-SPY and target systems ..................................................................................... 30

2: C-SPY E1/E20 communication overview ............................................................. 35

3: Overview of C-SPY J-Link communication with J-Link probe ........................... 37

4: Get Alternative File dialog box ............................................................................. 43

5: Connect the emulator alert .................................................................................... 44

6: ID Code Verification dialog box ........................................................................... 45

7: Example applications ............................................................................................ 47

8: Debug menu .......................................................................................................... 50

9: Images window ..................................................................................................... 53

10: Images window context menu ............................................................................. 54

11: Get Alternative File dialog box ........................................................................... 54

12: Download Emulator Firmware dialog box .......................................................... 55

13: Operating Frequency dialog box ......................................................................... 56

14: Hardware Setup dialog box (E1/E20) ................................................................. 57

15: Hardware Setup dialog box (J-Link) ................................................................... 61

16: External Area dialog box .................................................................................... 63

17: Address Range dialog box .................................................................................. 64

18: C-SPY highlighting source location .................................................................... 69

19: C-SPY Disassembly window .............................................................................. 71

20: Disassembly window context menu .................................................................... 73

21: Call Stack window .............................................................................................. 75

22: Call Stack window context menu ........................................................................ 76

23: Terminal I/O window .......................................................................................... 77

24: Ctrl codes menu ................................................................................................... 77

25: Input Mode dialog box ........................................................................................ 78

26: Terminal I/O Log File dialog box ....................................................................... 78

27: Debug Log window (message window) .............................................................. 79

28: Debug Log window context menu ...................................................................... 79

29: Log File dialog box ............................................................................................. 80

30: Report Assert dialog box ..................................................................................... 81

31: Start/Stop Function Settings dialog box .............................................................. 82

UCSRX-3

17

Page 18: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

18

32: Select Label dialog box ....................................................................................... 84

33: Autostep settings dialog box ............................................................................... 85

34: ID Code Verification dialog box ......................................................................... 85

35: Viewing assembler variables in the Watch window ........................................... 92

36: Auto window ....................................................................................................... 93

37: Locals window .................................................................................................... 93

38: Watch window .................................................................................................... 94

39: Watch window context menu .............................................................................. 94

40: Live Watch window ............................................................................................ 95

41: Statics window .................................................................................................... 96

42: Statics window context menu .............................................................................. 97

43: Select Statics dialog box ..................................................................................... 98

44: Quick Watch window .......................................................................................... 99

45: Symbols window ............................................................................................... 100

46: Symbols window context menu ........................................................................ 100

47: Resolve Symbol Ambiguity dialog box ............................................................ 101

48: Breakpoint icons ................................................................................................ 106

49: Modifying breakpoints via the context menu .................................................... 110

50: Breakpoints window .......................................................................................... 114

51: Breakpoints window context menu ................................................................... 114

52: Breakpoint Usage dialog box ............................................................................ 116

53: Code breakpoints dialog box ............................................................................. 117

54: Hardware Code breakpoints dialog box ............................................................ 118

55: Software Code breakpoints dialog box ............................................................. 120

56: Log breakpoints dialog box ............................................................................... 121

57: Data breakpoints dialog box .............................................................................. 123

58: Data breakpoints dialog box (E1/E20 and J-Link) ............................................ 125

59: Immediate breakpoints dialog box .................................................................... 127

60: Enter Location dialog box ................................................................................. 128

61: Resolve Source Ambiguity dialog box ............................................................. 129

62: Zones in C-SPY ................................................................................................. 133

63: Memory window ............................................................................................... 136

64: Memory window context menu ........................................................................ 138

65: Memory Save dialog box .................................................................................. 140

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 19: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Figures

66: Memory Restore dialog box .............................................................................. 141

67: Fill dialog box ................................................................................................... 141

68: RAM Monitor Setup dialog box ....................................................................... 143

69: Edit RAM monitor block dialog box ................................................................ 144

70: Symbolic Memory window ............................................................................... 145

71: Symbolic Memory window context menu ........................................................ 146

72: Stack window .................................................................................................... 147

73: Stack window context menu ............................................................................. 149

74: Register window ................................................................................................ 150

75: SFR Setup window ............................................................................................ 151

76: SFR Setup window context menu ..................................................................... 153

77: Edit SFR dialog box .......................................................................................... 154

78: Memory Access Setup dialog box ..................................................................... 155

79: Edit Memory Access dialog box ....................................................................... 157

80: Trace Settings dialog box .................................................................................. 163

81: The Trace window in the simulator .................................................................. 165

82: Function Trace window ..................................................................................... 167

83: C-SPY Simulator Timeline window ................................................................. 168

84: Timeline window context menu for the Call Stack Graph ................................ 170

85: Viewing Range dialog box ................................................................................ 173

86: Trace Start breakpoints dialog box ................................................................... 174

87: Trace Stop breakpoints dialog box .................................................................... 175

88: Trace Expressions window ............................................................................... 176

89: Find in Trace dialog box ................................................................................... 177

90: Find in Trace window ....................................................................................... 178

91: Instruction count in Disassembly window ........................................................ 183

92: Power Graph with a selected time interval ....................................................... 184

93: Function Profiler window in time-interval mode .............................................. 184

94: Function Profiler window ................................................................................. 185

95: Function Profiler window context menu ........................................................... 188

96: Performance Analysis Setup dialog box ........................................................... 191

97: Performance Analysis window ......................................................................... 193

98: Performance Start breakpoints dialog box ........................................................ 195

99: Performance Stop breakpoints dialog box ........................................................ 196

UCSRX-3

19

Page 20: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

20

100: Power consumption in an event-driven system ............................................... 202

101: A noise spike recorded by an oscilloscope ..................................................... 203

102: Power Setup window ....................................................................................... 206

103: Power Setup window context menu ................................................................ 207

104: Power Log window ......................................................................................... 207

105: Power Log window context menu ................................................................... 209

106: Code Coverage window .................................................................................. 212

107: Code coverage window context menu ............................................................ 214

108: Simulated interrupt configuration ................................................................... 217

109: Simulation states - example 1 ......................................................................... 218

110: Simulation states - example 2 ......................................................................... 219

111: Interrupt Setup dialog box ............................................................................... 223

112: Edit Interrupt dialog box ................................................................................. 225

113: Forced Interrupt window ................................................................................. 226

114: Interrupt Status window .................................................................................. 227

115: Interrupt Log window ..................................................................................... 229

116: Interrupt Log window context menu ............................................................... 230

117: Interrupt Log Summary window ..................................................................... 231

118: Macro Configuration dialog box ..................................................................... 237

119: Quick Watch window ...................................................................................... 239

120: Debugger setup options ................................................................................... 292

121: Debugger images options ................................................................................ 294

122: Debugger extra options ................................................................................... 295

123: Debugger plugin options ................................................................................. 295

124: Simulator setup options ................................................................................... 297

125: E1/E20 communication options ...................................................................... 298

126: C-SPY Download options ............................................................................... 298

127: J-Link JTAG Scan Chain options ................................................................... 300

128: Simulator menu ............................................................................................... 301

129: The E1/E20 Emulator menu ............................................................................ 303

130: The J-Link menu ............................................................................................. 304

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 21: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

PrefaceWelcome to the C-SPY® Debugging Guide for RX. The purpose of this guide is to help you fully use the features in the IAR C-SPY® Debugger for debugging your application based on the RX microcontroller.

Who should read this guideRead this guide if you want to get the most out of the features available in C-SPY. In addition, you should have working knowledge of:

● The C or C++ programming language

● Application development for embedded systems

● The architecture and instruction set of the RX microcontroller (refer to the chip manufacturer's documentation)

● The operating system of your host computer.

For more information about the other development tools incorporated in the IDE, refer to their respective documentation, see Other documentation, page 23.

How to use this guideIf you are new to using IAR Embedded Workbench, we suggest that you first read the guide Getting Started with IAR Embedded Workbench® for an overview of the tools and the features that the IDE offers.

If you already have had some experience using IAR Embedded Workbench, but need refreshing on how to work with the IAR Systems development tools, the tutorials which you can find in the IAR Information Center is a good place to begin. The process of managing projects and building, as well as editing, is described in the IDE Project Management and Building Guide, whereas information about how to use C-SPY for debugging is described in this guide.

This guide describes a number of topics, where each topic section contains an introduction which also covers concepts related to the topic. This will give you a good understanding of the features in C-SPY. Furthermore, the topic section provides procedures with step-by-step descriptions to help you use the features. Finally, each topic section gives all relevant reference information.

UCSRX-3

21

Page 22: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

22

What this guide contains

We also recommend the Glossary which you can find in the IDE Project Management and Building Guide if you should encounter any unfamiliar terms in the IAR Systems user and reference guides.

What this guide containsThis is a brief outline and summary of the chapters in this guide:

● The IAR C-SPY Debugger introduces you to the C-SPY debugger and to the concepts that are related to debugging in general and to C-SPY in particular. The chapter also introduces the various C-SPY drivers. The chapter briefly shows the difference in functionality that the various C-SPY drivers provide.

● Getting started using C-SPY helps you get started using C-SPY, which includes setting up, starting, and adapting C-SPY for target hardware.

● Executing your application describes the conceptual differences between source and disassembly mode debugging, the facilities for executing your application, and finally, how you can handle terminal input and output.

● Working with variables and expressions describes the syntax of the expressions and variables used in C-SPY, as well as the limitations on variable information. The chapter also demonstrates the various methods for monitoring variables and expressions.

● Using breakpoints describes the breakpoint system and the various ways to set breakpoints.

● Monitoring memory and registers shows how you can examine memory and registers.

● Collecting and using trace data describes how you can inspect the program flow up to a specific state using trace data.

● Using the profiler describes how the profiler can help you find the functions in your application source code where the most time is spent during execution.

● Analyzing code performance describes how to use a C-SPY hardware debugger to analyze code performance in terms of time, clock cycles, interrupts, exceptions, and instructions.

● Debugging in the power domain describes hardware solutions for measuring power consumption and how you can use them from C-SPY to find source code constructions that result in power leaks.

● Code coverage describes how the code coverage functionality can help you verify whether all parts of your code have been executed, thus identifying parts which have not been executed.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 23: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Preface

● Interrupts contains detailed information about the C-SPY interrupt simulation system and how to configure the simulated interrupts to make them reflect the interrupts of your target hardware.

● Using C-SPY macros describes the C-SPY macro system, its features, the purposes of these features, and how to use them.

● The C-SPY Command Line Utility—cspybat describes how to use C-SPY in batch mode.

● Debugger options describes the options you must set before you start the C-SPY debugger.

● Additional information on C-SPY drivers describes menus and topics not described elsewhere.

Other documentationUser documentation is available as hypertext PDFs and as a context-sensitive online help system in HTML format. You can access the documentation from the Information Center or from the Help menu in the IAR Embedded Workbench IDE. The online help system is also available via the F1 key.

USER AND REFERENCE GUIDES

The complete set of IAR Systems development tools is described in a series of guides. For information about:

● System requirements and information about how to install and register the IAR Systems products, refer to the booklet Quick Reference (available in the product box) and the Installation and Licensing Guide.

● Getting started using IAR Embedded Workbench and the tools it provides, see the guide Getting Started with IAR Embedded Workbench®.

● Using the IDE for project management and building, see the IDE Project Management and Building Guide.

● Programming for the IAR C/C++ Compiler for RX and linking using the IAR ILINK Linker, see the IAR C/C++ Development Guide for RX.

● Programming for the IAR Assembler for RX, see the IAR Assembler Reference Guide for RX.

● Using the IAR DLIB Library, see the DLIB Library Reference information, available in the online help system.

● Developing safety-critical applications using the MISRA C guidelines, see the IAR Embedded Workbench® MISRA C:2004 Reference Guide or the IAR Embedded Workbench® MISRA C:1998 Reference Guide.

UCSRX-3

23

Page 24: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

24

Document conventions

Note: Additional documentation might be available depending on your product installation.

THE ONLINE HELP SYSTEM

The context-sensitive online help contains:

● Comprehensive information about debugging using the IAR C-SPY® Debugger

● Reference information about the menus, windows, and dialog boxes in the IDE

● Compiler reference information

● Keyword reference information for the DLIB library functions. To obtain reference information for a function, select the function name in the editor window and press F1.

WEB SITES

Recommended web sites:

● The Renesas web site, www.renesas.com, contains information and news about the RX microcontrollers.

● The IAR Systems web site, www.iar.com, holds application notes and other product information.

● The web site of the C standardization working group, www.open-std.org/jtc1/sc22/wg14.

● The web site of the C++ Standards Committee, www.open-std.org/jtc1/sc22/wg21.

● Finally, the Embedded C++ Technical Committee web site, www.caravan.net/ec2plus, contains information about the Embedded C++ standard.

Document conventions When, in this text, we refer to the programming language C, the text also applies to C++, unless otherwise stated.

When referring to a directory in your product installation, for example rx\doc, the full path to the location is assumed, for example c:\Program Files\IAR Systems\Embedded Workbench 6.n\rx\doc.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 25: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Preface

TYPOGRAPHIC CONVENTIONS

This guide uses the following typographic conventions:

NAMING CONVENTIONS

The following naming conventions are used for the products and tools from IAR Systems® referred to in this guide:

Style Used for

computer • Source code examples and file paths.• Text on the command line.• Binary, hexadecimal, and octal numbers.

parameter A placeholder for an actual value used as a parameter, for example filename.h where filename represents the name of the file.

[option] An optional part of a command.

[a|b|c] An optional part of a command with alternatives.

{a|b|c} A mandatory part of a command with alternatives.

bold Names of menus, menu commands, buttons, and dialog boxes that appear on the screen.

italic • A cross-reference within this guide or to another guide.• Emphasis.

… An ellipsis indicates that the previous item can be repeated an arbitrary number of times.

Identifies instructions specific to the IAR Embedded Workbench® IDE interface.

Identifies instructions specific to the command line interface.

Identifies helpful tips and programming hints.

Identifies warnings.

Table 1: Typographic conventions used in this guide

Brand name Generic term

IAR Embedded Workbench® for RX IAR Embedded Workbench®

IAR Embedded Workbench® IDE for RX the IDE

IAR C-SPY® Debugger for RX C-SPY, the debugger

IAR C-SPY® Simulator the simulator

IAR C/C++ Compiler™ for RX the compiler

Table 2: Naming conventions used in this guide

UCSRX-3

25

Page 26: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

26

Document conventions

IAR Assembler™ for RX the assembler

IAR ILINK Linker™ ILINK, the linker

IAR DLIB Library™ the DLIB library

Brand name Generic term

Table 2: Naming conventions used in this guide (Continued)

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 27: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The IAR C-SPY DebuggerThis chapter introduces you to the IAR C-SPY® Debugger and to the concepts that are related to debugging in general and to C-SPY in particular. The chapter also introduces the various C-SPY drivers. More specifically, this means:

● Introduction to C-SPY

● Debugger concepts

● C-SPY drivers overview

● The IAR C-SPY Simulator

● The C-SPY E1/E20 driver

● The C-SPY J-Link driver.

Introduction to C-SPYThis section covers these topics:

● An integrated environment

● General C-SPY debugger features

● RTOS awareness.

AN INTEGRATED ENVIRONMENT

C-SPY is a high-level-language debugger for embedded applications. It is designed for use with the IAR Systems compilers and assemblers, and is completely integrated in the IDE, providing development and debugging within the same application. This will give you possibilities such as:

● Editing while debugging. During a debug session, you can make corrections directly in the same source code window that is used for controlling the debugging. Changes will be included in the next project rebuild.

● Setting breakpoints at any point during the development cycle. You can inspect and modify breakpoint definitions also when the debugger is not running, and breakpoint definitions flow with the text as you edit. Your debug settings, such as

UCSRX-3

27

Page 28: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

28

Introduction to C-SPY

watch properties, window layouts, and register groups will be preserved between your debug sessions.

All windows that are open in the Embedded Workbench workspace will stay open when you start the C-SPY Debugger. In addition, a set of C-SPY-specific windows are opened.

GENERAL C-SPY DEBUGGER FEATURES

Because IAR Systems provides an entire toolchain, the output from the compiler and linker can include extensive debug information for the debugger, resulting in good debugging possibilities for you.

C-SPY offers these general features:

● Source and disassembly level debugging

C-SPY allows you to switch between source and disassembly debugging as required, for both C or C++ and assembler source code.

● Single-stepping on a function call level

Compared to traditional debuggers, where the finest granularity for source level stepping is line by line, C-SPY provides a finer level of control by identifying every statement and function call as a step point. This means that each function call—inside expressions, and function calls that are part of parameter lists to other functions—can be single-stepped. The latter is especially useful when debugging C++ code, where numerous extra function calls are made, for example to object constructors.

● Code and data breakpoints

The C-SPY breakpoint system lets you set breakpoints of various kinds in the application being debugged, allowing you to stop at locations of particular interest. For example, you set breakpoints to investigate whether your program logic is correct or to investigate how and when the data changes.

● Monitoring variables and expressions

For variables and expressions there is a wide choice of facilities. Any variable and expression can be evaluated in one-shot views. You can easily both monitor and log values of a defined set of expressions during a longer period of time. You have instant control over local variables, and real-time data is displayed non-intrusively. Finally, the last referred variables are displayed automatically.

● Container awareness

When you run your application in C-SPY, you can view the elements of library data types such as STL lists and vectors. This gives you a very good overview and debugging opportunities when you work with C++ STL containers.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 29: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The IAR C-SPY Debugger

● Call stack information

The compiler generates extensive call stack information. This allows the debugger to show, without any runtime penalty, the complete stack of function calls wherever the program counter is. You can select any function in the call stack, and for each function you get valid information for local variables and available registers.

● Powerful macro system

C-SPY includes a powerful internal macro system, to allow you to define complex sets of actions to be performed. C-SPY macros can be used on their own or in conjunction with complex breakpoints and—if you are using the simulator—the interrupt simulation system to perform a wide variety of tasks.

Additional general C-SPY debugger features

This list shows some additional features:

● Threaded execution keeps the IDE responsive while running the target application

● Automatic stepping

● The source browser provides easy navigation to functions, types, and variables

● Extensive type recognition of variables

● Configurable registers (CPU and peripherals) and memory windows

● Graphical stack view with overflow detection

● Support for code coverage and function level profiling

● The target application can access files on the host PC using file I/O

● Optional terminal I/O emulation.

RTOS AWARENESS

C-SPY supports real-time OS aware debugging.

RTOS plugin modules can be provided by IAR Systems, and by third-party suppliers. Contact your software distributor or IAR Systems representative, alternatively visit the IAR Systems web site, for information about supported RTOS modules.

Provided that one or more real-time operating system plugin modules are supported for the IAR Embedded Workbench version you are using, you can load one for use with C-SPY. A C-SPY RTOS awareness plugin module gives you a high level of control and visibility over an application built on top of a real-time operating system. It displays RTOS-specific items like task lists, queues, semaphores, mailboxes, and various RTOS system variables. Task-specific breakpoints and task-specific stepping make it easier to debug tasks.

A loaded plugin will add its own menu, set of windows, and buttons when a debug session is started (provided that the RTOS is linked with the application). For

UCSRX-3

29

Page 30: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

30

Debugger concepts

information about other RTOS awareness plugin modules, refer to the manufacturer of the plugin module.

Debugger conceptsThis section introduces some of the concepts and terms that are related to debugging in general and to C-SPY in particular. This section does not contain specific information related to C-SPY features. Instead, you will find such information in each chapter of this part of the documentation. The IAR Systems user documentation uses the terms described in this section when referring to these concepts.

C-SPY AND TARGET SYSTEMS

You can use C-SPY to debug either a software target system or a hardware target system.

This figure gives an overview of C-SPY and possible target systems:

Figure 1: C-SPY and target systems

Note: In IAR Embedded Workbench for RX, there are no ROM-monitor drivers.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 31: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The IAR C-SPY Debugger

THE DEBUGGER

The debugger, for instance C-SPY, is the program that you use for debugging your applications on a target system.

THE TARGET SYSTEM

The target system is the system on which you execute your application when you are debugging it. The target system can consist of hardware, either an evaluation board or your own hardware design. It can also be completely or partially simulated by software. Each type of target system needs a dedicated C-SPY driver.

THE APPLICATION

A user application is the software you have developed and which you want to debug using C-SPY.

C-SPY DEBUGGER SYSTEMS

C-SPY consists of both a general part which provides a basic set of debugger features, and a target-specific back end. The back end consists of two components: a processor module—one for every microcontroller, which defines the properties of the microcontroller, and a C-SPY driver. The C-SPY driver is the part that provides communication with and control of the target system. The driver also provides the user interface—menus, windows, and dialog boxes—to the functions provided by the target system, for instance, special breakpoints. Typically, there are three main types of C-SPY drivers:

● Simulator driver

● ROM-monitor driver

● Emulator driver.

C-SPY is available with a simulator driver, and depending on your product package, optional drivers for hardware debugger systems. For an overview of the available C-SPY drivers and the functionality provided by each driver, see C-SPY drivers overview, page 32.

THE ROM-MONITOR PROGRAM

The ROM-monitor program is a piece of firmware that is loaded to non-volatile memory on your target hardware; it runs in parallel with your application. The ROM-monitor

UCSRX-3

31

Page 32: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

32

C-SPY drivers overview

communicates with the debugger and provides services needed for debugging the application, for instance stepping and breakpoints.

THIRD-PARTY DEBUGGERS

You can use a third-party debugger together with the IAR Systems toolchain as long as the third-party debugger can read ELF/DWARF, Intel-extended, or Motorola. For information about which format to use with a third-party debugger, see the user documentation supplied with that tool.

C-SPY PLUGIN MODULES

C-SPY is designed as a modular architecture with an open SDK that can be used for implementing additional functionality to the debugger in the form of plugin modules. These modules can be seamlessly integrated in the IDE.

Plugin modules are provided by IAR Systems, or can be supplied by third-party vendors. Examples of such modules are:

● Code Coverage and the Stack window, both integrated in the IDE.

● The various C-SPY drivers for debugging using certain debug systems.

● RTOS plugin modules for support for real-time OS aware debugging.

● C-SPYLink that bridges IAR visualSTATE and IAR Embedded Workbench to make true high-level state machine debugging possible directly in C-SPY, in addition to the normal C level symbolic debugging. For more information, refer to the documentation provided with IAR visualSTATE.

For more information about the C-SPY SDK, contact IAR Systems.

C-SPY drivers overviewAt the time of writing this guide, the IAR C-SPY Debugger for the RX microcontrollers is available with drivers for these target systems and evaluation boards:

● Simulator

● E1 or E20 emulator

● J-Link debug probe.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 33: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The IAR C-SPY Debugger

DIFFERENCES BETWEEN THE C-SPY DRIVERS

This table summarizes the key differences between the C-SPY drivers:

1 For detailed information about available breakpoints, see Breakpoints in the C-SPY hardware drivers, page 106.2 Supported in RAM Monitor mode for areas configured in the RAM Monitor Setup dialog box, see RAM Monitor Setup dialog box, page 143.3 Includes a cycle counter.4 Requires the separate J-Link debug probe. Not supported by the built-in J-Link.

The IAR C-SPY SimulatorThe C-SPY Simulator simulates the functions of the target processor entirely in software, which means that you can debug the program logic long before any hardware is available. Because no hardware is required, it is also the most cost-effective solution for many applications.

FEATURES

In addition to the general features in C-SPY, the simulator also provides:

● Instruction-level simulation

Feature Simulator E1 E20 J-Link

Code breakpoints Unlimited x1 x1 x

Data breakpoints x x x x

Execution in real time — x x x

Zero memory footprint x x x x

Simulated interrupts x — — —

Real interrupts — x x x

Interrupt logging x — — —

Live watch x x x x

Cycle counter x — — —

Code coverage x x x x

Data coverage x — x2 —

Performance analysis — x3 x3 x3

Start/stop routines — x x —

Profiling x x x x

Trace x x x x

Power debugging — — — x4

Table 3: Driver differences

UCSRX-3

33

Page 34: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

34

The C-SPY E1/E20 driver

● Memory configuration and validation

● Interrupt simulation

● Peripheral simulation (using the C-SPY macro system in conjunction with immediate breakpoints).

SELECTING THE SIMULATOR DRIVER

Before starting C-SPY, you must choose the simulator driver:

1 In the IDE, choose Project>Options and click the Setup tab in the Debugger category.

2 Choose Simulator from the Driver drop-down list.

The C-SPY E1/E20 driverThe C-SPY E1/E20 driver is automatically installed during the installation of IAR Embedded Workbench. Using the C-SPY E1/E20 driver, C-SPY can connect to an E1 or E20 emulator. All RX microcontrollers have built-in, on-chip debug support. Because the hardware debugger logic is built into the microcontroller, no ordinary ROM-monitor program or extra specific hardware is needed to make the debugging work.

COMMUNICATION OVERVIEW

The C-SPY E1/E20 driver uses USB to communicate with the E1 or E20 emulator. The E1 or E20 emulator communicates with the Front-end firmware (FFW) interface

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 35: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The IAR C-SPY Debugger

module. The FFW interface module, in turn, communicates with the Back-end firmware (BFW) module on the emulator.

Figure 2: C-SPY E1/E20 communication overview

For more information, see the documentation supplied with the E1 or E20 emulator.

When a debugging session is started, your application is automatically downloaded and programmed into flash memory. You can disable this feature, if necessary.

HARDWARE INSTALLATION

USB drivers are automatically installed during the installation of IAR Embedded Workbench. If you need to re-install them, they are available both on the installation CD and in the rx\drivers\Renesas\ directory in the installation directory.

For more information about the hardware installation, see the documentation supplied with the E1 or E20 emulator from Renesas. The following power-up sequence is

UCSRX-3

35

Page 36: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

36

The C-SPY J-Link driver

recommended to ensure proper communication between the target board, E1 or E20 emulator, and C-SPY:

1 Power up the target board.

2 Start the C-SPY debugging session.

The C-SPY J-Link driverThe C-SPY J-Link driver is automatically installed during the installation of IAR Embedded Workbench. Using the C-SPY J-Link driver, C-SPY can connect to the J-Link debug probe. All RX microcontrollers have built-in, on-chip debug support. Because the hardware debugger logic is built into the microcontroller, no ordinary ROM-monitor program or extra specific hardware is needed to make the debugging work.

COMMUNICATION OVERVIEW

The C-SPY J-Link driver uses USB to communicate. There are two possible hardware configurations, depending on the target board:

● If the target board has a built-in J-Link, a USB cable connects the host computer directly to the target board.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 37: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The IAR C-SPY Debugger

● If you have a separate J-Link debug probe, the probe communicates with the JTAG interface on the microcontroller as in this figure:

Figure 3: Overview of C-SPY J-Link communication with J-Link probe

For more information, see the documentation supplied with the J-Link debug probe or the target board.

When a debugging session is started, your application is automatically downloaded and programmed into flash memory. You can disable this feature, if necessary.

HARDWARE INSTALLATION

For information about the hardware installation, see the documentation supplied with the J-Link debug probe. The following power-up sequence is recommended to ensure proper communication between the target board, debug probe, and C-SPY:

1 Power up the target board.

2 Power up the J-Link debug probe.

3 Start the C-SPY debugging session.

UCSRX-3

37

Page 38: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

38

The C-SPY J-Link driver

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 39: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPYThis chapter helps you get started using C-SPY®. More specifically, this means:

● Setting up C-SPY

● Starting C-SPY

● Adapting for target hardware

● Running example projects

● Reference information on starting C-SPY.

Setting up C-SPYThis section describes the steps involved for setting up C-SPY.

More specifically, you will get information about:

● Setting up for debugging

● Executing from reset

● Using a setup macro file

● Selecting a device description file

● Loading plugin modules.

SETTING UP FOR DEBUGGING

1 Before you start C-SPY, choose Project>Options>Debugger>Setup and select the C-SPY driver that matches your debugger system: simulator or a hardware debugger system.

2 In the Category list, select the appropriate C-SPY driver and make your settings.

For information about these options, see Debugger options, page 291.

3 Click OK.

UCSRX-3

39

Page 40: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

40

Setting up C-SPY

4 Choose Tools>Options>Debugger to configure:

● The debugger behavior

● The debugger’s tracking of stack usage.

For more information about these options, see the IDE Project Management and Building Guide.

See also Adapting for target hardware, page 45.

EXECUTING FROM RESET

The Run to option—available on the Debugger>Setup page—specifies a location you want C-SPY to run to when you start the debugger as well as after each reset. C-SPY will place a temporary breakpoint at this location and all code up to this point is executed before stopping at the location.

The default location to run to is the main function. Type the name of the location if you want C-SPY to run to a different location. You can specify assembler labels or whatever can be evaluated to such, for instance function names.

If you leave the check box empty, the program counter will then contain the regular hardware reset address at each reset.

If no breakpoints are available when C-SPY starts, a warning message notifies you that single stepping will be required and that this is time-consuming. You can then continue execution in single-step mode or stop at the first instruction. If you choose to stop at the first instruction, the debugger starts executing with the PC (program counter) at the default reset location instead of the location you typed in the Run to box.

Note: This message will never be displayed in the C-SPY Simulator, where breakpoints are not limited.

USING A SETUP MACRO FILE

A setup macro file is a macro file that you choose to load automatically when C-SPY starts. You can define the setup macro file to perform actions according to your needs, using setup macro functions and system macros. Thus, if you load a setup macro file you can initialize C-SPY to perform actions automatically.

For more information about setup macro files and functions, see Briefly about setup macro functions and files, page 234. For an example of how to use a setup macro file, see the chapter Initializing target hardware before C-SPY starts, page 46.

To register a setup macro file:

1 Before you start C-SPY, choose Project>Options>Debugger>Setup.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 41: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

2 Select Use macro file and type the path and name of your setup macro file, for example Setup.mac. If you do not type a filename extension, the extension mac is assumed.

SELECTING A DEVICE DESCRIPTION FILE

C-SPY uses device description files to handle device-specific information.

A default device description file is automatically used based on your project settings. If you want to override the default file, you must select your device description file. Device description files are provided in the rx\config directory and they have the filename extension ddf.

For more information about device description files, see Adapting for target hardware, page 45.

To override the default device description file:

1 Before you start C-SPY, choose Project>Options>Debugger>Setup.

2 Enable the use of a device description file and select a file using the Device description file browse button.

LOADING PLUGIN MODULES

On the Plugins page you can specify C-SPY plugin modules to load and make available during debug sessions. Plugin modules can be provided by IAR Systems, and by third-party suppliers. Contact your software distributor or IAR Systems representative, or visit the IAR Systems web site, for information about available modules.

For more information, see Plugins, page 295.

Starting C-SPYWhen you have set up the debugger, you are ready to start a debug session; this section describes the steps involved.

More specifically, you will get information about:

● Starting the debugger

● Loading executable files built outside of the IDE

● Starting a debug session with source files missing

● Loading multiple images

● Start debugging a running application.

UCSRX-3

41

Page 42: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

42

Starting C-SPY

STARTING THE DEBUGGER

You can choose to start the debugger with or without loading the current project.

To start C-SPY and load the current project, click the Download and Debug button. Alternatively, choose Project>Download and Debug.

To start C-SPY without reloading the current project, click the Debug without Downloading button. Alternatively, choose Project>Debug without Downloading.

LOADING EXECUTABLE FILES BUILT OUTSIDE OF THE IDE

You can also load C-SPY with an application that was built outside the IDE, for example applications built on the command line. To load an externally built executable file and to set build options you must first create a project for it in your workspace.

To create a project for an externally built file:

1 Choose Project>Create New Project, and specify a project name.

2 To add the executable file to the project, choose Project>Add Files and make sure to choose All Files in the Files of type drop-down list. Locate the executable file.

3 To start the executable file, click the Download and Debug button. The project can be reused whenever you rebuild your executable file.

The only project options that are meaningful to set for this kind of project are options in the General Options and Debugger categories. Make sure to set up the general project options in the same way as when the executable file was built.

STARTING A DEBUG SESSION WITH SOURCE FILES MISSING

Normally, when you use the IAR Embedded Workbench IDE to edit source files, build your project, and start the debug session, all required files are available and the process works as expected.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 43: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

However, if C-SPY cannot automatically find the source files, for example if the application was built on another computer, the Get Alternative File dialog box is displayed:

Figure 4: Get Alternative File dialog box

Typically, you can use the dialog box like this:

● The source files are not available: Click If possible, don’t show this dialog again and then click Skip. C-SPY will assume that there simply is no source file available. The dialog box will not appear again, and the debug session will not try to display the source code.

● Alternative source files are available at another location: Specify an alternative source code file, click If possible, don’t show this dialog again, and then click Use this file. C-SPY will assume that the alternative file should be used. The dialog box will not appear again, unless a file is needed for which there is no alternative file specified and which cannot be located automatically.

If you restart the IAR Embedded Workbench IDE, the Get Alternative File dialog box will be displayed again once even if you have clicked If possible, don’t show this dialog again. This gives you an opportunity to modify your previous settings.

For more information, see Get Alternative File dialog box, page 54.

LOADING MULTIPLE IMAGES

Normally, a debuggable application consists of exactly one file that you debug. However, you can also load additional debug files (images). This means that the complete program consists of several images.

Typically, this is useful if you want to debug your application in combination with a prebuilt ROM image that contains an additional library for some platform-provided features. The ROM image and the application are built using separate projects in the IAR Embedded Workbench IDE and generate separate output files.

UCSRX-3

43

Page 44: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

44

Starting C-SPY

If more than one image has been loaded, you will have access to the combined debug information for all the loaded images. In the Images window you can choose whether you want to have access to debug information for one image or for all images.

To load additional images at C-SPY startup:

1 Choose Project>Options>Debugger>Images and specify up to three additional images to be loaded. For more information, see Images, page 294.

2 Start the debug session.

To load additional images at a specific moment:

Use the __loadImage system macro and execute it using either one of the methods described in Procedures for using C-SPY macros, page 235.

To display a list of loaded images:

Choose Images from the View menu. The Images window is displayed, see Images window, page 53.

START DEBUGGING A RUNNING APPLICATION

Using an E1 or E20 emulator, you can start debugging a running application at its current location, without resetting the target system.

Start debugging from the middle of execution

1 Choose Project>Options>E1/E20>Download and select the option Attach to program, see Attach to program, page 299.

2 Make sure that the target board is powered by external power and disconnect the emulator from the target board.

3 Choose Project>Download and Debug or click the Download and Debug toolbar button.

4 When you are prompted, connect the emulator to the target board and click OK.

Figure 5: Connect the emulator alert

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 45: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

5 Enter the ID code of the target MCU in the ID Code Verification dialog box.

Figure 6: ID Code Verification dialog box

6 When the debug session starts, your application is still executing but now you can monitor RAM and look at variables in the Live Watch window.

7 To stop execution, click Stop or set a breakpoint.

8 You can now debug your application as usual.

Adapting for target hardwareThis section provides information about how to describe the target hardware to C-SPY, and how you can make C-SPY initialize the target hardware before your application is downloaded to memory.

More specifically, you will get information about:

● Modifying a device description file

● Initializing target hardware before C-SPY starts.

MODIFYING A DEVICE DESCRIPTION FILE

C-SPY uses device description files provided with the product to handle several of the target-specific adaptations, see Selecting a device description file, page 41. They contain device-specific information such as:

● Memory information for device-specific memory zones, see C-SPY memory zones, page 133

● Definitions of memory-mapped peripheral units, device-specific CPU registers, and groups of these

● The device name and the MCU filename, used by emulators

● Definitions for device-specific interrupts, which makes it possible to simulate these interrupts in the C-SPY simulator; see Interrupts, page 215.

Normally, you do not need to modify the device description file. However, if the predefinitions are not sufficient for some reason, you can edit the file. Note, however,

UCSRX-3

45

Page 46: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

46

Running example projects

that the format of these descriptions might be updated in future upgrade versions of the product.

Make a copy of the device description file that best suits your needs, and modify it according to the description in the file.

For information about how to load a device description file, see Selecting a device description file, page 41.

INITIALIZING TARGET HARDWARE BEFORE C-SPY STARTS

If your hardware uses external memory that must be enabled before code can be downloaded to it, C-SPY needs a macro to perform this action before your application can be downloaded. For example:

1 Create a new text file and define your macro function. For example, a macro that enables external SDRAM might look like this:

/* Your macro function. */enableExternalSDRAM(){ __message "Enabling external SDRAM\n"; __writeMemory32( /* Place your code here. */ ); /* And more code here, if needed. */}

/* Setup macro determines time of execution. */execUserPreload(){ enableExternalSDRAM();}

Because the built-in execUserPreload setup macro function is used, your macro function will be executed directly after the communication with the target system is established but before C-SPY downloads your application.

2 Save the file with the filename extension mac.

3 Before you start C-SPY, choose Project>Options>Debugger and click the Setup tab.

4 Select the option Use Setup file and choose the macro file you just created.

Your setup macro will now be loaded during the C-SPY startup sequence.

Running example projectsIAR Embedded Workbench comes with example applications. You can use these examples to get started using the development tools from IAR Systems or simply to

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 47: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

verify that contact has been established with your target board. You can also use the examples as a starting point for your application project.

You can find the examples in the rx\examples directory. The examples are ready to be used as is. They are supplied with ready-made workspace files, together with source code files and all other related files.

RUNNING AN EXAMPLE PROJECT

To run an example project:

1 Choose Help>Information Center and click EXAMPLE PROJECTS.

2 Browse to the example that matches the specific evaluation board or starter kit you are using.

Figure 7: Example applications

Click the Open Project button.

3 In the dialog box that appears, choose a destination folder for your project location. Click Select to confirm your choice.

4 The available example projects are displayed in the workspace window. Select one of the projects, and if it is not the active project (highlighted in bold), right-click it and choose Set As Active from the context menu.

5 To view the project settings, select the project and choose Options from the context menu. Verify the settings for Device and Debugger>Setup>Driver. As for other settings, the project is set up to suit the target system you selected.

UCSRX-3

47

Page 48: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

48

Reference information on starting C-SPY

For more information about the C-SPY options and how to configure C-SPY to interact with the target board, see Debugger options, page 291.

Click OK to close the project Options dialog box.

6 To compile and link the application, choose Project>Make or click the Make button.

7 To start C-SPY, choose Project>Debug or click the Download and Debug button. If C-SPY fails to establish contact with the target system, see Resolving problems, page 306.

8 Choose Debug>Go or click the Go button to start the application.

Click the Stop button to stop execution.

Reference information on starting C-SPYThis section gives reference information about these windows and dialog boxes:

● C-SPY Debugger main window, page 48

● Images window, page 53

● Get Alternative File dialog box, page 54

● Download Emulator Firmware dialog box, page 55

● Operating Frequency dialog box, page 56

● Hardware Setup dialog box (E1/E20), page 57

● Hardware Setup dialog box (J-Link), page 61

● External Area dialog box, page 63

● Address Range dialog box, page 64.

See also:

● Tools options for the debugger in the IDE Project Management and Building Guide.

C-SPY Debugger main windowWhen you start the debugger, these debugger-specific items appear in the main IAR Embedded Workbench IDE window:

● A dedicated Debug menu with commands for executing and debugging your application

● Depending on the C-SPY driver you are using, a driver-specific menu, often referred to as the Driver menu in this documentation. Typically, this menu contains menu commands for opening driver-specific windows and dialog boxes.

● A special debug toolbar

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 49: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

● Several windows and dialog boxes specific to C-SPY.

The C-SPY main window might look different depending on which components of the product installation you are using.

Menu bar

These menus are available when C-SPY is running:

Debug Provides commands for executing and debugging the source application, see Debug menu, page 50. Most of the commands are also available as icon buttons on the debug toolbar.

Simulator Provides access to the dialog boxes for setting up interrupt simulation and memory access checking. This menu is only available when the C-SPY Simulator has been selected, see Simulator menu, page 301.

E1/E20 Emulator Provides commands specific to the C-SPY E1/E20 driver. This menu is only available when the driver has been selected, see E1/E20 Emulator menu, page 303.

J-Link Provides commands specific to the C-SPY J-Link driver. This menu is only available when the driver has been selected, see J-Link menu, page 304.

UCSRX-3

49

Page 50: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

50

Reference information on starting C-SPY

Debug menu

The Debug menu is available when C-SPY is running. The Debug menu provides commands for executing and debugging the source application. Most of the commands are also available as icon buttons on the debug toolbar.

Figure 8: Debug menu

These commands are available:

Go F5

Executes from the current statement or instruction until a breakpoint or program exit is reached.

Break Stops the application execution.

Reset Resets the target processor.

Stop Debugging Ctrl+Shift+D

Stops the debugging session and returns you to the project manager.

Step OverF10

Executes the next statement, function call, or instruction, without entering C or C++ functions or assembler subroutines.

Step IntoF11

Executes the next statement or instruction, or function call, entering C or C++ functions or assembler subroutines.

Step OutShift+F11

Executes from the current statement up to the statement after the call to the current function.

Next Statement Executes directly to the next statement without stopping at individual function calls.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 51: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

Run to Cursor Executes from the current statement or instruction up to a selected statement or instruction.

Autostep Displays a dialog box where you can customize and perform autostepping, see Autostep settings dialog box, page 85.

Set Next Statement Moves the program counter directly to where the cursor is, without executing any source code. Note, however, that this creates an anomaly in the program flow and might have unexpected effects.

C++ Exceptions>Break on Throw

This menu command is not supported by your product package.

C++ Exceptions>Break on Uncaught Exception

This menu command is not supported by your product package.

Memory>Save Displays a dialog box where you can save the contents of a specified memory area to a file, see Memory Save dialog box, page 140.

Memory>Restore Displays a dialog box where you can load the contents of a file in Intel-extended or Motorola s-record format to a specified memory zone, see Memory Restore dialog box, page 141.

Refresh Refreshes the contents of all debugger windows. Because window updates are automatic, this is needed only in unusual situations, such as when target memory is modified in ways C-SPY cannot detect. It is also useful if code that is displayed in the Disassembly window is changed.

Macros Displays a dialog box where you can list, register, and edit your macro files and functions, see Using the Macro Configuration dialog box, page 237.

Logging>Set Log file Displays a dialog box where you can choose to log the contents of the Debug Log window to a file. You can select the type and the location of the log file. You can choose what you want to log: errors, warnings, system information, user messages, or all of these. See Log File dialog box, page 80.

Logging>Set Terminal I/O Log file

Displays a dialog box where you can choose to log simulated target access communication to a file. You can select the destination of the log file. See Terminal I/O Log File dialog box, page 78.

UCSRX-3

51

Page 52: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

52

Reference information on starting C-SPY

C-SPY windows

Depending on the C-SPY driver you are using, these windows specific to C-SPY are available when C-SPY is running:

● C-SPY Debugger main window

● Disassembly window

● Memory window

● Symbolic Memory window

● Register window

● Watch window

● Locals window

● Auto window

● Live Watch window

● Quick Watch window

● Statics window

● Call Stack window

● Trace window

● Function Trace window

● Timeline window

● Terminal I/O window

● Code Coverage window

● Function Profiler window

● Images window

● Stack window

● Symbols window.

Additional windows are available depending on which C-SPY driver you are using.

Editing in C-SPY windows

You can edit the contents of the Memory, Symbolic Memory, Register, Auto, Watch, Locals, Statics, Live Watch, and Quick Watch windows.

Use these keyboard keys to edit the contents of these windows:

Enter Makes an item editable and saves the new value.

Esc Cancels a new value.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 53: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

In windows where you can edit the Expression field, you can specify the number of elements to be displayed in the field by adding a semicolon followed by an integer. For example, to display only the three first elements of an array named myArray, or three elements in sequence starting with the element pointed to by a pointer, write:

myArray;3

Optionally, add a comma and another integer that specifies which element to start with. For example, to display elements 10–14, write:

myArray;5,10

Images windowThe Images window is available from the View menu.

Figure 9: Images window

The Images window lists all currently loaded images (debug files).

Normally, a source application consists of exactly one image that you debug. However, you can also load additional images. This means that the complete debuggable unit consists of several images.

Display area

This area lists the loaded images in these columns:

C-SPY can either use debug information from all of the loaded images simultaneously, or from one image at a time. Double-click on a row to show information only for that image. The current choice is highlighted.

Name The name of the loaded image.

Path The path to the loaded image.

UCSRX-3

53

Page 54: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

54

Reference information on starting C-SPY

Context menu

This context menu is available:

Figure 10: Images window context menu

These commands are available:

Related information

For related information, see:

● Loading multiple images, page 43

● Images, page 294

● __loadImage, page 253.

Get Alternative File dialog boxThe Get Alternative File dialog box is displayed if C-SPY cannot automatically find the source files to be loaded, for example if the application was built on another computer.

Figure 11: Get Alternative File dialog box

Could not find the following source file

The missing source file.

Suggested alternative

Specify an alternative file.

Show all images Shows debug information for all loaded debug images.

Show only image Shows debug information for the selected debug image.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 55: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

Use this file

After you have specified an alternative file, Use this file establishes that file as the alias for the requested file. Note that after you have chosen this action, C-SPY will automatically locate other source files if these files reside in a directory structure similar to the first selected alternative file.

The next time you start a debug session, the selected alternative file will be preloaded automatically.

Skip

C-SPY will assume that the source file is not available for this debug session.

If possible, don’t show this dialog again

Instead of displaying the dialog box again for a missing source file, C-SPY will use the previously supplied response.

Related information

For related information, see Starting a debug session with source files missing, page 42.

Download Emulator Firmware dialog boxThe Download Emulator Firmware dialog box is available from the Driver menu.

Figure 12: Download Emulator Firmware dialog box

This dialog box is available for the:

● C-SPY E1/E20 driver

● C-SPY J-Link driver.

Use this dialog box to update the firmware of your emulator if needed. The only reason for doing this manually is if the automatically downloaded firmware is not working correctly.

UCSRX-3

55

Page 56: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

56

Reference information on starting C-SPY

Firmware file

Browse to the firmware file on your host computer and click OK to download it to your emulator hardware. The emulator firmware files have the filename extension .s and are located in subdirectories of the rx\config\Renesas\ directory of your product installation.

Operating Frequency dialog boxThe Operating Frequency dialog box is available from the Driver menu during a debug session.

Figure 13: Operating Frequency dialog box

This dialog box is available for the:

● C-SPY E1/E20 driver

● C-SPY J-Link driver.

Use this dialog box to inform the emulator of the operating frequency that the MCU is running at.

Operating frequency

Specifies the operating frequency that the MCU is running at. This value is used by the performance analysis feature to convert cycles to time and by the J-Link Timeline window to estimate the number of elapsed cycles.

Related information

For related information, see:

● Performance Analysis Setup dialog box, page 191

● Timeline window, page 168.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 57: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

Hardware Setup dialog box (E1/E20)The Hardware Setup dialog box for E1/E20 emulators is available from the E1/E20 Emulator menu. Before C-SPY is started for the first time in a new project, and when you change devices, the hardware must be configured.

Figure 14: Hardware Setup dialog box (E1/E20)

Use this dialog box to make settings that control how the emulator operates.

Mode pin setting

Controls the MCU operation based on the pin settings. Choose between:

● Single-chip mode

● User boot mode

● USB boot mode.

Note: Not all modes are available for all devices.

UCSRX-3

57

Page 58: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

58

Reference information on starting C-SPY

Input clock (EXTAL)

Specify the frequency in MHz of the clock source that supplies the target MCU.

Byte order

Controls the byte order of the device. Choose between:

● Little-endian

● Big-endian.

Note: This option is not available for all devices.

Register setting

Controls the MCU operation based on register settings. Choose between:

● Single-chip mode

● On-chip ROM enabled extended mode

● On-chip ROM disabled extended mode.

Note: Not all modes are available for all devices.

External memory areas

Lists the defined external memory areas. To edit a memory area, select the area and click Edit to display the External Area dialog box, see External Area dialog box, page 63.

These columns are displayed:

No external memory areas are defined if the Register setting is Single-chip mode.

Allow clock source change when writing internal flash

Allows the clock source to change while internal flash memory is being rewritten in the emulator.

Work RAM start address

Specify the start address of the working RAM area for the debugger. The specified amount of bytes, beginning with the start address you specify, is used by the emulator

Area The name of the external memory area.

Byte order Identifies whether the byte order is the same as the byte order of the MCU or different.

BUS width The bus width of the area: 8, 16 or 32 bits.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 59: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

firmware. The debugger uses the memory area when programming the on-chip flash memory, so the working RAM must be within the on-chip RAM area.

Your application can also use this area (because memory data in this area will be saved on the host computer and then restored), but do not specify any address in this area as the origin or destination of a transfer by the DMA or DTC.

Internal flash memory overwrite

Protects one or more flash memory ranges from being erased by the downloading process, before the debug image is written to the target MCU. This means that any addresses that are not overwritten by the downloaded image will keep their previous contents.

To add a memory area, click Add to open the Address Range dialog box, see Address Range dialog box, page 64. To remove a memory area, select it and click Delete. These columns are displayed:

Communication

Controls the communication between the emulator and the host computer. Choose between:

Debug the program re-writing the PROGRAM ROM

Debugs the program which writes to the program ROM (flash memory).

Debug the program re-writing the DATA FLASH

Debugs the program which writes to the data flash memory.

Start address The start address of the memory area.

End address The end address of the memory area.

JTAG clock Selects the JTAG interface. Choose a communication clock frequency.

FINE baud rate Selects the FINE single wire debug interface. Choose a communication speed in bits/second.

UCSRX-3

59

Page 60: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

60

Reference information on starting C-SPY

Emulator mode

Controls how the emulator can be used. Choose between:

Power target from the emulator

Select this option and the correct voltage if you are supplying the target board with power from the E1/E20 emulator, and not from an external power supply.

If you select this option but connect an external power supply to the target board, the external power supply will be used instead and these settings will be ignored.

Trace Makes the trace functionality of the E1/E20 driver available, see Collecting and using trace data, page 159.

RAM Monitor Makes the RAM-monitor functionality of the E1/E20 driver available, see RAM Monitor Setup dialog box, page 143. Only available for the E20 emulator.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 61: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

Hardware Setup dialog box (J-Link)The Hardware Setup dialog box for the J-Link debug probe is available from the J-Link menu. Before C-SPY is started for the first time in a new project, and when you change devices, the hardware must be configured.

Figure 15: Hardware Setup dialog box (J-Link)

Use this dialog box to make settings that control how the emulator operates.

Mode

Controls the MCU operation. Choose between:

● Single-chip mode

● On-chip ROM enabled extended mode

● On-chip ROM disabled extended mode.

Note: Not all modes are available for all devices.

UCSRX-3

61

Page 62: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

62

Reference information on starting C-SPY

Input clock (EXTAL)

Specify the frequency in MHz of the clock source that supplies the target MCU.

External memory areas

Displays the defined external memory areas. To edit a memory area, select the area and click Edit to display the External Area dialog box, see External Area dialog box, page 63.

These columns are displayed:

No external memory areas are defined if the Register setting is Single-chip mode.

Work RAM start address

Specify the start address of the working RAM area for the debugger. The specified amount of bytes, beginning with the start address you specify, is used by the emulator firmware The debugger uses the memory area when programming the on-chip flash memory, so the working RAM must be within the on-chip RAM area.

Your application can also use this area (because memory data in this area will be saved on the host computer and then restored), but do not specify any address in this area as the origin or destination of a transfer by the DMA or DTC.

JTAG

Controls the communication speed between the emulator and the host computer.

Overwrite data in FLASH without erasing the FLASH area block

Disables the erasure of the entire flash area block performed by the download process, before the debug image is written to the target MCU. This means that any addresses that are not overwritten by the downloaded image will keep their previous contents.

Debug the program using the CPU rewrite mode

Select this option if debugging your application involves overwriting the contents of the on-chip flash memory (the program ROM area).

Area The name of the external memory area.

Byte order Identifies whether the byte order is the same as the byte order of the MCU or different.

BUS width The bus width of the area: 8, 16 or 32 bits.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 63: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Getting started using C-SPY

When debugging in CPU rewrite mode, the following limitations apply:

● Address match breakpoints cannot be set

● No software breakpoints can be set in the internal ROM area.

External Area dialog boxThe External Area dialog box is available from the Hardware Setup dialog box.

Figure 16: External Area dialog box

Use this dialog box to edit a defined external memory area, see External memory areas, page 58 (E1/E20) and External memory areas, page 62 (J-Link).

Byte order

Controls the byte order of the memory area. Choose between:

● Same byte order as the MCU

● Different byte order from the MCU.

Bus width

The bus width of the area. Choose between:

● 8 bit

● 16 bit

● 32 bit.

UCSRX-3

63

Page 64: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

64

Reference information on starting C-SPY

Address Range dialog boxThe Address Range dialog box is available by clicking Add in the Hardware Setup dialog box for E1/E20 emulators.

Figure 17: Address Range dialog box

Use this dialog box to set up internal flash memory areas in the Hardware Setup dialog box for E1/E20 emulators, see Internal flash memory overwrite, page 59.

Start address

Specify the start address of the memory range.

End address

Specify the end address of the memory range.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 65: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your applicationThis chapter contains information about executing your application in C-SPY®. More specifically, this means:

● Introduction to application execution

● Reference information on application execution.

Introduction to application executionThis section covers these topics:

● Briefly about application execution

● Source and disassembly mode debugging

● Single stepping

● Running the application

● Highlighting

● Call stack information

● Terminal input and output

● Debug logging.

BRIEFLY ABOUT APPLICATION EXECUTION

C-SPY allows you to monitor and control the execution of your application. By single-stepping through it, and setting breakpoints, you can examine details about the application execution, for example the values of variables and registers. You can also use the call stack to step back and forth in the function call chain.

The terminal I/O and debug log features let you interact with your application.

You can find commands for execution on the Debug menu and on the toolbar.

SOURCE AND DISASSEMBLY MODE DEBUGGING

C-SPY allows you to switch between source mode and disassembly mode debugging as needed.

Source debugging provides the fastest and easiest way of developing your application, without having to worry about how the compiler or assembler has implemented the

UCSRX-3

65

Page 66: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

66

Introduction to application execution

code. In the editor windows you can execute the application one statement at a time while monitoring the values of variables and data structures.

Disassembly mode debugging lets you focus on the critical sections of your application, and provides you with precise control of the application code. You can open a disassembly window which displays a mnemonic assembler listing of your application based on actual memory contents rather than source code, and lets you execute the application exactly one machine instruction at a time.

Regardless of which mode you are debugging in, you can display registers and memory, and change their contents.

SINGLE STEPPING

C-SPY allows more stepping precision than most other debuggers because it is not line-oriented but statement-oriented. The compiler generates detailed stepping information in the form of step points at each statement, and at each function call. That is, source code locations where you might consider whether to execute a step into or a step over command. Because the step points are located not only at each statement but also at each function call, the step functionality allows a finer granularity than just stepping on statements. There are four step commands:

● Step Into

● Step Over

● Next Statement

● Step Out.

Using the Autostep settings dialog box, you can automate the single stepping. For more information, Autostep settings dialog box, page 85.

Consider this example and assume that the previous step has taken you to the f(i) function call (highlighted):

extern int g(int);int f(int n){ value = g(n-1) + g(n-2) + g(n-3); return value; }int main(){ ... f(i); value ++;}

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 67: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Step Into

While stepping, you typically consider whether to step into a function and continue stepping inside the function or subroutine. The Step Into command takes you to the first step point within the subroutine g(n-1):

extern int g(int);int f(int n){ value = g(n-1) + g(n-2) + g(n-3); return value;}

The Step Into command executes to the next step point in the normal flow of control, regardless of whether it is in the same or another function.

Step Over

The Step Over command executes to the next step point in the same function, without stopping inside called functions. The command would take you to the g(n-2) function call, which is not a statement on its own but part of the same statement as g(n-1). Thus, you can skip uninteresting calls which are parts of statements and instead focus on critical parts:

extern int g(int);int f(int n){ value = g(n-1) + g(n-2) + g(n-3); return value;}

Next Statement

The Next Statement command executes directly to the next statement, in this case return value, allowing faster stepping:

extern int g(int);int f(int n){ value = g(n-1) + g(n-2) + g(n-3); return value;}

UCSRX-3

67

Page 68: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

68

Introduction to application execution

Step Out

When inside the function, you can—if you wish—use the Step Out command to step out of it before it reaches the exit. This will take you directly to the statement immediately after the function call:

extern int g(int);int f(int n){ value = g(n-1) + g(n-2) g(n-3); return value;}int main(){ ... f(i); value ++;}

The possibility of stepping into an individual function that is part of a more complex statement is particularly useful when you use C code containing many nested function calls. It is also very useful for C++, which tends to have many implicit function calls, such as constructors, destructors, assignment operators, and other user-defined operators.

This detailed stepping can in some circumstances be either invaluable or unnecessarily slow. For this reason, you can also step only on statements, which means faster stepping.

RUNNING THE APPLICATION

Go

The Go command continues execution from the current position until a breakpoint or program exit is reached.

Run to Cursor

The Run to Cursor command executes to the position in the source code where you have placed the cursor. The Run to Cursor command also works in the Disassembly window and in the Call Stack window.

HIGHLIGHTING

At each stop, C-SPY highlights the corresponding C or C++ source or instruction with a green color, in the editor and the Disassembly window respectively. In addition, a green arrow appears in the editor window when you step on C or C++ source level, and in the Disassembly window when you step on disassembly level. This is determined by

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 69: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

which of the windows is the active window. If none of the windows are active, it is determined by which of the windows was last active.

Figure 18: C-SPY highlighting source location

For simple statements without function calls, the whole statement is typically highlighted. When stopping at a statement with function calls, C-SPY highlights the first call because this illustrates more clearly what Step Into and Step Over would mean at that time.

Occasionally, you will notice that a statement in the source window is highlighted using a pale variant of the normal highlight color. This happens when the program counter is at an assembler instruction which is part of a source statement but not exactly at a step point. This is often the case when stepping in the Disassembly window. Only when the program counter is at the first instruction of the source statement, the ordinary highlight color is used.

CALL STACK INFORMATION

The compiler generates extensive backtrace information. This allows C-SPY to show, without any runtime penalty, the complete function call chain at any time.

Typically, this is useful for two purposes:

● Determining in what context the current function has been called

● Tracing the origin of incorrect values in variables and in parameters, thus locating the function in the call chain where the problem occurred.

The Call Stack window shows a list of function calls, with the current function at the top. When you inspect a function in the call chain, the contents of all affected windows are updated to display the state of that particular call frame. This includes the editor, Locals, Register, Watch and Disassembly windows. A function would normally not make use of all registers, so these registers might have undefined states and be displayed as dashes (---).

In the editor and Disassembly windows, a green highlight indicates the topmost, or current, call frame; a yellow highlight is used when inspecting other frames.

For your convenience, it is possible to select a function in the call stack and click the Run to Cursor command to execute to that function.

UCSRX-3

69

Page 70: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

70

Reference information on application execution

Assembler source code does not automatically contain any backtrace information. To see the call chain also for your assembler modules, you can add the appropriate CFI assembler directives to the assembler source code. For further information, see the IAR Assembler Reference Guide for RX.

TERMINAL INPUT AND OUTPUT

Sometimes you might have to debug constructions in your application that use stdin and stdout without an actual hardware device for input and output. The Terminal I/O window lets you enter input to your application, and display output from it. You can also direct terminal I/O to a file, using the Terminal I/O Log Files dialog box.

This facility is useful in two different contexts:

● If your application uses stdin and stdout

● For producing debug trace printouts.

For more information, see Terminal I/O window, page 77 and Terminal I/O Log File dialog box, page 78.

DEBUG LOGGING

The Debug Log window displays debugger output, such as diagnostic messages, macro-generated output, event log messages, and information about trace.

It can sometimes be convenient to log the information to a file where you can easily inspect it. The two main advantages are:

● The file can be opened in another tool, for instance an editor, so you can navigate and search within the file for particularly interesting parts

● The file provides history about how you have controlled the execution, for instance, which breakpoints that have been triggered etc.

Reference information on application executionThis section gives reference information about these windows and dialog boxes:

● Disassembly window, page 71

● Call Stack window, page 75

● Terminal I/O window, page 77

● Terminal I/O Log File dialog box, page 78

● Debug Log window, page 79

● Log File dialog box, page 80

● Report Assert dialog box, page 81

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 71: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

● Start/Stop Function Settings dialog box, page 82

● Autostep settings dialog box, page 85

● ID Code Verification dialog box, page 85.

See also Terminal I/O options in IDE Project Management and Building Guide.

Disassembly windowThe C-SPY Disassembly window is available from the View menu.

Figure 19: C-SPY Disassembly window

This window shows the application being debugged as disassembled application code.

To change the default color of the source code in the Disassembly window:

1 Choose Tools>Options>Debugger.

2 Set the default color using the Source code coloring in disassembly window option.

To view the corresponding assembler code for a function, you can select it in the editor window and drag it to the Disassembly window.

Go to memory address

Current position

Breakpoint

Zone display

Code coverage information

Toggle embeddedsource mode

UCSRX-3

71

Page 72: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

72

Reference information on application execution

Toolbar

The toolbar contains:

Display area

The display area shows the disassembled application code.

This area contains these graphic elements:

If instruction profiling has been enabled from the context menu, an extra column in the left-side margin appears with information about how many times each instruction has been executed.

Go to The location you want to view. This can be a memory address, or the name of a variable, function, or label.

Zone display Lists the available memory zones to display, see C-SPY memory zones, page 133.

Toggle Mixed-Mode Toggles between displaying only disassembled code or disassembled code together with the corresponding source code. Source code requires that the corresponding source file has been compiled with debug information.

Green highlight Indicates the current position, that is the next assembler instruction to be executed. To move the cursor to any line in the Disassembly window, click the line. Alternatively, move the cursor using the navigation keys.

Yellow highlight Indicates a position other than the current position, such as when navigating between frames in the Call Stack window or between items in the Trace window.

Red dot Indicates a breakpoint. Double-click in the gray left-side margin of the window to set a breakpoint. For more information, see Using breakpoints, page 103.

Green diamond Indicates code that has been executed—that is, code coverage.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 73: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Context menu

This context menu is available:

Figure 20: Disassembly window context menu

Note: The contents of this menu are dynamic, which means it looks different depending on the C-SPY driver.

All or some of these commands are available:

Move to PC Displays code at the current program counter location.

Run to Cursor Executes the application from the current position up to the line containing the cursor.

Code Coverage Displays a submenu that provides commands for controlling code coverage. This command is only enabled if the driver you are using supports it.

Enable, toggles code coverage on or off.Show, toggles the display of code coverage on or off.

Executed code is indicated by a green diamond.Clear, clears all code coverage information.

Instruction Profiling Displays a submenu that provides commands for controlling instruction profiling. This command is only enabled if the driver you are using supports it.

Enable, toggles instruction profiling on or off.Show, toggles the display of instruction profiling on or off.

For each instruction, the left-side margin displays how many times the instruction has been executed.

Clear, clears all instruction profiling information.

UCSRX-3

73

Page 74: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

74

Reference information on application execution

Toggle Breakpoint (Code)

Toggles a code breakpoint. Assembler instructions and any corresponding label at which code breakpoints have been set are highlighted in red. For more information, see Code breakpoints dialog box, page 117.

Toggle Breakpoint (Hardware Code)

Toggles a hardware code breakpoint. Assembler instructions and any corresponding label at which hardware code breakpoints have been set are highlighted in red. Note that this menu command is only available for C-SPY hardware debugger drivers. For more information, see Hardware Code Breakpoint dialog box, page 118.

Toggle Breakpoint (Software Code)

Toggles a software code breakpoint. Assembler instructions and any corresponding label at which software code breakpoints have been set are highlighted in red. Note that this menu command is only available for C-SPY hardware debugger drivers. For more information, see Software Code Breakpoint dialog box, page 120.

Toggle Breakpoint (Performance Start)

Toggles a performance start breakpoint. When the breakpoint is triggered, the performance analysis starts. Note that this menu command is only available if the C-SPY driver you are using supports performance analysis. For more information, see Performance Start breakpoints dialog box, page 195.

Toggle Breakpoint (Performance Stop)

Toggles a performance stop breakpoint. When the breakpoint is triggered, the performance analysis stops. Note that this menu command is only available if the C-SPY driver you are using supports performance analysis. For more information, see Performance Stop breakpoints dialog box, page 196.

Toggle Breakpoint (Log)

Toggles a log breakpoint for trace printouts. Assembler instructions at which log breakpoints have been set are highlighted in red. For more information, see Log breakpoints dialog box, page 121.

Toggle Breakpoint (Trace Start)

Toggles a Trace Start breakpoint. When the breakpoint is triggered, the trace data collection starts. Note that this menu command is only available if the C-SPY driver you are using supports trace. For more information, see Trace Start breakpoints dialog box, page 174.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 75: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Call Stack windowThe Call stack window is available from the View menu.

Figure 21: Call Stack window

This window displays the C function call stack with the current function at the top. To inspect a function call, double-click it. C-SPY now focuses on that call frame instead.

Toggle Breakpoint (Trace Stop)

Toggles a Trace Stop breakpoint. When the breakpoint is triggered, the trace data collection stops. Note that this menu command is only available if the C-SPY driver you are using supports trace. For more information, see Trace Stop breakpoints dialog box, page 175.

Enable/Disable Breakpoint

Enables and Disables a breakpoint. If there is more than one breakpoint at a specific line, all those breakpoints are affected by the Enable/Disable command.

Edit Breakpoint Displays the breakpoint dialog box to let you edit the currently selected breakpoint. If there is more than one breakpoint on the selected line, a submenu is displayed that lists all available breakpoints on that line.

Set Next Statement Sets the program counter to the address of the instruction at the insertion point.

Copy Window Contents

Copies the selected contents of the Disassembly window to the clipboard.

Mixed-Mode Toggles between showing only disassembled code or disassembled code together with the corresponding source code. Source code requires that the corresponding source file has been compiled with debug information.

Destination for Step Into

UCSRX-3

75

Page 76: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

76

Reference information on application execution

If the next Step Into command would step to a function call, the name of the function is displayed in the grey bar at the top of the window. This is especially useful for implicit function calls, such as C++ constructors, destructors, and operators.

Display area

Provided that the command Show Arguments is enabled, each entry in the display area has the format:

function(values)

where (values) is a list of the current value of the parameters, or empty if the function does not take any parameters.

Context menu

This context menu is available:

Figure 22: Call Stack window context menu

These commands are available:

Go to Source Displays the selected function in the Disassembly or editor windows.

Show Arguments Shows function arguments.

Run to Cursor Executes until return to the function selected in the call stack.

Toggle Breakpoint (Code) Toggles a code breakpoint.

Toggle Breakpoint (Log) Toggles a log breakpoint.

Enable/Disable Breakpoint Enables or disables the selected breakpoint.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 77: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Terminal I/O windowThe Terminal I/O window is available from the View menu.

Figure 23: Terminal I/O window

Use this window to enter input to your application, and display output from it.

To use this window, you must:

1 Include C-SPY debugging support.

C-SPY will then direct stdin, stdout and stderr to this window. If the Terminal I/O window is closed, C-SPY will open it automatically when input is required, but not for output.

Input

Type the text that you want to input to your application.

Ctrl codes

Opens a menu for input of special characters, such as EOF (end of file) and NUL.

Figure 24: Ctrl codes menu

UCSRX-3

77

Page 78: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

78

Reference information on application execution

Input Mode

Opens the Input Mode dialog box where you choose whether to input data from the keyboard or from a file.

Figure 25: Input Mode dialog box

For reference information about the options available in this dialog box, see Terminal I/O options in IDE Project Management and Building Guide.

Terminal I/O Log File dialog boxThe Terminal I/O Log File dialog box is available by choosing Debug>Logging>Set Terminal I/O Log File.

Figure 26: Terminal I/O Log File dialog box

Use this dialog box to select a destination log file for terminal I/O from C-SPY.

Terminal IO Log Files

Controls the logging of terminal I/O. To enable logging of terminal I/O to a file, select Enable Terminal IO log file and specify a filename. The default filename extension is log. A browse button is available for your convenience.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 79: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Debug Log windowThe Debug Log window is available by choosing View>Messages.

Figure 27: Debug Log window (message window)

This window displays debugger output, such as diagnostic messages, macro-generated output, event log messages, and information about trace. This output is only available when C-SPY is running. When opened, this window is, by default, grouped together with the other message windows, see the IDE Project Management and Building Guide.

Double-click any rows in one of the following formats to display the corresponding source code in the editor window:

<path> (<row>):<message><path> (<row>,<column>):<message>

Context menu

This context menu is available:

Figure 28: Debug Log window context menu

These commands are available:

Copy Copies the contents of the window.

Select All Selects the contents of the window.

Clear All Clears the contents of the window.

UCSRX-3

79

Page 80: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

80

Reference information on application execution

Log File dialog boxThe Log File dialog box is available by choosing Debug>Logging>Set Log File.

Figure 29: Log File dialog box

Use this dialog box to log output from C-SPY to a file.

Enable Log file

Enables or disables logging to the file.

Include

The information printed in the file is, by default, the same as the information listed in the Log window. To change the information logged, choose between:

Use the browse button, to override the default file and location of the log file (the default filename extension is log).

Errors C-SPY has failed to perform an operation.

Warnings An error or omission of concern.

Info Progress information about actions C-SPY has performed.

User Messages from C-SPY macros, that is, your messages using the __message statement.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 81: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Report Assert dialog boxThe Report Assert dialog box appears if you have a call to the assert function in your application source code, and the assert condition is false. In this dialog box you can choose how to proceed.

Figure 30: Report Assert dialog box

Abort

The application stops executing and the runtime library function abort, which is part of your application on the target system, will be called. This means that the application itself terminates its execution.

Debug

C-SPY stops the execution of the application and returns control to you.

Ignore

The assertion is ignored and the application continues to execute.

UCSRX-3

81

Page 82: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

82

Reference information on application execution

Start/Stop Function Settings dialog boxThe Start/Stop Function Settings dialog box is available from the C-SPY Driver menu.

Figure 31: Start/Stop Function Settings dialog box

This dialog box is available for the C-SPY E1/E20 driver.

Use this dialog box to configure the emulator to execute specific routines of your application immediately before the execution starts and/or after it halts. This is useful if you want to control your system in synchronization with starting and stopping the execution of your application.

Restrictions on using start/stop routines

Some restrictions apply:

● When the start/stop feature is enabled you cannot:

● set memory or download into the program area of a start/stop routine

● set breakpoints in the program area of a start/stop routine.

● While either of the start/stop routines is running, the four bytes of memory indicated by the interrupt stack pointer are in use by the emulator.

● In the start/stop routines, these restrictions apply to registers and flags:

Register and flag names Restrictions

ISP register When execution of a start/stop routine is ended, the register must be returned to its value at the time the routine started.

Flag U While a specified start/stop is running, switching to user mode is prohibited.

Table 4: Restrictions on registers and flags

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 83: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

● When either of the start/stop routines is running, the following does not work:

● Trace

● Breaks in execution in the start/stop routines

● RAM-monitoring. RAM-monitoring does not reflect access to memory by the start/stop routines.

● Performance measurement. The start/stop routines are not within the scope of performance measurement.

● Events. Event settings are invalid within the start/stop routines.

● While either of the start/stop routines is running, non-maskable interrupts are always disabled.

● This table shows which state the MCU will be in when your application starts running after executing a start routine:

Enable start routine

Enables the execution of a routine immediately before your application starts executing.

Start routine location

Specifies the routine to be executed immediately before your application starts executing. Type a label or an address, or click the browse button to open the Select Label dialog box; see Select Label dialog box, page 84.

Flag I No interrupts are allowed during execution of a start/stop routine.

Flag PM While a start/stop routine is running, switching to user mode is prohibited.

MCU resource Status

MCU general purpose registers

These registers are in the same state as when your application last stopped, or in states determined by the settings in the Register window. Changes made by the start routine to the contents of registers are not reflected.

Memory in the MCU space

Accesses to memory after the start routine has finished executing are reflected.

MCU peripheral functions

The operation of the MCU’s peripheral functions is continued after the start routine has finished executing.

Table 5: MCU status when the user application starts executing

Register and flag names Restrictions

Table 4: Restrictions on registers and flags

UCSRX-3

83

Page 84: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

84

Reference information on application execution

Enable stop routine

Enables the execution of a routine immediately after your application stops executing.

Stop routine location

Specifies the routine to be executed immediately after your application stops executing. Type a label or an address, or click the browse button to open the Select Label dialog box; see Select Label dialog box, page 84.

Select Label dialog boxThe Select Label dialog box is available from the Start/Stop Function Settings dialog box.

Figure 32: Select Label dialog box

This dialog box is available for the C-SPY E1/E20 driver.

Select the routine you want to be executed and click OK.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 85: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Executing your application

Autostep settings dialog boxThe Autostep settings dialog box is available from the Debug menu.

Figure 33: Autostep settings dialog box

Use this dialog box to customize autostepping.

The drop-down menu lists the available step commands.

Delay

Specify the delay between each step in milliseconds.

ID Code Verification dialog boxThe ID Code Verification dialog box is displayed if the ID code programmed in the target MCU differs from the ID code in the application that is being downloaded.

Figure 34: ID Code Verification dialog box

Use this dialog box to verify that you have the right to debug or download your application to the target board.

If you have selected the option Attach to program on the Project>Options>E1/E20>Download page, this dialog box will be displayed every time you launch a debug session.

Enter ID Code

Specify the ID code of the target MCU, a sequence of 32 hexadecimal digits.

UCSRX-3

85

Page 86: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

86

Reference information on application execution

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 87: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressionsThis chapter describes how variables and expressions can be used in C-SPY®. More specifically, this means:

● Introduction to working with variables and expressions

● Procedures for working with variables and expressions

● Reference information on working with variables and expressions.

Introduction to working with variables and expressionsThis section covers these topics:

● Briefly about working with variables and expressions

● C-SPY expressions

● Limitations on variable information.

BRIEFLY ABOUT WORKING WITH VARIABLES AND EXPRESSIONS

There are several methods for looking at variables and calculating their values:

● Tooltip watch—in the editor window—provides the simplest way of viewing the value of a variable or more complex expressions. Just point at the variable with the mouse pointer. The value is displayed next to the variable.

● The Auto window displays a useful selection of variables and expressions in, or near, the current statement. The window is automatically updated when execution stops.

● The Locals window displays the local variables, that is, auto variables and function parameters for the active function. The window is automatically updated when execution stops.

● The Watch window allows you to monitor the values of C-SPY expressions and variables. The window is automatically updated when execution stops.

● The Live Watch window repeatedly samples and displays the values of expressions while your application is executing. Variables in the expressions must be statically located, such as global variables.

UCSRX-3

87

Page 88: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

88

Introduction to working with variables and expressions

● The Statics window displays the values of variables with static storage duration. The window is automatically updated when execution stops.

● The Quick Watch window gives you precise control over when to evaluate an expression.

● The Symbols window displays all symbols with a static location, that is, C/C++ functions, assembler labels, and variables with static storage duration, including symbols from the runtime library.

● The Trace-related windows let you inspect the program flow up to a specific state. For more information, see Collecting and using trace data, page 159.

C-SPY EXPRESSIONS

C-SPY expressions can include any type of C expression, except for calls to functions. The following types of symbols can be used in expressions:

● C/C++ symbols

● Assembler symbols (register names and assembler labels)

● C-SPY macro functions

● C-SPY macro variables.

Expressions that are built with these types of symbols are called C-SPY expressions and there are several methods for monitoring these in C-SPY. Examples of valid C-SPY expressions are:

i + ji = 42#asm_label#R2#PCmy_macro_func(19)

In case you have a static variable with the same name declared in several different functions

C/C++ symbols

C symbols are symbols that you have defined in the C source code of your application, for instance variables, constants, and functions (functions can be used as symbols but cannot be executed). C symbols can be referenced by their names. Note that C++ symbols might implicitly contain function calls which are not allowed in C-SPY symbols and expressions.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 89: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

Assembler symbols

Assembler symbols can be assembler labels or register names. That is, general purpose registers, such as R1–R15, and special purpose registers, such as the program counter and the status register. If a device description file is used, all memory-mapped peripheral units, such as I/O ports, can also be used as assembler symbols in the same way as the CPU registers. See Modifying a device description file, page 45.

Assembler symbols can be used in C-SPY expressions if they are prefixed by #.

In case of a name conflict between a hardware register and an assembler label, hardware registers have a higher precedence. To refer to an assembler label in such a case, you must enclose the label in back quotes ` (ASCII character 0x60). For example:

Which processor-specific symbols are available by default can be seen in the Register window, using the CPU Registers register group. See Register window, page 150.

C-SPY macro functions

Macro functions consist of C-SPY macro variable definitions and macro statements which are executed when the macro is called.

For information about C-SPY macro functions and how to use them, see Briefly about the macro language, page 235.

C-SPY macro variables

Macro variables are defined and allocated outside your application, and can be used in a C-SPY expression. In case of a name conflict between a C symbol and a C-SPY macro variable, the C-SPY macro variable will have a higher precedence than the C variable. Assignments to a macro variable assign both its value and type.

For information about C-SPY macro variables and how to use them, see Reference information on the macro language, page 241.

Example What it does

#pc++ Increments the value of the program counter.

myptr = #label7 Sets myptr to the integral address of label7 within its zone.

Table 6: C-SPY assembler symbols expressions

Example What it does

#pc Refers to the program counter.

#`pc` Refers to the assembler label pc.

Table 7: Handling name conflicts between hardware registers and assembler labels

UCSRX-3

89

Page 90: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

90

Introduction to working with variables and expressions

Using sizeof

According to standard C, there are two syntactical forms of sizeof:

sizeof(type)sizeof expr

The former is for types and the latter for expressions.

Note: In C-SPY, do not use parentheses around an expression when you use the sizeof operator. For example, use sizeof x+2 instead of sizeof (x+2).

LIMITATIONS ON VARIABLE INFORMATION

The value of a C variable is valid only on step points, that is, the first instruction of a statement and on function calls. This is indicated in the editor window with a bright green highlight color. In practice, the value of the variable is accessible and correct more often than that.

When the program counter is inside a statement, but not at a step point, the statement or part of the statement is highlighted with a pale variant of the ordinary highlight color.

Effects of optimizations

The compiler is free to optimize the application software as much as possible, as long as the expected behavior remains. The optimization can affect the code so that debugging might be more difficult because it will be less clear how the generated code relates to the source code. Typically, using a high optimization level can affect the code in a way that will not allow you to view a value of a variable as expected.

Consider this example:

myFunction(){ int i = 42; ... x = computer(i); /* Here, the value of i is known to C-SPY */ ...}

From the point where the variable i is declared until it is actually used, the compiler does not need to waste stack or register space on it. The compiler can optimize the code, which means that C-SPY will not be able to display the value until it is actually used. If you try to view the value of a variable that is temporarily unavailable, C-SPY will display the text:

Unavailable

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 91: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

If you need full information about values of variables during your debugging session, you should make sure to use the lowest optimization level during compilation, that is, None.

Procedures for working with variables and expressionsThis section gives you step-by-step descriptions about how to work with variables and expressions.

More specifically, you will get information about:

● Using the windows related to variables and expressions

● Viewing assembler variables.

USING THE WINDOWS RELATED TO VARIABLES AND EXPRESSIONS

Where applicable, you can add, modify, and remove expressions, and change the display format in the windows related to variables and expressions.

To add a value you can also click in the dotted rectangle and type the expression you want to examine. To modify the value of an expression, click the Value field and modify its content. To remove an expression, select it and press the Delete key.

For text that is too wide to fit in a column—in any of the these windows, except the Trace window—and thus is truncated, just point at the text with the mouse pointer and tooltip information is displayed.

Right-click in any of the windows to access the context menu which contains additional commands. Convenient drag-and-drop between windows is supported, except for in the Locals window and the Quick Watch window where it is not relevant.

VIEWING ASSEMBLER VARIABLES

An assembler label does not convey any type information at all, which means C-SPY cannot easily display data located at that label without getting extra information. To view data conveniently, C-SPY by default treats all data located at assembler labels as variables of type int. However, in the Watch, Quick Watch, and Live Watch windows, you can select a different interpretation to better suit the declaration of the variables.

UCSRX-3

91

Page 92: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

92

Reference information on working with variables and expressions

In this figure, you can see four variables in the Watch window and their corresponding declarations in the assembler source file to the left:

Figure 35: Viewing assembler variables in the Watch window

Note that asmvar4 is displayed as an int, although the original assembler declaration probably intended for it to be a single byte quantity. From the context menu you can make C-SPY display the variable as, for example, an 8-bit unsigned variable. This has already been specified for the asmvar3 variable.

Reference information on working with variables and expressionsThis section gives reference information about these windows and dialog boxes:

● Auto window, page 93

● Locals window, page 93

● Watch window, page 94

● Live Watch window, page 95

● Statics window, page 96

● Select Statics dialog box, page 98

● Quick Watch window, page 99

● Symbols window, page 100

● Resolve Symbol Ambiguity dialog box, page 101.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 93: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

For trace-related reference information, see Reference information on trace, page 163.

Auto windowThe Auto window is available from the View menu.

Figure 36: Auto window

This window displays a useful selection of variables and expressions in, or near, the current statement. Every time execution in C-SPY stops, the values in the Auto window are recalculated. Values that have changed since the last stop are highlighted in red.

Context menu

For more information about the context menu, see Watch window, page 94.

Locals windowThe Locals window is available from the View menu.

Figure 37: Locals window

This window displays the local variables and parameters for the current function. Every time execution in C-SPY stops, the values in the Locals window are recalculated. Values that have changed since the last stop are highlighted in red.

Context menu

For more information about the context menu, see Watch window, page 94.

UCSRX-3

93

Page 94: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

94

Reference information on working with variables and expressions

Watch windowThe Watch window is available from the View menu.

Figure 38: Watch window

Use this window to monitor the values of C-SPY expressions or variables. You can view, add, modify, and remove expressions. Tree structures of arrays, structs, and unions are expandable, which means that you can study each item of these.

Every time execution in C-SPY stops, the values in the Watch window are recalculated. Values that have changed since the last stop are highlighted in red.

Context menu

This context menu is available:

Figure 39: Watch window context menu

These commands are available:

Add Adds an expression.

Remove Removes the selected expression.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 95: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

The display format setting affects different types of expressions in these ways:

Live Watch windowThe Live Watch window is available from the View menu.

Figure 40: Live Watch window

This window repeatedly samples and displays the value of expressions while your application is executing. Variables in the expressions must be statically located, such as global variables.

This window can only be used for hardware target systems supporting this feature.

Default Format,Binary Format,Octal Format,Decimal Format,Hexadecimal Format,Char Format

Changes the display format of expressions. The display format setting affects different types of expressions in different ways, see Table 8, Effects of display format setting on different types of expressions. Your selection of display format is saved between debug sessions.

Show As Displays a submenu that provides commands for changing the default type interpretation of variables. The commands on this submenu are mainly useful for assembler variables—data at assembler labels—because these are, by default, displayed as integers. For more information, see Viewing assembler variables, page 91.

Type of expression Effects of display format setting

Variable The display setting affects only the selected variable, not other variables.

Array element The display setting affects the complete array, that is, the same display format is used for each array element.

Structure field All elements with the same definition—the same field name and C declaration type—are affected by the display setting.

Table 8: Effects of display format setting on different types of expressions

UCSRX-3

95

Page 96: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

96

Reference information on working with variables and expressions

Context menu

For more information about the context menu, see Watch window, page 94.

In addition, the menu contains the Options command, which opens the Debugger dialog box where you can set the Update interval option. The default value of this option is 1000 milliseconds, which means the Live Watch window will be updated once every second during program execution.

Statics windowThe Statics window is available from the View menu.

Figure 41: Statics window

This window displays the values of variables with static storage duration, typically that is variables with file scope but also static variables in functions and classes. Note that volatile declared variables with static storage duration will not be displayed.

Every time execution in C-SPY stops, the values in the Statics window are recalculated. Values that have changed since the last stop are highlighted in red.

Display area

This area contains these columns:

Expression The name of the variable. The base name of the variable is followed by the full name, which includes module, class, or function scope. This column is not editable.

Value The value of the variable. Values that have changed are highlighted in red. This column is editable.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 97: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

Context menu

This context menu is available:

Figure 42: Statics window context menu

These commands are available:

The display format setting affects different types of expressions in these ways:

Location The location in memory where this variable is stored.

Type The data type of the variable.

Default Format,Binary Format,Octal Format,Decimal Format,Hexadecimal Format,Char Format

Changes the display format of expressions. The display format setting affects different types of expressions in different ways, see Table 8, Effects of display format setting on different types of expressions. Your selection of display format is saved between debug sessions.

Select Statics Displays a dialog box where you can select a subset of variables to be displayed in the Statics window, see Select Statics dialog box, page 98.

Type of expression Effects of display format setting

Variable The display setting affects only the selected variable, not other variables.

Array element The display setting affects the complete array, that is, the same display format is used for each array element.

Table 9: Effects of display format setting on different types of expressions

UCSRX-3

97

Page 98: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

98

Reference information on working with variables and expressions

Select Statics dialog boxThe Select Statics dialog box is available from the context menu in the Statics window.

Figure 43: Select Statics dialog box

Use this dialog box to select which variables should be displayed in the Statics window.

Show all variables with static storage duration

Makes all variables be displayed in the Statics window, including new variables that are added to your application between debug sessions.

Show selected variables only

Selects which variables to be displayed in the Statics window. Note that if you add a new variable to your application between two debug sessions, this variable will not automatically be displayed in the Statics window. Select the checkbox next to a variable to make that variable be displayed. Alternatively, click Select All.

Structure field All elements with the same definition—the same field name and C declaration type—are affected by the display setting.

Type of expression Effects of display format setting

Table 9: Effects of display format setting on different types of expressions (Continued)

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 99: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

Quick Watch windowThe Quick Watch window is available from the View menu and from the context menu in the editor window.

Figure 44: Quick Watch window

Use this window to watch the value of a variable or expression and evaluate expressions at a specific point in time.

In contrast to the Watch window, the Quick Watch window gives you precise control over when to evaluate the expression. For single variables this might not be necessary, but for expressions with possible side effects, such as assignments and C-SPY macro functions, it allows you to perform evaluations under controlled conditions.

To evaluate an expression:

1 In the editor window, right-click on the expression you want to examine and choose Quick Watch from the context menu that appears.

2 The expression will automatically appear in the Quick Watch window.

Alternatively:

1 In the Quick Watch window, type the expression you want to examine in the Expressions text box.

2 Click the Recalculate button to calculate the value of the expression.

For an example, see Executing macros using Quick Watch, page 239.

Context menu

For more information about the context menu, see Watch window, page 94.

In addition, the menu contains the Add to Watch window command, which adds the selected expression to the Watch window.

UCSRX-3

99

Page 100: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

100

Reference information on working with variables and expressions

Symbols windowThe Symbols window is available from the View menu.

Figure 45: Symbols window

This window displays all symbols with a static location, that is, C/C++ functions, assembler labels, and variables with static storage duration, including symbols from the runtime library.

Display area

This area contains these columns:

Click the column headers to sort the list by symbol name, location, or full name.

Context menu

This context menu is available:

Figure 46: Symbols window context menu

Symbol The symbol name.

Location The memory address.

Full name The symbol name; often the same as the contents of the Symbol column but differs for example for C++ member functions.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 101: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Working with variables and expressions

These commands are available:

Resolve Symbol Ambiguity dialog boxThe Resolve Symbol Ambiguity dialog box appears, for example, when you specify a symbol in the Disassembly window to go to, and there are several instances of the same symbol due to templates or function overloading.

Figure 47: Resolve Symbol Ambiguity dialog box

Ambiguous symbol

Indicates which symbol that is ambiguous.

Please select one symbol

A list of possible matches for the ambiguous symbol. Select the one you want to use.

Functions Toggles the display of function symbols on or off in the list.

Variables Toggles the display of variables on or off in the list.

Labels Toggles the display of labels on or off in the list.

UCSRX-3

101

Page 102: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

102

Reference information on working with variables and expressions

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 103: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpointsThis chapter describes breakpoints and the various ways to define and monitor them. More specifically, this means:

● Introduction to setting and using breakpoints

● Procedures for setting breakpoints

● Reference information on breakpoints.

Introduction to setting and using breakpointsThis section introduces breakpoints.

These topics are covered:

● Reasons for using breakpoints

● Briefly about setting breakpoints

● Breakpoint types

● Breakpoint icons

● Breakpoints in the C-SPY simulator

● Breakpoints in the C-SPY hardware drivers

● Breakpoint consumers.

REASONS FOR USING BREAKPOINTS

C-SPY® lets you set various types of breakpoints in the application you are debugging, allowing you to stop at locations of particular interest. You can set a breakpoint at a code location to investigate whether your program logic is correct, or to get trace printouts. In addition to code breakpoints, and depending on what C-SPY driver you are using, additional breakpoint types might be available. For example, you might be able to set a data breakpoint, to investigate how and when the data changes.

You can let the execution stop under certain conditions, which you specify. You can also let the breakpoint trigger a side effect, for instance executing a C-SPY macro function, by transparently stopping the execution and then resuming. The macro function can be defined to perform a wide variety of actions, for instance, simulating hardware behavior.

All these possibilities provide you with a flexible tool for investigating the status of your application.

UCSRX-3

103

Page 104: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

104

Introduction to setting and using breakpoints

BRIEFLY ABOUT SETTING BREAKPOINTS

You can set breakpoints in many various ways, allowing for different levels of interaction, precision, timing, and automation. All the breakpoints you define will appear in the Breakpoints window. From this window you can conveniently view all breakpoints, enable and disable breakpoints, and open a dialog box for defining new breakpoints. The Breakpoint Usage dialog box also lists all internally used breakpoints, see Breakpoint consumers, page 107.

Breakpoints are set with a higher precision than single lines, using the same mechanism as when stepping; for more information about the precision, see Single stepping, page 66.

You can set breakpoints while you edit your code even if no debug session is active. The breakpoints will then be validated when the debug session starts. Breakpoints are preserved between debug sessions.

Note: For most hardware debugger systems it is only possible to set breakpoints when the application is not executing.

BREAKPOINT TYPES

Depending on the C-SPY driver you are using, C-SPY supports different types of breakpoints.

Code breakpoints

Code breakpoints are used for code locations to investigate whether your program logic is correct or to get trace printouts. Code breakpoints are triggered when an instruction is fetched from the specified location. If you have set the breakpoint on a specific machine instruction, the breakpoint will be triggered and the execution will stop, before the instruction is executed.

Note: When you use a C-SPY hardware debugger driver and set a breakpoint in code without specifying the type, a hardware code breakpoint will be set as long as there are any available. If there are no available hardware code breakpoints, a software code breakpoint will be set.

Log breakpoints

Log breakpoints provide a convenient way to add trace printouts without having to add any code to your application source code. Log breakpoints are triggered when an instruction is fetched from the specified location. If you have set the breakpoint on a specific machine instruction, the breakpoint will be triggered and the execution will temporarily stop and print the specified message in the C-SPY Debug Log window.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 105: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Trace breakpoints

Trace Start and Stop breakpoints start and stop trace data collection—a convenient way to analyze instructions between two execution points.

Data breakpoints

Data breakpoints are primarily useful for variables that have a fixed address in memory. If you set a breakpoint on an accessible local variable, the breakpoint is set on the corresponding memory location. The validity of this location is only guaranteed for small parts of the code. Data breakpoints are triggered when data is accessed at the specified location. The execution will usually stop directly after the instruction that accessed the data has been executed.

Hardware code breakpoints

Hardware code breakpoints are code breakpoints that use hardware resources. Because memory does not have to be reprogrammed after a hardware code breakpoint has been hit, hardware code breakpoints are preferred over software code breakpoints. However, the number of available hardware breakpoints is limited, see Breakpoints in the C-SPY hardware drivers, page 106.

Software code breakpoints

Software code breakpoints are code breakpoints that use software resources. After a software code breakpoint has been triggered the memory must be reprogrammed, so software code breakpoints should if possible be used only in RAM memory or for breakpoints that are not triggered so often.

Performance breakpoints

By default, performance analysis is running from when the hardware debugger starts until it stops. Performance Start and Stop breakpoints are used for analyzing the performance over a smaller region of code. For reference information about these breakpoints, see Reference information on performance analysis, page 191.

Performance Start and Stop breakpoints share the same resources as hardware code breakpoints, see Breakpoints in the C-SPY hardware drivers, page 106.

Immediate breakpoints

The C-SPY Simulator lets you set immediate breakpoints, which will halt instruction execution only temporarily. This allows a C-SPY macro function to be called when the simulated processor is about to read data from a location or immediately after it has written data. Instruction execution will resume after the action.

UCSRX-3

105

Page 106: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

106

Introduction to setting and using breakpoints

This type of breakpoint is useful for simulating memory-mapped devices of various kinds (for instance serial ports and timers). When the simulated processor reads from a memory-mapped location, a C-SPY macro function can intervene and supply appropriate data. Conversely, when the simulated processor writes to a memory-mapped location, a C-SPY macro function can act on the value that was written.

BREAKPOINT ICONS

A breakpoint is marked with an icon in the left margin of the editor window, and the icon varies with the type of breakpoint:

Figure 48: Breakpoint icons

If the breakpoint icon does not appear, make sure the option Show bookmarks is selected, see Editor options in the IDE Project Management and Building Guide.

Just point at the breakpoint icon with the mouse pointer to get detailed tooltip information about all breakpoints set on the same location. The first row gives user breakpoint information, the following rows describe the physical breakpoints used for implementing the user breakpoint. The latter information can also be seen in the Breakpoint Usage dialog box.

Note: The breakpoint icons might look different for the C-SPY driver you are using.

BREAKPOINTS IN THE C-SPY SIMULATOR

The C-SPY simulator supports all breakpoint types and you can set an unlimited amount of breakpoints.

BREAKPOINTS IN THE C-SPY HARDWARE DRIVERS

Using the C-SPY drivers for hardware debugger systems you can set various breakpoint types. The amount of breakpoints you can set depends on the number of hardware breakpoints available on the target system. If no hardware breakpoints are available, software breakpoints will be used.

Code breakpoint

Log breakpoint

Tooltip information

Disabled code breakpoint

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 107: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

This table summarizes the characteristics of breakpoints for the different target systems:

* The number of available hardware breakpoints depends on the target system you are using.† These 8 breakpoint resources are shared between three types of breakpoints.

Hardware breakpoints in the RX emulators share the same resources. There is a total of 12 of these breakpoint events, divided into 8 that are triggered by a program counter access and 4 that are triggered by a data access.

The software code breakpoints use a mechanism that writes to the memory with a BRK instruction, and when a breakpoint is triggered the original instruction is written back to the memory. This makes it possible to use the breakpoint for code in RAM, but if used for code in flash memory the execution is slowed down by the need to reprogram the memory. There are up to 256 software code breakpoints.

The debugger will first use any available hardware breakpoints before using software breakpoints. Exceeding the number of available breakpoints causes the debugger to single step. This will significantly reduce the execution speed. For this reason you must be aware of the different breakpoint consumers.

BREAKPOINT CONSUMERS

A debugger system includes several consumers of breakpoints.

User breakpoints

The breakpoints you define in the breakpoint dialog box or by toggling breakpoints in the editor window often consume one physical breakpoint each, but this can vary greatly. Some user breakpoints consume several physical breakpoints and conversely, several user breakpoints can share one physical breakpoint. User breakpoints are displayed in the same way both in the Breakpoint Usage dialog box and in the Breakpoints window, for example Data @[R] callCount.

C-SPY hardware driver

Software

code

breakpoints

Hardware

code and

Log

breakpoints

Trace

breakpoints

Data

breakpoints

Perform-

ance

breakpoints

E1/E20

using 12 h/w breakpoints* 256 Up to 8† Up to 8† 4 Up to 8†

J-Link

using 12 h/w breakpoints* 256 Up to 8† Up to 8† 4 Up to 8†

Table 10: Available breakpoints in C-SPY hardware drivers

UCSRX-3

107

Page 108: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

108

Procedures for setting breakpoints

C-SPY itself

C-SPY itself also consumes breakpoints. C-SPY will set a breakpoint if:

● The debugger option Run to has been selected, and any step command is used. These are temporary breakpoints which are only set when the debugger system is running. This means that they are not visible in the Breakpoints window.

● The linker option Include C-SPY debugging support has been selected.

These types of breakpoint consumers are displayed in the Breakpoint Usage dialog box, for example, C-SPY Terminal I/O & libsupport module.

C-SPY plugin modules

For example, modules for real-time operating systems can consume additional breakpoints. Specifically, by default, the Stack window consumes one physical breakpoint.

To disable the breakpoint used by the Stack window:

1 Choose Tools>Options>Stack.

2 Deselect the Stack pointer(s) not valid until program reaches: label option.

Procedures for setting breakpointsThis section gives you step-by-step descriptions about how to set and use breakpoints.

More specifically, you will get information about:

● Various ways to set a breakpoint

● Toggling a simple code breakpoint

● Setting breakpoints using the dialog box

● Setting a data breakpoint in the Memory window

● Setting breakpoints using system macros

● Useful breakpoint hints.

VARIOUS WAYS TO SET A BREAKPOINT

You can set a breakpoint in various ways:

● Using the Toggle Breakpoint command toggles a code breakpoint. This command is available both from the Tools menu and from the context menus in the editor window and in the Disassembly window.

● Right-clicking in the left-side margin of the editor window or the Disassembly window toggles a code breakpoint.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 109: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

● Using the New Breakpoints dialog box and the Edit Breakpoints dialog box available from the context menus in the editor window, Breakpoints window, and in the Disassembly window. The dialog boxes give you access to all breakpoint options.

● Setting a data breakpoint on a memory area directly in the Memory window.

● Using predefined system macros for setting breakpoints, which allows automation.

The different methods offer different levels of simplicity, complexity, and automation.

TOGGLING A SIMPLE CODE BREAKPOINT

Toggling a code breakpoint is a quick method of setting a breakpoint. The following methods are available both in the editor window and in the Disassembly window:

● Double-click in the gray left-side margin of the window

● Place the insertion point in the C source statement or assembler instruction where you want the breakpoint, and click the Toggle Breakpoint button in the toolbar

● Choose Edit>Toggle Breakpoint

● Right-click and choose Toggle Breakpoint from the context menu.

SETTING BREAKPOINTS USING THE DIALOG BOX

The advantage of using a breakpoint dialog box is that it provides you with a graphical interface where you can interactively fine-tune the characteristics of the breakpoints. You can set the options and quickly test whether the breakpoint works according to your intentions.

All breakpoints you define using a breakpoint dialog box are preserved between debug sessions.

To set a new breakpoint:

You can open the dialog box from the context menu available in the editor window, Breakpoints window, and in the Disassembly window.

1 Choose View>Breakpoints to open the Breakpoints window.

2 In the Breakpoints window, right-click, and choose New Breakpoint from the context menu.

3 On the submenu, choose the breakpoint type you want to set.

Depending on the C-SPY driver you are using, different breakpoint types are available.

4 In the breakpoint dialog box that appears, specify the breakpoint settings and click OK.

The breakpoint is displayed in the Breakpoints window.

UCSRX-3

109

Page 110: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

110

Procedures for setting breakpoints

To modify an existing breakpoint:

1 In the Breakpoints window, editor window, or in the Disassembly window, select the breakpoint you want to modify and right-click to open the context menu.

Figure 49: Modifying breakpoints via the context menu

If there are several breakpoints on the same source code line, the breakpoints will be listed on a submenu.

2 On the context menu, choose the appropriate command.

3 In the breakpoint dialog box that appears, specify the breakpoint settings and click OK.

The breakpoint is displayed in the Breakpoints window.

SETTING A DATA BREAKPOINT IN THE MEMORY WINDOW

You can set breakpoints directly on a memory location in the Memory window. Right-click in the window and choose the breakpoint command from the context menu that appears. To set the breakpoint on a range, select a portion of the memory contents.

The breakpoint is not highlighted in the Memory window; instead, you can see, edit, and remove it using the Breakpoints window, which is available from the View menu. The breakpoints you set in the Memory window will be triggered for both read and write accesses. All breakpoints defined in this window are preserved between debug sessions.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 111: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Note: Setting breakpoints directly in the Memory window is only possible if the driver you use supports this.

SETTING BREAKPOINTS USING SYSTEM MACROS

You can set breakpoints not only in the breakpoint dialog box but also by using built-in C-SPY system macros. When you use system macros for setting breakpoints, the breakpoint characteristics are specified as macro parameters.

Macros are useful when you have already specified your breakpoints so that they fully meet your requirements. You can define your breakpoints in a macro file, using built-in system macros, and execute the file at C-SPY startup. The breakpoints will then be set automatically each time you start C-SPY. Another advantage is that the debug session will be documented, and that several engineers involved in the development project can share the macro files.

Note: If you use system macros for setting breakpoints, you can still view and modify them in the Breakpoints window. In contrast to using the dialog box for defining breakpoints, all breakpoints that are defined using system macros are removed when you exit the debug session.

These breakpoint macros are available:

For information about each breakpoint macro, see Reference information on C-SPY system macros, page 247.

Setting breakpoints at C-SPY startup using a setup macro file

You can use a setup macro file to define breakpoints at C-SPY startup. Follow the procedure described in Registering and executing using setup macros and setup files, page 238.

C-SPY macro for breakpoints Simulator E1/E20 J-Link

__setCodeBreak Yes Yes Yes

__setDataBreak Yes — —

__setLogBreak Yes Yes Yes

__setSimBreak Yes — —

__setTraceStartBreak Yes Yes Yes

__setTraceStopBreak Yes Yes Yes

__clearBreak Yes Yes Yes

Table 11: C-SPY macros for breakpoints

UCSRX-3

111

Page 112: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

112

Procedures for setting breakpoints

USEFUL BREAKPOINT HINTS

Below are some useful hints related to setting breakpoints.

Tracing incorrect function arguments

If a function with a pointer argument is sometimes incorrectly called with a NULL argument, you might want to debug that behavior. These methods can be useful:

● Set a breakpoint on the first line of the function with a condition that is true only when the parameter is 0. The breakpoint will then not be triggered until the problematic situation actually occurs. The advantage of this method is that no extra source code is needed. The drawback is that the execution speed might become unacceptably low.

● You can use the assert macro in your problematic function, for example:

int MyFunction(int * MyPtr){ assert(MyPtr != 0); /* Assert macro added to your source code. */ /* Here comes the rest of your function. */}

The execution will break whenever the condition is true. The advantage is that the execution speed is only very slightly affected, but the drawback is that you will get a small extra footprint in your source code. In addition, the only way to get rid of the execution stop is to remove the macro and rebuild your source code.

● Instead of using the assert macro, you can modify your function like this:

int MyFunction(int * MyPtr){ if(MyPtr == 0) MyDummyStatement; /* Dummy statement where you set a breakpoint. */ /* Here comes the rest of your function. */}

You must also set a breakpoint on the extra dummy statement, so that the execution will break whenever the condition is true. The advantage is that the execution speed is only very slightly affected, but the drawback is that you will still get a small extra footprint in your source code. However, in this way you can get rid of the execution stop by just removing the breakpoint.

Performing a task and continuing execution

You can perform a task when a breakpoint is triggered and then automatically continue execution.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 113: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

You can use the Action text box to associate an action with the breakpoint, for instance a C-SPY macro function. When the breakpoint is triggered and the execution of your application has stopped, the macro function will be executed. In this case, the execution will not continue automatically.

Instead, you can set a condition which returns 0 (false). When the breakpoint is triggered, the condition—which can be a call to a C-SPY macro that performs a task— is evaluated and because it is not true, execution continues.

Consider this example where the C-SPY macro function performs a simple task:

__var my_counter;

count(){ my_counter += 1; return 0;}

To use this function as a condition for the breakpoint, type count() in the Expression text box under Conditions. The task will then be performed when the breakpoint is triggered. Because the macro function count returns 0, the condition is false and the execution of the program will resume automatically, without any stop.

Reference information on breakpointsThis section gives reference information about these windows and dialog boxes:

● Breakpoints window, page 114

● Breakpoint Usage dialog box, page 116

● Code breakpoints dialog box, page 117

● Hardware Code Breakpoint dialog box, page 118

● Software Code Breakpoint dialog box, page 120

● Log breakpoints dialog box, page 121

● Data breakpoints dialog box (simulator), page 123

● Data breakpoints dialog box (E1/E20 and J-Link), page 125

● Immediate breakpoints dialog box, page 127

● Enter Location dialog box, page 128

● Resolve Source Ambiguity dialog box, page 129.

See also:

● Reference information on C-SPY system macros, page 247

UCSRX-3

113

Page 114: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

114

Reference information on breakpoints

● Reference information on trace, page 163

● Reference information on performance analysis, page 191.

Breakpoints windowThe Breakpoints window is available from the View menu.

Figure 50: Breakpoints window

The Breakpoints window lists all breakpoints you define.

Use this window to conveniently monitor, enable, and disable breakpoints; you can also define new breakpoints and modify existing breakpoints.

Display area

This area lists all breakpoints you define. For each breakpoint, information about the breakpoint type, source file, source line, and source column is provided.

Context menu

This context menu is available:

Figure 51: Breakpoints window context menu

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 115: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

These commands are available:

Go to Source Moves the insertion point to the location of the breakpoint, if the breakpoint has a source location. Double-click a breakpoint in the Breakpoints window to perform the same command.

Edit Opens the breakpoint dialog box for the breakpoint you selected.

Delete Deletes the breakpoint. Press the Delete key to perform the same command.

Enable Enables the breakpoint. The check box at the beginning of the line will be selected. You can also perform the command by manually selecting the check box. This command is only available if the breakpoint is disabled.

Disable Disables the breakpoint. The check box at the beginning of the line will be deselected. You can also perform this command by manually deselecting the check box. This command is only available if the breakpoint is enabled.

Enable All Enables all defined breakpoints.

Disable All Disables all defined breakpoints.

New Breakpoint Displays a submenu where you can open the breakpoint dialog box for the available breakpoint types. All breakpoints you define using this dialog box are preserved between debug sessions.

UCSRX-3

115

Page 116: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

116

Reference information on breakpoints

Breakpoint Usage dialog boxThe Breakpoint Usage dialog box is available from the menu specific to the C-SPY driver you are using.

Figure 52: Breakpoint Usage dialog box

The Breakpoint Usage dialog box lists all breakpoints currently set in the target system, both the ones you have defined and the ones used internally by C-SPY. The format of the items in this dialog box depends on the C-SPY driver you are using.

The dialog box gives a low-level view of all breakpoints, related but not identical to the list of breakpoints displayed in the Breakpoints window.

C-SPY uses breakpoints when stepping. If your target system has a limited number of hardware breakpoints, software breakpoints will be used. Exceeding the number of available breakpoints will cause the debugger to single step. This will significantly reduce the execution speed. Therefore, in a debugger system with a limited amount of breakpoints, you can use the Breakpoint Usage dialog box for:

● Identifying all breakpoint consumers

● Checking that the number of active breakpoints is supported by the target system

● Configuring the debugger to use the available breakpoints in a better way, if possible.

Display area

For each breakpoint in the list, the address and access type are displayed. Each breakpoint in the list can also be expanded to show its originator.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 117: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Code breakpoints dialog boxThe Code breakpoints dialog box is available from the context menu in the editor window, Breakpoints window, and in the Disassembly window.

Figure 53: Code breakpoints dialog box

Use the Code breakpoints dialog box to set a code breakpoint.

Note: The Code breakpoints dialog box depends on the C-SPY driver you are using. This figure reflects the C-SPY simulator. For information about support for breakpoints in the C-SPY driver you are using, see Breakpoints in the C-SPY hardware drivers, page 106.

Break At

Specify the location of the breakpoint in the text box. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

Size

Determines whether there should be a size—in practice, a range—of locations where the breakpoint will trigger. Each fetch access to the specified memory range will trigger the breakpoint. Select how to specify the size:

Note: This option is only available for the C-SPY simulator driver.

Auto The size will be set automatically, typically to 1.

Manual Specify the size of the breakpoint range in the text box

UCSRX-3

117

Page 118: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

118

Reference information on breakpoints

Action

Determines whether there is an action connected to the breakpoint. Specify an expression, for instance a C-SPY macro function, which is evaluated when the breakpoint is triggered and the condition is true.

Conditions

Specify simple or complex conditions:

Hardware Code Breakpoint dialog boxThe Hardware Code Breakpoint dialog box is available from the context menu in the editor window, Breakpoints window, and in the Disassembly window.

Figure 54: Hardware Code breakpoints dialog box

Expression Specify a valid expression conforming to the C-SPY expression syntax.

Condition true The breakpoint is triggered if the value of the expression is true.

Condition changed The breakpoint is triggered if the value of the expression has changed since it was last evaluated.

Skip count The number of times that the breakpoint condition must be fulfilled before the breakpoint starts triggering. After that, the breakpoint will trigger every time the condition is fulfilled.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 119: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

This dialog box is available for these drivers:

● C-SPY E1/E20 driver

● C-SPY J-Link driver.

Use the Hardware breakpoints dialog box to set a hardware breakpoint.

Break At

Specify the location of the breakpoint in the text box. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

Action

Determines whether there is an action connected to the breakpoint. Specify an expression, for instance a C-SPY macro function, which is evaluated when the breakpoint is triggered and the condition is true.

Conditions

Specify simple or complex conditions:

Expression Specify a valid expression conforming to the C-SPY expression syntax.

Condition true The breakpoint is triggered if the value of the expression is true.

Condition changed The breakpoint is triggered if the value of the expression has changed since it was last evaluated.

Skip count The number of times that the breakpoint condition must be fulfilled before the breakpoint starts triggering.

UCSRX-3

119

Page 120: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

120

Reference information on breakpoints

Software Code Breakpoint dialog boxThe Software Code Breakpoint dialog box is available from the context menu in the editor window, Breakpoints window, and in the Disassembly window.

Figure 55: Software Code breakpoints dialog box

This dialog box is available for these drivers:

● C-SPY E1/E20 driver

● C-SPY J-Link driver.

Use the Software Code Breakpoint breakpoints dialog box to set a software code breakpoint.

Note: Because the memory must be reprogrammed after a software code breakpoint has been triggered, software code breakpoints should if possible be used only in RAM memory or for breakpoints that are not triggered so often.

Break At

Specify the location of the breakpoint in the text box. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

Action

Determines whether there is an action connected to the breakpoint. Specify an expression, for instance a C-SPY macro function, which is evaluated when the breakpoint is triggered and the condition is true.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 121: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Conditions

Specify simple or complex conditions:

Log breakpoints dialog boxThe Log breakpoints dialog box is available from the context menu in the editor window, Breakpoints window, and in the Disassembly window.

Figure 56: Log breakpoints dialog box

Use the Log breakpoints dialog box to set a log breakpoint.

Note: The Log breakpoints dialog box depends on the C-SPY driver you are using. This figure reflects the C-SPY simulator. For information about support for breakpoints in the C-SPY driver you are using, see Breakpoints in the C-SPY hardware drivers, page 106.

Expression Specify a valid expression conforming to the C-SPY expression syntax.

Condition true The breakpoint is triggered if the value of the expression is true.

Condition changed The breakpoint is triggered if the value of the expression has changed since it was last evaluated.

Skip count The number of times that the breakpoint condition must be fulfilled before the breakpoint starts triggering.

UCSRX-3

121

Page 122: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

122

Reference information on breakpoints

Break At

Specify the location of the breakpoint. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

Message

Specify the message you want to be displayed in the C-SPY Debug Log window. The message can either be plain text, or—if you also select the option C-SPY macro "__message" style—a comma-separated list of arguments.

C-SPY macro "__message" style

Select this option to make a comma-separated list of arguments specified in the Message text box be treated exactly as the arguments to the C-SPY macro language statement __message, see Formatted output, page 244.

Conditions

Specify simple or complex conditions:

Expression Specify a valid expression conforming to the C-SPY expression syntax.

Condition true The breakpoint is triggered if the value of the expression is true.

Condition changed The breakpoint is triggered if the value of the expression has changed since it was last evaluated.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 123: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Data breakpoints dialog box (simulator)The Data breakpoints dialog box is available from the context menu in the editor window, Breakpoints window, the Memory window, and in the Disassembly window.

Figure 57: Data breakpoints dialog box

Use the Data breakpoints dialog box to set a data breakpoint. Data breakpoints never stop execution within a single instruction. They are recorded and reported after the instruction is executed.

Note: The Data breakpoints dialog box depends on the C-SPY driver you are using. This figure reflects the C-SPY simulator. For information about support for breakpoints in the C-SPY driver you are using, see Breakpoints in the C-SPY hardware drivers, page 106.

Break At

Specify the location for the breakpoint in the Break At text box. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

Access Type

Selects the type of memory access that triggers data breakpoints:

Read/Write Reads from or writes to location.

Read Reads from location.

Write Writes to location.

UCSRX-3

123

Page 124: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

124

Reference information on breakpoints

Size

Determines whether there should be a size—in practice, a range—of locations where the breakpoint will trigger. Each fetch access to the specified memory range will trigger the breakpoint. For data breakpoints, this can be useful if you want the breakpoint to be triggered on accesses to data structures, such as arrays, structs, and unions. Select between two different ways to specify the size:

Action

Determines whether there is an action connected to the breakpoint. Specify an expression, for instance a C-SPY macro function, which is evaluated when the breakpoint is triggered and the condition is true.

Conditions

Specify simple or complex conditions:

Auto The size will automatically be based on the type of expression the breakpoint is set on. For example, if you set the breakpoint on a 12-byte structure, the size of the breakpoint will be 12 bytes.

Manual Specify the size of the breakpoint range in the text box.

Expression Specify a valid expression conforming to the C-SPY expression syntax.

Condition true The breakpoint is triggered if the value of the expression is true.

Condition changed The breakpoint is triggered if the value of the expression has changed since it was last evaluated.

Skip count The number of times that the breakpoint condition must be fulfilled before a break occurs (integer).

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 125: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Data breakpoints dialog box (E1/E20 and J-Link)The Data breakpoints dialog box is available from the context menu in the editor window, Breakpoints window, the Memory window, and in the Disassembly window.

Figure 58: Data breakpoints dialog box (E1/E20 and J-Link)

Use the Data breakpoints dialog box to set a data breakpoint. Data breakpoints never stop execution within a single instruction. They are recorded and reported after the instruction is executed.

The contents of the Data breakpoints dialog box depends on the C-SPY driver you are using. This figure reflects the C-SPY E1/E20 and J-Link drivers.

Break At

Specify the location of the breakpoint, or the start location if you select the address condition Range. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

UCSRX-3

125

Page 126: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

126

Reference information on breakpoints

Address Condition

Determines whether there should be a trigger condition for the address where the data is located:

Data Condition

Determines whether there should be data trigger conditions for the breakpoint:

None There is no condition for the address.

Mask Specify an address mask and choose a Compare setting.

Compare Specify whether the condition is that the address should be equal (Specified value (==)) or not equal (Any other value (!=)) to the mask.

Range Uses the location in the Break At field as the start address of an address range. Use the text box to specify whether the trigger condition applies to inside the range or outside the range.

End address Specify the end location if the Break At field contains the start location of an address range. Alternatively, click the Edit button to open the Enter Location dialog box, see Enter Location dialog box, page 128

Read/Write Read — the breakpoint is only triggered by a read accessWrite — the breakpoint is only triggered by a write accessRead/Write — the breakpoint is triggered by all accesses.

Access size Determines whether there should be a size—in practice, a range—of locations where the breakpoint will trigger. Each fetch access to the specified memory range will trigger the breakpoint. Choose between:

Auto — The access size will be set automatically.Byte — The access size will be set to a byte.Word — The access size will be set to a word.Long — The access size will be set to a long.

Compared data Set a value that the accessed data should be compared to, using decimal notation or hexadecimal notation (prefixed by 0x).

Mask Set a mask for the compared data.

Compare Specify whether the condition is that the data should be equal (Specified value (==)) or not equal (Any other value (!=)) to the mask.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 127: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Immediate breakpoints dialog boxThe Immediate breakpoints dialog box is available from the context menu in the editor window, Breakpoints window, the Memory window, and in the Disassembly window.

Figure 59: Immediate breakpoints dialog box

In the C-SPY simulator, use the Immediate breakpoints dialog box to set an immediate breakpoint. Immediate breakpoints do not stop execution at all; they only suspend it temporarily.

Break At

Specify the location for the breakpoint in the Break At text box. Alternatively, click the Edit button to open the Enter Location dialog box; see Enter Location dialog box, page 128.

Access Type

Selects the type of memory access that triggers immediate breakpoints:

Action

Determines whether there is an action connected to the breakpoint. Specify an expression, for instance a C-SPY macro function, which is evaluated when the breakpoint is triggered and the condition is true.

Read Reads from location.

Write Writes to location.

UCSRX-3

127

Page 128: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

128

Reference information on breakpoints

Enter Location dialog boxThe Enter Location dialog box is available from the breakpoints dialog box, either when you set a new breakpoint or when you edit a breakpoint.

Figure 60: Enter Location dialog box

Use the Enter Location dialog box to specify the location of the breakpoint.

Note: This dialog box looks different depending on the Type you select.

Type

Selects the type of location to be used for the breakpoint:

Expression A C-SPY expression, whose value evaluates to a valid address, such as a function or variable name.

Code breakpoints are set on functions, for example main. Data breakpoints are set on variable names. For example, my_var refers to the location of the variable my_var, and arr[3] refers to the location of the third element of the array arr.

For static variables declared with the same name in several functions, use the syntax my_func::my_static_variable to refer to a specific variable.

For more information about C-SPY expressions, see C-SPY expressions, page 88.

Absolute address An absolute location on the form zone:hexaddress or simply hexaddress (for example Memory:0x42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 129: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using breakpoints

Resolve Source Ambiguity dialog boxThe Resolve Source Ambiguity dialog box appears, for example, when you try to set a breakpoint on inline functions or templates, and the source location corresponds to more than one function.

Figure 61: Resolve Source Ambiguity dialog box

To resolve a source ambiguity, perform one of these actions:

● In the text box, select one or several of the listed locations and click Selected.

● Click All.

Source location A location in your C source code using the syntax: {filename}.row.column.

filename specifies the filename and full path.row specifies the row in which you want the breakpoint.column specifies the column in which you want the

breakpoint.

For example, {C:\src\prog.c}.22.3 sets a breakpoint on the third character position on line 22 in the source file Utilities.c.

Note that the Source location type is usually meaningful only for code breakpoints.

UCSRX-3

129

Page 130: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

130

Reference information on breakpoints

All

The breakpoint will be set on all listed locations.

Selected

The breakpoint will be set on the source locations that you have selected in the text box.

Cancel

No location will be used.

Automatically choose all

Determines that whenever a specified source location corresponds to more than one function, all locations will be used.

Note that this option can also be specified in the IDE Options dialog box, see Debugger options in the IDE Project Management and Building Guide.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 131: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registersThis chapter describes how to use the features available in C-SPY® for examining memory and registers. More specifically, this means information about:

● Introduction to monitoring memory and registers

● Reference information on memory and registers.

Introduction to monitoring memory and registersThis section covers these topics:

● Briefly about monitoring memory and registers

● C-SPY memory zones

● Stack display

● Memory access checking.

BRIEFLY ABOUT MONITORING MEMORY AND REGISTERS

C-SPY provides many windows for monitoring memory and registers, each of them available from the View menu:

● The Memory window

Gives an up-to-date display of a specified area of memory—a memory zone—and allows you to edit it. Different colors are used for indicating data coverage along with execution of your application. You can fill specified areas with specific values and you can set breakpoints directly on a memory location or range. You can open several instances of this window, to monitor different memory areas. The content of the window can be regularly updated while your application is executing.

● The Symbolic memory window

Displays how variables with static storage duration are laid out in memory. This can be useful for better understanding memory usage or for investigating problems caused by variables being overwritten, for example by buffer overruns.

UCSRX-3

131

Page 132: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

132

Introduction to monitoring memory and registers

● The Stack window

Displays the contents of the stack, including how stack variables are laid out in memory. In addition, some integrity checks of the stack can be performed to detect and warn about problems with stack overflow. For example, the Stack window is useful for determining the optimal size of the stack. You can open several instances of this window, each showing different stacks or different display modes of the same stack.

● The Register window

Gives an up-to-date display of the contents of the processor registers and SFRs, and allows you to edit them. Due to the large amount of registers—memory-mapped peripheral unit registers and CPU registers—it is inconvenient to show all registers concurrently in the Register window. Instead you can divide registers into register groups. You can choose to load either predefined register groups or define your own application-specific groups. You can open several instances of this window, each showing a different register group.

● The SFR Setup window

Displays the currently defined SFRs that C-SPY has information about. If required, you can use this window to customize aspects of the SFRs.

To view the memory contents for a specific variable, simply drag the variable to the Memory window or the Symbolic memory window. The memory area where the variable is located will appear.

Reading the value of some registers might influence the runtime behavior of your application. For example, reading the value of a UART status register might reset a pending bit, which leads to the lack of an interrupt that would have processed a received byte. To prevent this from happening, make sure that the Register window containing any such registers is closed when debugging a running application.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 133: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

C-SPY MEMORY ZONES

In C-SPY, the term zone is used for a named memory area. A memory address, or location, is a combination of a zone and a numerical offset into that zone. By default, the RX architecture has one zone, Memory, which covers the whole RX memory range.

Figure 62: Zones in C-SPY

Memory zones are used in several contexts, most importantly in the Memory and Disassembly windows. Use the Zone box in these windows to choose which memory zone to display.

Device-specific zones

Memory information for device-specific zones are defined in the device description files. By default, there is only one zone in the debugger, Memory. If you load a device description file, additional zones that adhere to the specific memory layout are defined.

These zones are available depending on the device description file you are using:

Memory zone Type Description

DATA_FLASH Code Read/write

IO Sfr Read/write

IO1 Sfr Read/write

IO2 Sfr Read/write

RAM Data Read/write

ROM Code Read-only

Table 12: Device-specific memory zones

Default zone Memory

0xFFFFFFFF

0x00000000

UCSRX-3

133

Page 134: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

134

Introduction to monitoring memory and registers

If your hardware does not have the same memory layout as any of the predefined device description files, you can define customized zones by adding them to the file.

For more information, see Selecting a device description file, page 41 and Modifying a device description file, page 45.

STACK DISPLAY

The Stack window displays the contents of the stack, overflow warnings, and it has a graphical stack bar. These can be useful in many contexts. Some examples are:

● Investigating the stack usage when assembler modules are called from C modules and vice versa

● Investigating whether the correct elements are located on the stack

● Investigating whether the stack is restored properly

● Determining the optimal stack size

● Detecting stack overflows.

For microcontrollers with multiple stacks, you can select which stack to view.

Stack usage

When your application is first loaded, and upon each reset, the memory for the stack area is filled with the dedicated byte value 0xCD before the application starts executing. Whenever execution stops, the stack memory is searched from the end of the stack until a byte with a value different from 0xCD is found, which is assumed to be how far the stack has been used. Although this is a reasonably reliable way to track stack usage, there is no guarantee that a stack overflow is detected. For example, a stack can incorrectly grow outside its bounds, and even modify memory outside the stack area, without actually modifying any of the bytes near the stack range. Likewise, your application might modify memory within the stack area by mistake.

The Stack window cannot detect a stack overflow when it happens, but can only detect the signs it leaves behind. However, when the graphical stack bar is enabled, the functionality needed to detect and warn about stack overflows is also enabled.

Note: The size and location of the stack is retrieved from the definition of the section holding the stack, made in the linker configuration file. If you, for some reason, modify the stack initialization made in the system startup code, cstartup, you should also change the section definition in the linker configuration file accordingly; otherwise the Stack window cannot track the stack usage. For more information about this, see the IAR C/C++ Development Guide for RX.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 135: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

MEMORY ACCESS CHECKING

The C-SPY simulator can simulate various memory access types of the target hardware and detect illegal accesses, for example a read access to write-only memory. If a memory access occurs that does not agree with the access type specified for the specific memory area, C-SPY will regard this as an illegal access. Also, a memory access to memory which is not defined is regarded as an illegal access. The purpose of memory access checking is to help you to identify any memory access violations.

The memory areas can either be the zones predefined in the device description file, or memory areas based on the section information available in the debug file. In addition to these, you can define your own memory areas. The access type can be read and write, read-only, or write-only. You cannot map two different access types to the same memory area. You can check for access type violation and accesses to unspecified ranges. Any violations are logged in the Debug Log window. You can also choose to have the execution halted.

Reference information on memory and registersThis section gives reference information about these windows and dialog boxes:

● Memory window, page 136

● Memory Save dialog box, page 140

● Memory Restore dialog box, page 141

● Fill dialog box, page 141

● RAM Monitor Setup dialog box, page 143

● Edit RAM monitor block dialog box, page 144

● Symbolic Memory window, page 145

● Stack window, page 147

● Register window, page 150

● SFR Setup window, page 151

● Edit SFR dialog box, page 154

● Memory Access Setup dialog box, page 155

● Edit Memory Access dialog box, page 157.

UCSRX-3

135

Page 136: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

136

Reference information on memory and registers

Memory windowThe Memory window is available from the View menu.

Figure 63: Memory window

This window gives an up-to-date display of a specified area of memory—a memory zone—and allows you to edit it. You can open several instances of this window, which is very convenient if you want to keep track of several memory or register zones, or monitor different parts of the memory.

To view the memory corresponding to a variable, you can select it in the editor window and drag it to the Memory window.

Toolbar

The toolbar contains:

Available zones

Memory addresses

Context menu buttonMemory contents

Data coverage information

Go to location

Memory contents in ASCII format

Go to The location you want to view. This can be a memory address, or the name of a variable, function, or label.

Zone display Selects a memory zone to display, see C-SPY memory zones, page 133.

Context menu button

Displays the context menu, see Context menu, page 138.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 137: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Display area

The display area shows the addresses currently being viewed, the memory contents in the format you have chosen, and—provided that the display mode is set to 1x Units—the memory contents in ASCII format. You can edit the contents of the display area, both in the hexadecimal part and the ASCII part of the area.

Data coverage is displayed with these colors:

Note: Data coverage is not supported by all C-SPY drivers. Data coverage is supported by the C-SPY Simulator and the E1/E20 driver. For the E1/E20 driver, memory areas for data coverage are configured in the RAM Monitor Setup dialog box, see RAM Monitor Setup dialog box, page 143.

Update Now Updates the content of the Memory window while your application is executing. This button is only enabled if the C-SPY driver you are using has access to the target system memory while your application is executing.

Live Update Updates the contents of the Memory window regularly while your application is executing. This button is only enabled if the C-SPY driver you are using has access to the target system memory while your application is executing. To set the update frequency, specify an appropriate frequency in the IDE Options>Debugger dialog box.

Yellow Indicates data that has been read.

Blue Indicates data that has been written

Green Indicates data that has been both read and written.

UCSRX-3

137

Page 138: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

138

Reference information on memory and registers

Context menu

This context menu is available:

Figure 64: Memory window context menu

These commands are available:

Copy, Paste Standard editing commands.

Zone Selects a memory zone to display, see C-SPY memory zones, page 133.

1x Units Displays the memory contents in units of 8 bits.

2x Units Displays the memory contents in units of 16 bits.

4x Units Displays the memory contents in units of 32 bits.

Little Endian Displays the contents in little-endian byte order.

Big Endian Displays the contents in big-endian byte order.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 139: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Data Coverage Choose between:

Enable toggles data coverage on or off.Show toggles between showing or hiding data coverage.Clear clears all data coverage information.

These commands are only available if your C-SPY driver supports data coverage.

Find Displays a dialog box where you can search for text within the Memory window; read about the Find dialog box in the IDE Project Management and Building Guide.

Replace Displays a dialog box where you can search for a specified string and replace each occurrence with another string; read about the Replace dialog box in the IDE Project Management and Building Guide.

Memory Fill Displays a dialog box, where you can fill a specified area with a value, see Fill dialog box, page 141.

Memory Save Displays a dialog box, where you can save the contents of a specified memory area to a file, see Memory Save dialog box, page 140.

Memory Restore Displays a dialog box, where you can load the contents of a file in Intel-hex or Motorola s-record format to a specified memory zone, see Memory Restore dialog box, page 141.

Set Data Breakpoint Sets breakpoints directly in the Memory window. The breakpoint is not highlighted; you can see, edit, and remove it in the Breakpoints dialog box. The breakpoints you set in this window will be triggered for both read and write access. For more information, see Setting a data breakpoint in the Memory window, page 110.

UCSRX-3

139

Page 140: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

140

Reference information on memory and registers

Memory Save dialog boxThe Memory Save dialog box is available by choosing Debug>Memory>Save or from the context menu in the Memory window.

Figure 65: Memory Save dialog box

Use this dialog box to save the contents of a specified memory area to a file.

Zone

Selects a memory zone.

Start address

Specify the start address of the memory range to be saved.

End address

Specify the end address of the memory range to be saved.

File format

Selects the file format to be used, which is Intel-extended by default.

Filename

Specify the destination file to be used; a browse button is available for your convenience.

Save

Saves the selected range of the memory zone to the specified file.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 141: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Memory Restore dialog boxThe Memory Restore dialog box is available by choosing Debug>Memory>Restore or from the context menu in the Memory window.

Figure 66: Memory Restore dialog box

Use this dialog box to load the contents of a file in Intel-extended or Motorola S-record format to a specified memory zone.

Zone

Selects a memory zone.

Filename

Specify the file to be read; a browse button is available for your convenience.

Restore

Loads the contents of the specified file to the selected memory zone.

Fill dialog boxThe Fill dialog box is available from the context menu in the Memory window.

Figure 67: Fill dialog box

Use this dialog box to fill a specified area of memory with a value.

UCSRX-3

141

Page 142: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

142

Reference information on memory and registers

Start address

Type the start address—in binary, octal, decimal, or hexadecimal notation.

Length

Type the length—in binary, octal, decimal, or hexadecimal notation.

Zone

Selects a memory zone.

Value

Type the 8-bit value to be used for filling each memory location.

Operation

These are the available memory fill operations:

Copy Value will be copied to the specified memory area.

AND An AND operation will be performed between Value and the existing contents of memory before writing the result to memory.

XOR An XOR operation will be performed between Value and the existing contents of memory before writing the result to memory.

OR An OR operation will be performed between Value and the existing contents of memory before writing the result to memory.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 143: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

RAM Monitor Setup dialog boxThe RAM Monitor Setup dialog box is available from the E1/E20 Emulator menu when the debugger is running.

Figure 68: RAM Monitor Setup dialog box

Use this dialog box to configure the memory areas for data coverage in the Memory window.

Note: This dialog box is only available if the Emulator mode option in the Hardware Setup dialog box is set to RAM Monitor.

Display area

This area contains these columns:

Buttons

These buttons are available:

Items The memory block.

Area The memory range.

Size The memory size in bytes.

New Opens the New RAM monitor block dialog box, where you can specify a new memory range, see Edit Memory Access dialog box, page 157.

You can configure up to four memory ranges to monitor.

UCSRX-3

143

Page 144: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

144

Reference information on memory and registers

Edit RAM monitor block dialog boxThe Edit RAM monitor block dialog box is available from the RAM Monitor Setup dialog box for E1/E20 emulators.

Figure 69: Edit RAM monitor block dialog box

Use this dialog box to specify or edit a memory area to monitor using data coverage in the Memory window for E1/E20 emulators, see RAM Monitor Setup dialog box, page 143.

Start address

Specify the start address of the memory range.

End address

Specify the end address of the memory range. When you specify a start address this field will automatically be filled with the end address of the memory block, but you can modify this address.

Edit Opens the Edit RAM monitor block dialog box, where you can edit the selected memory area. See Edit Memory Access dialog box, page 157.

Delete Deletes the selected memory area definition.

Delete All Deletes all defined memory area definitions.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 145: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Symbolic Memory windowThe Symbolic Memory window is available from the View menu when the debugger is running.

Figure 70: Symbolic Memory window

This window displays how variables with static storage duration, typically variables with file scope but also static variables in functions and classes, are laid out in memory. This can be useful for better understanding memory usage or for investigating problems caused by variables being overwritten, for example buffer overruns. Other areas of use are spotting alignment holes or for understanding problems caused by buffers being overwritten.

To view the memory corresponding to a variable, you can select it in the editor window and drag it to the Symbolic Memory window.

Toolbar

The toolbar contains:

Go to The memory location or symbol you want to view.

Zone display Selects a memory zone to display, see C-SPY memory zones, page 133.

Previous Highlights the previous symbol in the display area.

Next Highlights the next symbol in the display area.

UCSRX-3

145

Page 146: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

146

Reference information on memory and registers

Display area

This area contains these columns:

There are several different ways to navigate within the memory space:

● Text that is dropped in the window is interpreted as symbols

● The scroll bar at the right-side of the window

● The toolbar buttons Next and Previous

● The toolbar list box Go to can be used for locating specific locations or symbols.

Note: Rows are marked in red when the corresponding value has changed.

Context menu

This context menu is available:

Figure 71: Symbolic Memory window context menu

These commands are available:

Location The memory address.

Data The memory contents in hexadecimal format. The data is grouped according to the size of the symbol. This column is editable.

Variable The variable name; requires that the variable has a fixed memory location. Local variables are not displayed.

Value The value of the variable. This column is editable.

Type The type of the variable.

Next Symbol Highlights the next symbol in the display area.

Previous Symbol Highlights the previous symbol in the display area.

1x Units Displays the memory contents in units of 8 bits. This applies only to rows which do not contain a variable.

2x Units Displays the memory contents in units of 16 bits.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 147: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Stack windowThe Stack window is available from the View menu.

Figure 72: Stack window

This window is a memory window that displays the contents of the stack. In addition, some integrity checks of the stack can be performed to detect and warn about problems with stack overflow. For example, the Stack window is useful for determining the optimal size of the stack.

To view the graphical stack bar:

1 Choose Tools>Options>Stack.

2 Select the option Enable graphical stack display and stack usage.

You can open several Stack windows, each showing a different stack—if several stacks are available—or the same stack with different display settings.

Note: By default, this window uses one physical breakpoint. For more information, see Breakpoint consumers, page 107.

For information about options specific to the Stack window, see the IDE Project Management and Building Guide.

4x Units Displays the memory contents in units of 32 bits.

Add to Watch Window Adds the selected symbol to the Watch window.

Current stack pointer

Unused stack memory, in light gray

Current stack pointer Used stack memory,

in dark grayStack view

The graphical stack bar with tooltip information

UCSRX-3

147

Page 148: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

148

Reference information on memory and registers

Toolbar

The graphical stack bar

Displays the state of the stack graphically.

The left end of the stack bar represents the bottom of the stack, in other words, the position of the stack pointer when the stack is empty. The right end represents the end of the memory space reserved for the stack. The graphical stack bar turns red when the stack usage exceeds a threshold that you can specify.

When the stack bar is enabled, the functionality needed to detect and warn about stack overflows is also enabled.

Place the mouse pointer over the stack bar to get tooltip information about stack usage.

Display area

This area contains these columns:

Stack Selects which stack to view. This applies to microcontrollers with multiple stacks.

Location Displays the location in memory. The addresses are displayed in increasing order. The address referenced by the stack pointer, in other words the top of the stack, is highlighted in a green color.

Data Displays the contents of the memory unit at the given location. From the Stack window context menu, you can select how the data should be displayed; as a 1-, 2-, or 4-byte group of data.

Variable Displays the name of a variable, if there is a local variable at the given location. Variables are only displayed if they are declared locally in a function, and located on the stack and not in registers.

Value Displays the value of the variable that is displayed in the Variable column.

Frame Displays the name of the function that the call frame corresponds to.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 149: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Context menu

This context menu is available:

Figure 73: Stack window context menu

These commands are available:

Show variables Displays separate columns named Variables, Value, and Frame in the Stack window. Variables located at memory addresses listed in the Stack window are displayed in these columns.

Show offsets Displays locations in the Location column as offsets from the stack pointer. When deselected, locations are displayed as absolute addresses.

1x Units Displays data in the Data column as single bytes.

2x Units Displays data in the Data column as 2-byte groups.

4x Units Displays data in the Data column as 4-byte groups.

Options Opens the IDE Options dialog box where you can set options specific to the Stack window, see the IDE Project Management and Building Guide.

UCSRX-3

149

Page 150: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

150

Reference information on memory and registers

Register windowThe Register window is available from the View menu.

Figure 74: Register window

This window gives an up-to-date display of the contents of the processor registers and special function registers, and allows you to edit their contents. Optionally, you can choose to load either predefined register groups or to define your own application-specific groups

You can open several instances of this window, which is very convenient if you want to keep track of different register groups.

To enable predefined register groups:

1 Select a device description file that suits your device, see Selecting a device description file, page 41.

2 The register groups appear in the Register window, provided that they are defined in the device description file. Note that the available register groups are also listed on the Register Filter page.

To define application-specific register groups, read about register filter options in the IDE Project Management and Building Guide.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 151: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Toolbar

Display area

Displays registers and their values. Every time C-SPY stops, a value that has changed since the last stop is highlighted. To edit the contents of a register, click it, and modify the value.

Some registers are expandable, which means that the register contains interesting bits or subgroups of bits.

To change the display format, change the Base setting on the Register Filter page—available by choosing Tools>Options.

SFR Setup windowThe SFR Setup window is available from the Project menu.

Figure 75: SFR Setup window

This window displays the currently defined SFRs that C-SPY has information about. You can choose to display only factory-defined or custom-defined SFRs, or both. If required, you can use this window to customize aspects of the SFRs. For factory-defined SFRs (that is, retrieved from the ddf file that is currently used), you can only customize the access type.

Any custom-defined SFRs are added to a dedicated register group called Custom, which you can choose to display in the Register window. Your custom-defined SFRs are saved in projectCustomSfr.sfr.

CPU Registers Selects which register group to display, by default CPU Registers. Additional register groups are predefined in the device description files that make all SFR registers available in the Register window. The device description file contains a section that defines the special function registers and their groups.

UCSRX-3

151

Page 152: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

152

Reference information on memory and registers

You can only add or modify SFRs when the C-SPY debugger is not running.

Requirements

None; this window is always available.

Display area

This area contains these columns:

You can click a name or an address to change the value. The hexadecimal 0x prefix for the address can be omitted, the value you enter will still be interpreted as hexadecimal. For example, if you enter 4567, you will get 0x4567.

You can click a column header to sort the SFRs according to the column property.

Color coding used in the display area:

Status A character that signals the status of the SFR, which can be one of:

blank, a factory-defined SFRC, a factory-defined SFR that has been modified+, a custom-defined SFR?, an SFR that is ignored for some reason. An SFR can be ignored

when a factory-defined SFR has been modified, but the SFR is no longer available, or it is located somewhere else or has a different size. Typically, this might happen if you change devices.

Name A unique name of the SFR.

Address The memory address of the SFR.

Zone The memory zone.

Size The size of the register, which can be one of 8, 16, 32, or 64.

Access The access type of the register, which can be one of Read/Write, Read only, Write only, or None.

Green Indicates that the corresponding value has changed.

Red Indicates an ignored SFR.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 153: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Context menu

This context menu is available:

Figure 76: SFR Setup window context menu

These commands are available:

Show All Shows all SFRs.

Show Custom SFRs Only Shows all custom-defined SFRs.

Show Factory SFRs Only Shows all factory-defined SFRs retrieved from the ddf file.

Add Displays the Edit SFR dialog box where you can add a new SFR, see Edit SFR dialog box, page 154.

Edit Displays the Edit SFR dialog box where you can edit an SFR, see Edit SFR dialog box, page 154.

Delete Deletes an SFR. This command only works on custom-defined SFRs.

Delete/Revert All Custom SFRs

Deletes all custom-defined SFRs and reverts all modified factory-defined SFRs to their factory settings.

Save Custom SFRs Opens a standard save dialog box to save all custom-defined SFRs.

UCSRX-3

153

Page 154: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

154

Reference information on memory and registers

Edit SFR dialog boxThe Edit SFR dialog box is available from the SFR Setup window.

Figure 77: Edit SFR dialog box

Use this dialog box to define the SFRs.

Requirements

None; this dialog box is always available.

Name

Specify the name of the SFR that you want to add or edit.

Address

Specify the address of the SFR that you want to add or edit. The hexadecimal 0x prefix for the address can be omitted, the value you enter will still be interpreted as hexadecimal. For example, if you enter 4567, you will get 0x4567.

8|16|32|64 bits Selects the display format for the selected SFR, which can be 8, 16, 32, or 64 bits. Note that the display format can only be changed for custom-defined SFRs.

Read/Write|Read only|Write only|None

Selects the access type of the selected SFR, which can be Read/Write, Read only, Write only, or None. Note that for factory-defined SFRs, the default access type is indicated.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 155: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Zone

Selects the memory zone for the SFR you want to add or edit. The list of zones is retrieved from the ddf file that is currently used.

Size

Selects the size of the SFR. Choose between 8, 16, 32, or 64 bits. Note that the display format can only be changed for custom-defined SFRs.

Access

Selects the access type of the SFR. Choose between Read/Write, Read only, Write only, or None. Note that for factory-defined SFRs, the default access type is indicated.

Memory Access Setup dialog boxThe Memory Access Setup dialog box is available from the Simulator menu.

Figure 78: Memory Access Setup dialog box

This dialog box lists all defined memory areas, where each column in the list specifies the properties of the area. In other words, the dialog box displays the memory access setup that will be used during the simulation.

UCSRX-3

155

Page 156: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

156

Reference information on memory and registers

Note: If you enable both the Use ranges based on and the Use manual ranges option, memory accesses are checked for all defined ranges.

For information about the columns and the properties displayed, see Edit Memory Access dialog box, page 157.

Use ranges based on

Selects any of the predefined alternatives for the memory access setup. Choose between:

Use manual ranges

Specify your own ranges manually via the Edit Memory Access dialog box. To open this dialog box, choose New to specify a new memory range, or select a memory zone and choose Edit to modify it. For more information, see Edit Memory Access dialog box, page 157.

The ranges you define manually are saved between debug sessions.

Memory access checking

Check for determines what to check for;

● Access type violation

● Access to unspecified ranges.

Action selects the action to be performed if an access violation occurs; choose between:

● Log violations

● Log and stop execution.

Any violations are logged in the Debug Log window.

Device description file Loads properties from the device description file.

Debug file segment information

Properties are based on the section information available in the debug file. This information is only available while debugging. The advantage of using this option, is that the simulator can catch memory accesses outside the linked application.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 157: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Monitoring memory and registers

Buttons

These buttons are available:

Note: Except for the OK and Cancel buttons, buttons are only available when the option Use manual ranges is selected.

Edit Memory Access dialog boxThe Edit Memory Access dialog box is available from the Memory Access Setup dialog box.

Figure 79: Edit Memory Access dialog box

Use this dialog box to specify the memory ranges, and assign an access type to each memory range, for which you want to detect illegal accesses during the simulation.

New Opens the Edit Memory Access dialog box, where you can specify a new memory range and attach an access type to it, see Edit Memory Access dialog box, page 157.

Edit Opens the Edit Memory Access dialog box, where you can edit the selected memory area. See Edit Memory Access dialog box, page 157.

Delete Deletes the selected memory area definition.

Delete All Deletes all defined memory area definitions.

UCSRX-3

157

Page 158: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

158

Reference information on memory and registers

Memory range

Defines the memory area for which you want to check the memory accesses:

Access type

Selects an access type to the memory range; choose between:

● Read and write

● Read only

● Write only.

Zone Selects a memory zone, see C-SPY memory zones, page 133.

Start address Specify the start address for the address range, in hexadecimal notation.

End address Specify the end address for the address range, in hexadecimal notation.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 159: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace dataThis chapter gives you information about collecting and using trace data in C-SPY®. More specifically, this means:

● Introduction to using trace

● Procedures for using trace

● Reference information on trace.

Introduction to using traceThis section introduces trace.

These topics are covered:

● Reasons for using trace

● Briefly about trace

● Requirements for using trace.

See also:

● Using the profiler, page 179

● Debugging in the power domain, page 197.

REASONS FOR USING TRACE

By using trace, you can inspect the program flow up to a specific state, for instance an application crash, and use the trace data to locate the origin of the problem. Trace data can be useful for locating programming errors that have irregular symptoms and occur sporadically.

BRIEFLY ABOUT TRACE

Your target system must be able to generate trace data. Once generated, C-SPY can collect it and you can visualize and analyze the data in various windows and dialog boxes.

Depending on your target system, different types of trace data can be generated.

UCSRX-3

159

Page 160: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

160

Procedures for using trace

Trace data is a continuously collected sequence of every executed instruction for a selected portion of the execution.

Trace features in C-SPY

In C-SPY, you can use the trace-related windows Trace, Function Trace, Timeline, and Find in Trace. In the C-SPY simulator, you can also use the windows Trace Expressions, Interrupt Log, and Interrupt Log Summary. Depending on your C-SPY driver, you can set various types of trace breakpoints and events to control the collection of trace data.

If you use the C-SPY J-Link driver, you have access to windows such as the Power Log window.

In addition, several other features in C-SPY also use trace data, features such as the Profiler, Code coverage, and Instruction profiling.

REQUIREMENTS FOR USING TRACE

The C-SPY simulator supports trace-related functionality, and there are no specific requirements.

To use trace-related functionality in you hardware debugger system, you need debug components (hardware, in some cases a debug probe, and a C-SPY driver) that all support trace. Both the C-SPY E1/E20 driver and the C-SPY J-Link driver support trace.

Note: The specific set of debug components you are using determine which trace features in C-SPY that are supported.

Procedures for using traceThis section gives you step-by-step descriptions about how to collect and use trace data.

More specifically, you will get information about:

● Getting started with trace in the C-SPY simulator

● Getting started with trace in the C-SPY hardware debugger drivers

● Trace data collection using breakpoints

● Searching in trace data

● Browsing through trace data.

GETTING STARTED WITH TRACE IN THE C-SPY SIMULATOR

To collect trace data using the C-SPY simulator, no specific build settings are required.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 161: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

To get started using trace:

1 After you have built your application and started C-SPY, choose Simulator>Trace to open the Trace window, and click the Activate button to enable collecting trace data.

2 Start the execution. When the execution stops, for instance because a breakpoint is triggered, trace data is displayed in the Trace window. For more information about the window, see Trace window, page 165.

GETTING STARTED WITH TRACE IN THE C-SPY HARDWARE DEBUGGER DRIVERS

To get started using trace:

1 For the C-SPY E20 emulator, before you start C-SPY you must choose E1/E20 Emulator>Hardware Setup and select Trace as the Emulator mode. If you are using the E1 emulator or the J-Link debug probe, you do not need to perform this step.

2 After you have started C-SPY, choose Trace Settings from the C-SPY driver menu. In the Trace Settings dialog box that appears, check if you need to change any of the default settings. For more information, see Trace Settings dialog box, page 163.

3 Open the Trace window—available from the driver-specific menu—and click the Activate button to enable trace data collection.

4 Start the execution. When the execution stops, for instance because a breakpoint is triggered, trace data is displayed in the Trace window. For more information about the window, see Trace window, page 165.

TRACE DATA COLLECTION USING BREAKPOINTS

A convenient way to collect trace data between two execution points is to start and stop the data collection using dedicated breakpoints. Choose between these alternatives:

● In the editor or Disassembly window, position your insertion point, right-click, and toggle a Trace Start or Trace Stop breakpoint from the context menu.

● In the Breakpoints window, choose Trace Start, Trace Stop, or Trace Filter.

● The C-SPY system macros __setTraceStartBreak and __setTraceStopBreak can also be used.

For more information about these breakpoints, see Trace Start breakpoints dialog box, page 174 and Trace Stop breakpoints dialog box, page 175, respectively.

UCSRX-3

161

Page 162: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

162

Procedures for using trace

SEARCHING IN TRACE DATA

When you have collected trace data, you can perform searches in the collected data to locate the parts of your code or data that you are interested in, for example, a specific interrupt or accesses of a specific variable.

You specify the search criteria in the Find in Trace dialog box and view the result in the Find in Trace window.

The Find in Trace window is very similar to the Trace window, showing the same columns and data, but only those rows that match the specified search criteria. Double-clicking an item in the Find in Trace window brings up the same item in the Trace window.

To search in your trace data:

1 In the Trace window toolbar, click the Find button.

2 In the Find in Trace dialog box, specify your search criteria.

Typically, you can choose to search for:

● A specific piece of text, for which you can apply further search criteria

● An address range

● A combination of these, like a specific piece of text within a specific address range.

For more information about the different options, see Find in Trace dialog box, page 177.

3 When you have specified your search criteria, click Find. The Find in Trace window is displayed, which means you can start analyzing the trace data. For more information, see Find in Trace window, page 178.

BROWSING THROUGH TRACE DATA

To follow the execution history, simply look and scroll in the Trace window. Alternatively, you can enter browse mode.

To enter browse mode, double-click an item in the Trace window, or click the Browse toolbar button.

The selected item turns yellow and the source and disassembly windows will highlight the corresponding location. You can now move around in the trace data using the up and down arrow keys, or by scrolling and clicking; the source and Disassembly windows will be updated to show the corresponding location. This is like stepping backward and forward through the execution history.

Double-click again to leave browse mode.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 163: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

Reference information on traceThis section gives reference information about these windows and dialog boxes:

● Trace Settings dialog box, page 163

● Trace window, page 165

● Function Trace window, page 167

● Timeline window, page 168

● Viewing Range dialog box, page 173

● Trace Start breakpoints dialog box, page 174

● Trace Stop breakpoints dialog box, page 175

● Trace Expressions window, page 176

● Find in Trace dialog box, page 177

● Find in Trace window, page 178.

Trace Settings dialog boxThe Trace Settings dialog box is available from the C-SPY driver menu.

Figure 80: Trace Settings dialog box

This dialog box is available for the:

● E1/E20 drivers

● J-Link driver.

Use this dialog box to configure trace generation and collection.

See also Getting started with trace in the C-SPY hardware debugger drivers, page 161.

UCSRX-3

163

Page 164: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

164

Reference information on trace

Trace mode

Selects the trace collection mode. Choose between:

Trace output

Controls the generation of trace data. Choose between:

Note: For the E1 emulator and the J-Link debug probe, only the setting Do not output is available.

Trace capacity

Sets the size of the trace buffer: 1, 2, 4, 8, 16, or 32 Mbytes.

Note: This option is only available for the E20 emulator.

Restart emulator when trace buffer is full

Halts execution when the trace buffer is full and restarts the emulator after the buffer has been read by the emulator. This option offers full trace, but might result in very large amounts of trace data.

Note: This option is only available for the E20 emulator.

Fill until stop Continues to collect trace data until the execution stops or a trace stop breakpoint stops the collection.

Fill until full Continues to collect trace data until the buffer is full.

CPU execution CPU execution is given priority, meaning that some trace data might be lost.

Trace output Generating trace data is given priority. Because the CPU execution is paused when trace data is generated, execution speed slows down.

Do not output No trace data is generated. The trace buffer of the MCU will be used.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 165: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

Trace windowThe Trace window is available from the C-SPY driver menu.

Figure 81: The Trace window in the simulator

This window displays the collected trace data, where the content differs depending on the C-SPY driver you are using:

Trace toolbar

The toolbar in the Trace window and in the Function trace window contains:

C-SPY simulator The window displays a collected sequence of executed machine instructions. In addition, the window can display trace data for expressions.

C-SPY hardware drivers The window displays a collected sequence of executed machine instructions.

Enable/Disable Enables and disables collecting and viewing trace data in this window. This button is not available in the Function trace window.

Clear trace data Clears the trace buffer. Both the Trace window and the Function trace window are cleared.

Toggle source Toggles the Trace column between showing only disassembly or disassembly together with the corresponding source code.

Browse Toggles browse mode on or off for a selected item in the Trace window, see Browsing through trace data, page 162.

UCSRX-3

165

Page 166: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

166

Reference information on trace

Display area

This area contains these columns:

Find Displays a dialog box where you can perform a search, see Find in Trace dialog box, page 177.

Save Displays a standard Save As dialog box where you can save the collected trace data to a text file, with tab-separated columns.

Edit Settings For the C-SPY hardware debugger drivers, this button displays the Trace Settings dialog box, see Trace Settings dialog box, page 163.

In the C-SPY simulator this button is not enabled.

Edit Expressions (C-SPY simulator only)

Opens the Trace Expressions window, see Trace Expressions window, page 176.

# A serial number for each row in the trace buffer. Simplifies the navigation within the buffer.

Cycles The number of cycles elapsed to this point. This column is only available for the C-SPY simulator driver.

Trace The collected sequence of executed machine instructions. Optionally, the corresponding source code can also be displayed.

Expression Each expression you have defined to be displayed appears in a separate column. Each entry in the expression column displays the value after executing the instruction on the same row. You specify the expressions for which you want to collect trace data in the Trace Expressions window, see Trace Expressions window, page 176. This column is only available for the C-SPY simulator driver.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 167: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

Function Trace windowThe Function Trace window is available from the C-SPY driver menu during a debug session.

Figure 82: Function Trace window

This window displays a subset of the trace data displayed in the Trace window. Instead of displaying all rows, the Function Trace window only shows trace data corresponding to calls to and returns from functions.

Toolbar

For information about the toolbar, see Trace toolbar, page 165.

Display area

For information about the columns in the display area, see Display area, page 166.

UCSRX-3

167

Page 168: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

168

Reference information on trace

Timeline windowThe Timeline window is available from the C-SPY driver menu during a debug session.

Figure 83: C-SPY Simulator Timeline window

This window is available for the:

● C-SPY simulator

● J-Link driver (J-Link debug probe only—not built-in J-Link)

This window displays trace data (for interrupt logs and for the call stack) as well as logged power values (J-Link debug probe only), as graphs in relation to a common time axis.

To display a graph and navigate on it:

1 Choose J-Link>Operating Frequency and specify the operating frequency of the MCU.

If you are using the C-SPY simulator you can ignore this step.

2 Choose Timeline from the C-SPY driver menu to open the Timeline window.

3 In the Timeline window, click in the graph area and choose Enable from the context menu to enable a specific graph.

4 Click Go on the toolbar to start executing your application. The graph appears.

To navigate in the graph, use any of these alternatives:● Right-click and from the context menu choose Zoom In or Zoom Out.

Alternatively, use the + and – keys. The graph zooms in or out depending on which command you used.

Common time axis Selection for

current graph

An active interrupt

InterruptLog Graph

CallStack Graph

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 169: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

● Right-click in the graph and from the context menu choose Navigate and the appropriate command to move backwards and forwards on the graph. Alternatively, use any of the shortcut keys: arrow keys, Home, End, and Ctrl+End.

● Double-click on a sample of interest and the corresponding source code is highlighted in the editor window and in the Disassembly window.

● Click on the graph and drag to select a time interval. Press Enter or right-click and from the context menu choose Zoom>Zoom to Selection. The selection zooms in.

Point in the graph with the mouse pointer to get detailed tooltip information for that location.

Display area

Depending on the C-SPY driver you are using, the display area can be populated with different graphs:

If a specific graph is available or not depends on abilities in hardware, debugger probe, and the C-SPY driver. See Table 3, Driver differences on page page 33, and Requirements for using trace, page 160.

At the bottom of the window, there is a common time axis that uses seconds as the time unit.

Selection and navigation

Click and drag to select. The selection extends vertically over all graphs, but appears highlighted in a darker color for the selected graph. You can navigate backward and forward in the selected graph using the left and right arrow keys. Use the Home and End keys to move to the first or last relevant point, respectively. Use the navigation keys in combination with the Shift key to extend the selection.

Interrupt Log Graph

The Interrupt Log Graph displays interrupts reported by trace or by the C-SPY simulator. In other words, the graph provides a graphical view of the interrupt events during the execution of your application, where:

● The label area at the left end of the graph shows the names of the interrupts.

Graphs C-SPY simulator C-SPY J-Link driver

Interrupt Log Graph X —

Call Stack Graph X —

Power Log Graph — X

Table 13: Supported graphs in the Timeline window

UCSRX-3

169

Page 170: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

170

Reference information on trace

● The graph itself shows active interrupts as a thick green horizontal bar. This graph is a graphical representation of the information in the Interrupt Log window, see Interrupt Log window, page 229.

Call Stack Graph

The Call Stack Graph displays the sequence of calls and returns collected by trace. At the bottom of the graph you will usually find main, and above it, the functions called from main, and so on. The horizontal bars, which represent invocations of functions, use four different colors:

● Medium green for normal C functions with debug information

● Light green for functions known to the debugger only through an assembler label

● Medium or light yellow for interrupt handlers, with the same distinctions as for green.

The numbers represent the number of cycles spent in, or between, the function invocations.

Power Log Graph

The Power Log Graph displays power measurement samples generated by the debug probe or associated hardware.

Context menu

This context menu is available:

Figure 84: Timeline window context menu for the Call Stack Graph

Note: The context menu contains some commands that are common to all graphs and some commands that are specific to each graph. The figure reflects the context menu for the Call Stack Graph, which means that the menu looks slightly different for the other graphs.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 171: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

These commands are available:

Navigate All graphs Commands for navigating over the graph(s); choose between:

Next moves the selection to the next relevant point in the graph. Shortcut key: right arrow.

Previous moves the selection backward to the previous relevant point in the graph. Shortcut key: left arrow.

First moves the selection to the first data entry in the graph. Shortcut key: Home.

Last moves the selection to the last data entry in the graph. Shortcut key: End.

End moves the selection to the last data in any displayed graph, in other words the end of the time axis. Shortcut key: Ctrl+End.

Auto Scroll All graphs Toggles auto scrolling on or off. When on, the most recent collected data is automatically displayed.

Zoom All graphs Commands for zooming the window, in other words, changing the time scale; choose between:

Zoom to Selection makes the current selection fit the window. Shortcut key: Return.

Zoom In zooms in on the time scale. Shortcut key: +.

Zoom Out zooms out on the time scale. Shortcut key: -.

10ns, 100ns, 1us, etc makes an interval of 10 nanoseconds, 100 nanoseconds, 1 microsecond, respectively, fit the window.

1ms, 10ms, etc makes an interval of 1 millisecond or 10 milliseconds, respectively, fit the window.

10m, 1h, etc makes an interval of 10 minutes or 1 hour, respectively, fit the window.

Power Log Power Log Graph

A heading that shows that the Power Log-specific commands below are available.

UCSRX-3

171

Page 172: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

172

Reference information on trace

Call Stack Call Stack Graph

A heading that shows that the Call stack-specific commands below are available.

Interrupt Interrupt Log Graph

A heading that shows that the Interrupt Log-specific commands below are available.

Enable All graphs Toggles the display of the graph on or off. If you disable a graph, that graph will be indicated as OFF in the Timeline window. If no trace data has been collected for a graph, no data will appear instead of the graph.

Viewing Range Power Log Graph

Displays a dialog box, see Viewing Range dialog box, page 173.

Size Power Log Graph

Determines the vertical size of the graph; choose between Small, Medium, and Large.

Show Numerical Value

Power Log Graph

Shows the numerical value of the variable, in addition to the graph.

Go To Source Common Displays the corresponding source code in an editor window, if applicable.

Select Graphs Common Selects which graphs to be displayed in the Timeline window.

Time Axis Unit Common Selects the unit used in the time axis; choose between Seconds and Cycles.

Profile Selection Common Enables profiling time intervals in the Function Profiler window. Note that this command is only available if the C-SPY driver supports PC Sampling.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 173: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

Viewing Range dialog boxThe Viewing Range dialog box is available from the context menu that appears when you right-click in the Power Log Graph in the Timeline window.

Figure 85: Viewing Range dialog box

This dialog box is available for the J-Link driver (J-Link debug probe only—not built-in J-Link).

Use this dialog box to specify the value range, that is, the range for the Y-axis for the graph.

Range for xxxx

Selects the viewing range for the displayed values:

Auto Uses the range according to the range of the values that are actually collected, continuously keeping track of minimum or maximum values. The currently computed range, if any, is displayed in parentheses. The range is rounded to reasonably even limits.

Factory Uses the range according to the properties of the measuring hardware.

Custom Use the text boxes to specify an explicit range.

UCSRX-3

173

Page 174: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

174

Reference information on trace

Scale

Selects the scale type of the Y-axis:

● Linear

● Logarithmic.

Trace Start breakpoints dialog boxThe Trace Start dialog box is available from the context menu that appears when you right-click in the Breakpoints window.

Figure 86: Trace Start breakpoints dialog box

To set a Trace Start breakpoint:

1 In the editor or Disassembly window, right-click and choose Trace Start from the context menu.

Alternatively, open the Breakpoints window by choosing View>Breakpoints.

2 In the Breakpoints window, right-click and choose New Breakpoint>Trace Start.

Alternatively, to modify an existing breakpoint, select a breakpoint in the Breakpoints window and choose Edit on the context menu.

3 In the Trigger At text box, specify an expression, an absolute address, or a source location. Click OK.

4 When the breakpoint is triggered, the trace data collection starts.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 175: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

Trigger At

Specify the location for the breakpoint in the text box. Alternatively, click the Edit browse button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

Trace Stop breakpoints dialog boxThe Trace Stop dialog box is available from the context menu that appears when you right-click in the Breakpoints window.

Figure 87: Trace Stop breakpoints dialog box

To set a Trace Stop breakpoint:

1 In the editor or Disassembly window, right-click and choose Trace Stop from the context menu.

Alternatively, open the Breakpoints window by choosing View>Breakpoints.

2 In the Breakpoints window, right-click and choose New Breakpoint>Trace Stop.

Alternatively, to modify an existing breakpoint, select a breakpoint in the Breakpoints window and choose Edit on the context menu.

3 In the Trigger At text box, specify an expression, an absolute address, or a source location. Click OK.

4 When the breakpoint is triggered, the trace data collection stops.

Trigger At

Specify the location for the breakpoint in the text box. Alternatively, click the Edit browse button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

UCSRX-3

175

Page 176: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

176

Reference information on trace

Trace Expressions windowThe Trace Expressions window is available from the Trace window toolbar.

Figure 88: Trace Expressions window

This dialog box is available for the C-SPY simulator.

Use this window to specify, for example, a specific variable (or an expression) for which you want to collect trace data.

Toolbar

The toolbar buttons change the order between the expressions:

Display area

Use the display area to specify expressions for which you want to collect trace data:

Each row in this area will appear as an extra column in the Trace window.

Arrow up Moves the selected row up.

Arrow down Moves the selected row down.

Expression Specify any expression that you want to collect data from. You can specify any expression that can be evaluated, such as variables and registers.

Format Shows which display format that is used for each expression. Note that you can change display format via the context menu.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 177: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Collecting and using trace data

Find in Trace dialog boxThe Find in Trace dialog box is available by clicking the Find button on the Trace window toolbar or by choosing Edit>Find and Replace>Find.

Note that the Edit>Find and Replace>Find command is context-dependent. It displays the Find in Trace dialog box if the Trace window is the current window or the Find dialog box if the editor window is the current window.

Figure 89: Find in Trace dialog box

Use this dialog box to specify the search criteria for advanced searches in the trace data.

The search results are displayed in the Find in Trace window—available by choosing the View>Messages command, see Find in Trace window, page 178.

See also Searching in trace data, page 162.

Text search

Specify the string you want to search for. To specify the search criteria, choose between:

Match Case Searches only for occurrences that exactly match the case of the specified text. Otherwise int will also find INT and Int and so on.

Match whole word Searches only for the string when it occurs as a separate word. Otherwise int will also find print, sprintf and so on.

Only search in one column

Searches only in the column you selected from the drop-down list.

UCSRX-3

177

Page 178: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

178

Reference information on trace

Address Range

Specify the address range you want to display or search. The trace data within the address range is displayed. If you also have specified a text string in the Text search field, the text string is searched for within the address range.

Find in Trace windowThe Find in Trace window is available from the View>Messages menu. Alternatively, it is automatically displayed when you perform a search using the Find in Trace dialog box or perform a search using the Find in Trace command available from the context menu in the editor window.

Figure 90: Find in Trace window

This window displays the result of searches in the trace data. Double-click an item in the Find in Trace window to bring up the same item in the Trace window.

Before you can view any trace data, you must specify the search criteria in the Find in Trace dialog box, see Find in Trace dialog box, page 177.

For more information, see Searching in trace data, page 162.

Display area

The Find in Trace window looks like the Trace window and shows the same columns and data, but only those rows that match the specified search criteria.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 179: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using the profilerThis chapter describes how to use the profiler in C-SPY®. More specifically, this means:

● Introduction to the profiler

● Procedures for using the profiler

● Reference information on the profiler.

Introduction to the profilerThis section introduces the profiler.

These topics are covered:

● Reasons for using the profiler

● Briefly about the profiler

● Requirements for using the profiler.

REASONS FOR USING THE PROFILER

Function profiling can help you find the functions in your source code where the most time is spent during execution. You should focus on those functions when optimizing your code. A simple method of optimizing a function is to compile it using speed optimization. Alternatively, you can move the data used by the function into the memory which uses the most efficient addressing mode. For detailed information about efficient memory usage, see the IAR C/C++ Development Guide for RX.

Instruction profiling can help you fine-tune your code on a very detailed level, especially for assembler source code. Instruction profiling can also help you to understand where your compiled C/C++ source code spends most of its time, and perhaps give insight into how to rewrite it for better performance.

BRIEFLY ABOUT THE PROFILER

Function profiling information is displayed in the Function Profiler window, that is, timing information for the functions in an application. Profiling must be turned on explicitly using a button on the window’s toolbar, and will stay enabled until it is turned off.

UCSRX-3

179

Page 180: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

180

Introduction to the profiler

Instruction profiling information is displayed in the Disassembly window, that is, the number of times each instruction has been executed.

Profiling sources

The profiler can use different mechanisms, or sources, to collect profiling information. Depending on the available hardware features, one or more of the sources can be used for profiling:

● Trace (calls)

The full instruction trace is analyzed to determine all function calls and returns. When the collected instruction sequence is incomplete or discontinuous, the profiling information is less accurate.

● Trace (flat) / Sampling

Each instruction in the full instruction trace or each PC sample is assigned to a corresponding function or code fragment, without regard to function calls or returns. This is most useful when the application does not exhibit normal call/return sequences, such as when you are using an RTOS, or when you are profiling code which does not have full debug information.

Trace data for the E1 emulator and the J-Link debug probe is very limited. If you are using an E1 emulator or a J-Link debug probe, PC sampling provides much better profiling data than any other source.

Power sampling

Some debug probes support regular sampling of the power consumption of the development board, or components on the board. Each sample is also associated with a PC sample and represents the power consumption (actually, the electrical current) for a small time interval preceding the time of the sample. When the profiler is set to use Power sampling, additional columns are displayed in the Profiler window. Each power sample is associated with a function or code fragment, just as with regular PC Sampling. Note that this does not imply that all the energy corresponding to a sample can be attributed to that function or code fragment. The time scales of power samples and instruction execution are vastly different; during one power measurement, the CPU has typically executed many thousands of instructions. Power sampling is a statistics tool.

REQUIREMENTS FOR USING THE PROFILER

The C-SPY simulator supports the profiler, and there are no specific requirements for using the profiler.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 181: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using the profiler

To use the profiler in your hardware debugger system, you need the appropriate hardware:

● Either a target board with built-in J-Link or a J-Link/J-Link Ultra debug probe and a J-Link RX adapter

● An E1/E20 emulator.

This table lists the C-SPY driver profiling support:

Procedures for using the profilerThis section gives you step-by-step descriptions about how to use the profiler.

More specifically, you will get information about:

● Getting started using the profiler on function level

● Getting started using the profiler on instruction level

● Selecting a time interval for profiling information.

GETTING STARTED USING THE PROFILER ON FUNCTION LEVEL

To display function profiling information in the Function Profiler window:

1 Make sure you build your application using these options:

2 To set up the profiler for function profiling:

● If you use an E20 emulator and want to use another profiling source than PC sampling, you must choose E1/E20 Emulator>Hardware Setup and choose Trace as the Emulator mode.

C-SPY driver Trace (calls) Trace (flat) Sampling Power

C-SPY simulator X X — —

C-SPY E1/E20 X X X —

C-SPY J-Link X X X X

Table 14: C-SPY driver profiling support

Category Setting

C/C++ Compiler Output>Generate debug information

Linker Output>Include debug information in output

Table 15: Project options for enabling the profiler

UCSRX-3

181

Page 182: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

182

Procedures for using the profiler

● If you use the C-SPY simulator, an E1 emulator or a J-Link debug probe, no specific settings are required.

3 When you have built your application and started C-SPY, choose Driver-menu>Function Profiler to open the Function Profiler window, and click the Enable button to turn on the profiler. Alternatively, choose Enable from the context menu that is available when you right-click in the Function Profiler window.

4 Start executing your application to collect the profiling information.

5 Profiling information is displayed in the Function Profiler window. To sort, click on the relevant column header.

6 When you start a new sampling, you can click the Clear button—alternatively, use the context menu—to clear the data.

GETTING STARTED USING THE PROFILER ON INSTRUCTION LEVEL

To display instruction profiling information in the Disassembly window:

1 When you have built your application and started C-SPY, choose View>Disassembly to open the Disassembly window, and choose Instruction Profiling>Enable from the context menu that is available when you right-click in the left-hand margin of the Disassembly window.

2 Make sure that the Show command on the context menu is selected, to display the profiling information.

3 Start executing your application to collect the profiling information.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 183: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using the profiler

4 When the execution stops, for instance because the program exit is reached or a breakpoint is triggered, you can view instruction level profiling information in the left-hand margin of the window.

Figure 91: Instruction count in Disassembly window

For each instruction, the number of times it has been executed is displayed.

Instruction profiling attempts to use the same source as the function profiler. If the function profiler is not on, the instruction profiler will try to use first trace and then sampling as source. You can change the source to be used from the context menu that is available in the Function Profiler window.

SELECTING A TIME INTERVAL FOR PROFILING INFORMATION

Normally, the profiler computes its information from all PC samples it receives, accumulating more and more information until you explicitly clear the profiling information. However, you can choose a time interval for which the profiler computes the PC samples. This feature is supported by the J-Link debug probe.

To select a time interval, follow these steps:

1 Choose J-Link>Function Profiler.

2 In the Function Profiler window, right-click and choose Source: Sampling from the context menu.

3 Execute your application to collect samples.

4 Choose View>Timeline.

UCSRX-3

183

Page 184: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

184

Procedures for using the profiler

5 In the Timeline window, click and drag to select a time interval.

Figure 92: Power Graph with a selected time interval

6 In the selected time interval, right-click and choose Profile Selection from the context menu.

The Function Profiler window now displays profiling information for the selected time interval.

Figure 93: Function Profiler window in time-interval mode

7 Click the Full/Time-interval profiling button to toggle the Full profiling view.

A selected time interval

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 185: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using the profiler

Reference information on the profilerThis section gives reference information about these windows and dialog boxes:

● Function Profiler window, page 185

● Disassembly window, page 71

See also:

● Trace Settings dialog box, page 163.

Function Profiler windowThe Function Profiler window is available from the C-SPY driver menu.

Figure 94: Function Profiler window

This window displays function profiling information.

Toolbar

The toolbar contains:

Enable/Disable Enables or disables the profiler.

Clear Clears all profiling data.

Save Opens a standard Save As dialog box where you can save the contents of the window to a file, with tab-separated columns. Only non-expanded rows are included in the list file.

Graphical view Overlays the values in the percentage columns with a graphical bar.

UCSRX-3

185

Page 186: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

186

Reference information on the profiler

Display area

The content in the display area depends on which source that is used for the profiling information:

● For the Trace (calls) source, the display area contains one line for each function compiled with debug information enabled. When some profiling information has been collected, it is possible to expand rows of functions that have called other functions. The child items for a given function list all the functions that have been called by the parent function and the corresponding statistics.

● For the Sampling and Trace (flat) sources, the display area contains one line for each C function of your application, but also lines for sections of code from the runtime library or from other code without debug information, denoted only by the corresponding assembler labels. Each executed PC address from trace data is treated as a separate sample and is associated with the corresponding line in the Profiling window. Each line contains a count of those samples.

Progress bar Displays a backlog of profiling data that is still being processed. If the rate of incoming data is higher than the rate of the profiler processing the data, a backlog is accumulated. The progress bar indicates that the profiler is still processing data, but also approximately how far the profiler has come in the process. Note that because the profiler consumes data at a certain rate and the target system supplies data at another rate, the amount of data remaining to be processed can both increase and decrease. The progress bar can grow and shrink accordingly.

Time-interval mode Toggles between profiling a selected time interval or full profiling. This toolbar button is only available if PC Sampling is supported by the debug probe.

For information about which views that are supported in the C-SPY driver you are using, see Requirements for using the profiler, page 180.

Status field Displays the range of the selected time interval, in other words, the profiled selection. This field is yellow when Time-interval profiling mode is enabled. This field is only available if PC Sampling is supported by the debug probe.

For information about which views that are supported in the C-SPY driver you are using, see Requirements for using the profiler, page 180.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 187: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using the profiler

For information about which views that are supported in the C-SPY driver you are using, see Requirements for using the profiler, page 180.

More specifically, the display area provides information in these columns:

Function All sources The name of the profiled C function.

For Sampling source, also sections of code from the runtime library or from other code without debug information, denoted only by the corresponding assembler labels, is displayed.

Calls Trace (calls) The number of times the function has been called.

Flat time Trace (calls) The time in number of executed instructions spent inside the function.

Flat time (%) Trace (calls) Flat time expressed as a percentage of the total time.

Acc. time Trace (calls) The time in number of executed instructions spent in this function and everything called by this function.

Acc. time (%) Trace (calls) Accumulated time expressed as a percentage of the total time.

PC Samples Trace (flat) and Sampling

The number of PC samples associated with the function.

PC Samples (%) Trace (flat) and Sampling

The number of PC samples associated with the function as a percentage of the total number of samples.

Power Samples Power Sampling The number of power samples associated with that function.

Energy (%) Power Sampling The accumulated value of all measurements associated with that function, expressed as a percentage of all measurements.

Avg Current [mA] Power Sampling The average measured value for all samples associated with that function.

Min Current [mA] Power Sampling The minimum measured value for all samples associated with that function.

UCSRX-3

187

Page 188: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

188

Reference information on the profiler

Context menu

This context menu is available:

Figure 95: Function Profiler window context menu

These commands are available:

* The available sources depend on the C-SPY driver you are using.

For information about which views that are supported in the C-SPY driver you are using, see Requirements for using the profiler, page 180.

Max Current [mA] Power Sampling The maximum measured value for all samples associated with that function.

Enable Enables the profiler. The system will collect information also when the window is closed.

Clear Clears all profiling data.

Source* Selects which source to be used for the profiling information. Choose between:

Sampling—the instruction count for instruction profiling represents the number of samples for each instruction.

Trace (calls)—the instruction count for instruction profiling is only as complete as the collected trace data.

Trace (flat)—the instruction count for instruction profiling is only as complete as the collected trace data.

Power Sampling Toggles power sampling information on or off.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 189: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Analyzing code performanceThis chapter describes how to use a C-SPY® hardware debugger to analyze code performance in terms of time, clock cycles, interrupts, exceptions, and instructions. More specifically, this means:

● Introduction to performance analysis

● Procedures for analyzing performance

● Reference information on performance analysis.

Introduction to performance analysisThis section introduces the performance analysis.

These topics are covered:

● Reasons for using performance analysis

● Briefly about performance analysis

● Requirements for performance analysis.

REASONS FOR USING PERFORMANCE ANALYSIS

The performance analyzing facility of the hardware debugger can measure a number of execution aspects to help you understand how well your application performs on the MCU.

Because performance analysis uses the debugger’s performance measurement circuit to measure the execution time, it does not slow down the execution of your application.

BRIEFLY ABOUT PERFORMANCE ANALYSIS

The performance analysis is capable of measuring these execution aspects:

● the total time the execution takes

● the total number of cycles the execution takes

● the number of cycles spent processing interrupts and other exceptions

● the number of executed instructions

UCSRX-3

189

Page 190: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

190

Procedures for analyzing performance

● the number of accepted interrupts and other exceptions.

The analysis can cover either the entire execution or execution between two breakpoints.

Performance analysis settings cannot be changed during the execution and the results of the analysis are displayed in the Performance Analysis window.

REQUIREMENTS FOR PERFORMANCE ANALYSIS

To use performance analysis with your hardware debugger system, you need the appropriate hardware:

● An E1/E20 emulator

● Either a target board with built-in J-Link or a J-Link/J-Link Ultra debug probe and a J-Link RX adapter.

The C-SPY simulator does not support performance analysis.

Procedures for analyzing performanceThis section gives you step-by-step descriptions about how to use the performance analysis.

More specifically, you will get information about:

● Using performance analysis.

USING PERFORMANCE ANALYSIS

Getting started analyzing code performance:

1 When you have built your application and started C-SPY, choose Driver>Performance Analysis to open the Performance Analysis window and click the Enable button to turn on the analysis.

2 Click the Setup button to display the Performance Analysis Setup dialog box.

3 Use the Condition list box to select what to measure and close the dialog box.

4 Start executing your application to begin the analysis.

5 Measurements are displayed in the Performance Analysis window.

You can also choose to set performance breakpoints to measure the execution of certain sections of code. These breakpoints will be displayed in the Performance Analysis Setup dialog box.

Before you start a new measurement, you can click the Clear button to clear the collected data. To clear just one of the counters, select it before clearing.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 191: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Analyzing code performance

Reference information on performance analysisThis section gives reference information about these windows and dialog boxes:

● Performance Analysis Setup dialog box, page 191

● Performance Analysis window, page 193

● Performance Start breakpoints dialog box, page 195

● Performance Stop breakpoints dialog box, page 196.

Performance Analysis Setup dialog box The Performance Analysis Setup dialog box is available from the Performance Analysis window and from the C-SPY Driver menu.

Figure 96: Performance Analysis Setup dialog box

This dialog box is available for the:

● C-SPY E1/E20 driver

● C-SPY J-Link driver.

UCSRX-3

191

Page 192: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

192

Reference information on performance analysis

Use this dialog box to configure the analysis. You can configure one or two counters. The size of the counters is 32 bits, which limits the amount of data they can collect. To collect more data, select the Use 64-bit counter option and use just one counter.

Condition

Selects what to measure. Choose between:

Display list

This list displays any performance start/stop breakpoints connected to the counter. Information is provided in these columns:

For information about performance start/stop breakpoints, see Performance Start breakpoints dialog box, page 195 and Performance Stop breakpoints dialog box, page 196.

Not in use The counter is not in use.

Execution cycle The number of cycles that have elapsed.

Execution cycle (supervisor mode) The number of cycles that have elapsed in supervisor mode.

Exception and interrupt cycle The number of cycles spent processing interrupts and other exceptions.

Exception cycle The number of cycles spent processing exceptions.

Interrupt cycle The number of cycles spent processing interrupts.

Execution count The number of valid instructions executed.

Exception and interrupt count The number of accepted interrupts and other exceptions.

Exception count The number of accepted exceptions.

Interrupt count The number of accepted interrupts.

Event Identifies the breakpoint.

Type The type of breakpoint: Start or Stop.

Address The memory address where the breakpoint is placed.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 193: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Analyzing code performance

Display the cycle as a time span

Converts the number of cycles spent into time and displays the value in the Time column of the Performance Analysis Window, using the operating frequency value from the Operating Frequency dialog box; see Operating Frequency dialog box, page 56. This option requires that the counter Condition measures cycles.

Measure the performance only once

Specifies that the code section between two performance breakpoints is only analyzed once, even if the execution loops. This option can only be used with performance breakpoints.

Use 64-bit counter

Combines the two 32-bit counters to use them as a single 64-bit counter. This increases the capacity when measuring the performance of a single address range. Only the settings from Counter 1 are used.

Performance Analysis windowThe Performance Analysis window is available from the C-SPY driver menu during a debug session.

Figure 97: Performance Analysis window

This window is available for the:

● C-SPY E1/E20 driver

● C-SPY J-Link driver.

This window displays the performance analysis.

UCSRX-3

193

Page 194: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

194

Reference information on performance analysis

Toolbar

The toolbar contains:

Display area

The display area provides information in these columns:

Enable/Disable Enables or disables the performance analysis. Disabling the analysis does not clear already collected data; re-enabling the analysis and running more passes will append the new data to the previously collected data.

Clear Clears all data in the selected row of the display area. If no row is selected, all data is cleared.

Setup Displays the Performance Analysis Setup dialog box where you configure the measurement. See Performance Analysis Setup dialog box, page 191.

No The number of the analysis counter. The numbers are 1 and 2 when a 32-bit counter is used for both of two ranges or 1 when the two 32-bit counters are handled as a 64-bit counter for measurement of performance in a single address range.

Condition Indicates the measurement type. See Condition, page 192.

Time The cumulative total of the analyzed execution.

If the measurement type in the Condition column is cycles, the time is calculated from the operating frequency value and the value in the Count column.

If the measurement type in the Condition column is a count, this column displays a –.

Count A decimal value that indicates the number of times the measurement has been performed. Any overflows will be indicated.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 195: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Analyzing code performance

Performance Start breakpoints dialog boxThe Performance Start dialog box is available from the context menu that appears when you right-click in the Breakpoints window.

Figure 98: Performance Start breakpoints dialog box

Use this dialog box to set performance start breakpoints.

To set a Performance Start breakpoint:

1 In the editor, Breakpoints, or Disassembly window, right-click and choose one of the two Performance Start commands from the context menu. The number of the breakpoint, 1 or 2, connects the breakpoint to one of the two counters in the Performance Analysis Setup dialog box.

Alternatively, to modify an existing breakpoint, select it in the Breakpoints window and choose Edit on the context menu.

2 In the Trigger At text box, specify an expression, an absolute address, or a source location. Click OK.

3 When the breakpoint is triggered, the performance analysis starts.

Trigger At

Specify the location for the breakpoint in the text box. Alternatively, click the Edit browse button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

UCSRX-3

195

Page 196: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

196

Reference information on performance analysis

Performance Stop breakpoints dialog boxThe Performance Stop dialog box is available from the context menu that appears when you right-click in the Breakpoints window.

Figure 99: Performance Stop breakpoints dialog box

Use this dialog box to set performance stop breakpoints.

To set a Performance Stop breakpoint:

1 In the editor, Breakpoints, or Disassembly window, right-click and choose the Performance Stop command that corresponds to a previously defined performance start breakpoint. The number of the breakpoint, 1 or 2, connects the breakpoint to one of the two counters in the Performance Analysis Setup dialog box.

Alternatively, to modify an existing breakpoint, select it in the Breakpoints window and choose Edit on the context menu.

2 In the Trigger At text box, specify an expression, an absolute address, or a source location. Click OK.

3 When the breakpoint is triggered, the performance analysis stops.

Trigger At

Specify the location for the breakpoint in the text box. Alternatively, click the Edit browse button to open the Enter Location dialog box, see Enter Location dialog box, page 128.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 197: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domainThis chapter describes techniques for power debugging and how you can use C-SPY® to find source code constructions that result in unexpected power consumption. More specifically, this means:

● Introduction to power debugging

● Optimizing your source code for power consumption

● Procedures for power debugging

● Reference information on power debugging.

Introduction to power debuggingThis section covers these topics:

● Reasons for using power debugging

● Briefly about power debugging

● Requirements for power debugging.

REASONS FOR USING POWER DEBUGGING

Long battery lifetime is a very important factor for many embedded systems in almost any market segment: medical, consumer electronics, home automation, etc. The power consumption in these systems does not only depend on the hardware design, but also on how the hardware is used. The system software controls how it is used.

For examples of when power debugging can be useful, see Optimizing your source code for power consumption, page 199.

BRIEFLY ABOUT POWER DEBUGGING

Power debugging is based on the ability to sample the power consumption—more precisely, the power being consumed by the CPU and the peripheral units—and correlate each sample with the application’s instruction sequence and hence with the source code and various events in the program execution.

UCSRX-3

197

Page 198: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

198

Introduction to power debugging

Traditionally, the main software design goal has been to use as little memory as possible. However, by correlating your application’s power consumption with its source code you can get insight into how the software affects the power consumption, and thus how it can be minimized.

Measuring power consumption

The power consumption is measured by the debug probe, which measures the voltage drop across a small resistor in series with the supply power to the device. The voltage drop is measured by a differential amplifier and then sampled by an AD converter.

You can specify a threshold and an appropriate action to be executed when the threshold value is reached. This means that you can enable or disable the power measurement or you can stop the application’s execution and determine the cause of unexpected power values.

Power debugging using C-SPY

C-SPY provides an interface for configuring your power debugging and a set of windows for viewing the power values:

● The Power Setup window is where you can specify a threshold and an action to be executed when the threshold is reached.

● The Power Log window displays all logged power values. This window can be used for finding peaks in the power logging and because the values are correlated with the executed code, you can double-click on a value in the Power Log window to get the corresponding code. The precision depends on the frequency of the samples, but there is a good chance that you find the source code sequence that caused the peak.

● The Timeline window displays power values on a time scale. This provides a convenient way of viewing the power consumption in relation to the other information displayed in the window. The Timeline window is correlated to both the Power Log window, the source code window, and the Disassembly window, which means you are just a double-click away from the source code that corresponds to the values you see on the timeline.

● The Function Profiler window combines the function profiling with the power logging to display the power consumption per function—power profiling. You will get a list of values per function and also the average values together with max and min values. Thus, you will find the regions in the application that you should focus when optimizing for power consumption.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 199: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domain

REQUIREMENTS FOR POWER DEBUGGING

To use the features in C-SPY for power debugging, you need a system with a J-Link/J-Link Ultra debug probe and a J-Link RX adapter. Target boards with built-in J-Link do not support power debugging.

Optimizing your source code for power consumptionThis section gives some examples where power debugging can be useful and thus hopefully help you identify source code constructions that can be optimized for low power consumption.

WAITING FOR DEVICE STATUS

One common construction that could cause unnecessary power consumption is to use a poll loop for waiting for a status change of, for example a peripheral device. Constructions like this example execute without interruption until the status value changes into the expected state.

while (USBD_GetState() < USBD_STATE_CONFIGURED);while ((BASE_PMC->PMC_SR & MC_MCKRDY) != PMC_MCKRDY);

To minimize power consumption, rewrite polling of a device status change to use interrupts if possible, or a timer interrupt so that the CPU can sleep between the polls.

SOFTWARE DELAYS

A software delay might be implemented as a for or while loop like for example:

i = 10000; /* A software delay */do i--;while (i != 0);

Such software delays will keep the CPU busy with executing instructions performing nothing except to make the time go by. Time delays are much better implemented using a hardware timer. The timer interrupt is set up and after that, the CPU goes down into a low power mode until it is awakened by the interrupt.

DMA VERSUS POLLED I/O

DMA has traditionally been used for increasing transfer speed. For MCUs there are plenty of DMA techniques to increase flexibility, speed, and to lower power consumption. Sometimes, CPUs can even be put into sleep mode during the DMA transfer. Power debugging lets you experiment and see directly in the debugger what effects these DMA techniques will have on power consumption compared to a traditional CPU-driven polled solution.

UCSRX-3

199

Page 200: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

200

Optimizing your source code for power consumption

LOW-POWER MODE DIAGNOSTICS

Many embedded applications spend most of their time waiting for something to happen: receiving data on a serial port, watching an I/O pin change state, or waiting for a time delay to expire. If the processor is still running at full speed when it is idle, battery life is consumed while very little is being accomplished. So in many applications, the microprocessor is only active during a very small amount of the total time, and by placing it in a low-power mode during the idle time, the battery life can be extended considerably.

A good approach is to have a task-oriented design and to use an RTOS. In a task-oriented design, a task can be defined with the lowest priority, and it will only execute when there is no other task that needs to be executed. This idle task is the perfect place to implement power management. In practice, every time the idle task is activated, it sets the microprocessor into a low-power mode. Many microprocessors and other silicon devices have a number of different low-power modes, in which different parts of the microprocessor can be turned off when they are not needed. The oscillator can for example either be turned off or switched to a lower frequency. In addition, individual peripheral units, timers, and the CPU can be stopped. The different low-power modes have different power consumption based on which peripherals are left turned on. A power debugging tool can be very useful when experimenting with different low-level modes.

You can use the Function profiler in C-SPY to compare power measurements for the task or function that sets the system in a low-power mode when different low-power modes are used. Both the mean value and the percentage of the total power consumption can be useful in the comparison.

CPU FREQUENCY

Power consumption in a CMOS MCU is theoretically given by the formula:

P = f * U2 * k

where f is the clock frequency, U is the supply voltage, and k is a constant.

Power debugging lets you verify the power consumption as a factor of the clock frequency. A system that spends very little time in sleep mode at 50 MHz is expected to spend 50% of the time in sleep mode when running at 100 MHz. You can use the power data collected in C-SPY to verify the expected behavior and if there is nonlinear dependency on the clock frequency, make sure to choose the operating frequency that gives the lowest power consumption.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 201: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domain

DETECTING MISTAKENLY UNATTENDED PERIPHERALS

Peripheral units can consume much power even when they are not actively in use. If you are designing for low power, it is important that you disable the peripheral units and not just leave them unattended when they are not in use. But for different reasons, a peripheral unit can be left with its power supply on; it can be a careful and correct design decision, or it can be an inadequate design or just a mistake. If not the first case, then more power than expected will be consumed by your application. This will be easily revealed by the Power graph in the Timeline window. Double-clicking in the Timeline window where the power consumption is unexpectedly high will take you to the corresponding source code and disassembly code. In many cases, it is enough to disable the peripheral unit when it is inactive, for example by turning off its clock which in most cases will shut down its power consumption completely.

However, there are some cases where clock gating will not be enough. Analog peripherals like converters or comparators can consume a substantial amount of power even when the clock is turned off. The Timeline window will reveal that turning off the clock was not enough and that you need to turn off the peripheral completely.

PERIPHERAL UNITS IN AN EVENT-DRIVEN SYSTEM

Consider a system where one task uses an analog comparator while executing, but the task is suspended by a higher-priority task. Ideally, the comparator should be turned off when the task is suspended and then turned on again once the task is resumed. This would minimize the power being consumed during the execution of the high-priority task.

UCSRX-3

201

Page 202: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

202

Optimizing your source code for power consumption

This is a schematic diagram of the power consumption of an assumed event-driven system where the system at the point of time t0 is in an inactive mode and the current is I0:

Figure 100: Power consumption in an event-driven system

At t1, the system is activated whereby the current rises to I1 which is the system’s power consumption in active mode when at least one peripheral device turned on, causing the current to rise to I1. At t2, the execution becomes suspended by an interrupt which is handled with high priority. Peripheral devices that were already active are not turned off, although the task with higher priority is not using them. Instead, more peripheral devices are activated by the new task, resulting in an increased current I2 between t2 and t3 where control is handed back to the task with lower priority.

The functionality of the system could be excellent and it can be optimized in terms of speed and code size. But also in the power domain, more optimizations can be made. The shadowed area represents the energy that could have been saved if the peripheral devices that are not used between t2 and t3 had been turned off, or if the priorities of the two tasks had been changed.

If you use the Timeline window, you can make a closer examination and identify that unused peripheral devices were activated and consumed power for a longer period than necessary. Naturally, you must consider whether it is worth it to spend extra clock cycles to turn peripheral devices on and off in a situation like in the example.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 203: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domain

FINDING CONFLICTING HARDWARE SETUPS

To avoid floating inputs, it is a common design practice to connect unused MCU I/O pins to ground. If your source code by mistake configures one of the grounded I/O pins as a logical 1 output, a high current might be drained on that pin. This high unexpected current is easily observed by reading the current value from the Power Graph in the Timeline window. It is also possible to find the corresponding erratic initialization code by looking at the Power Graph at application startup.

A similar situation arises if an I/O pin is designed to be an input and is driven by an external circuit, but your code incorrectly configures the input pin as output.

ANALOG INTERFERENCE

When mixing analog and digital circuits on the same board, the board layout and routing can affect the analog noise levels. To ensure accurate sampling of low-level analog signals, it is important to keep noise levels low. Obtaining a well-mixed signal design requires careful hardware considerations. Your software design can also affect the quality of the analog measurements. Performing a lot of I/O activity at the same time as sampling analog signals causes many digital lines to toggle state at the same time, which might introduce extra noise into the AD converter.

Figure 101: A noise spike recorded by an oscilloscope

Power debugging will help you investigate interference from digital and power supply lines into the analog parts. Power spikes in the vicinity of AD conversions could be the source of noise and should be investigated. All data presented in the Timeline window is correlated to the executed code. Simply double-clicking on a suspicious power value will bring up the corresponding C source code.

Procedures for power debuggingThis section gives you step-by-step descriptions of how to use features related to power debugging.

UCSRX-3

203

Page 204: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

204

Procedures for power debugging

More specifically, you will get information about:

● Displaying the application’s power profile and analyzing the result

● Detecting unexpected power usage during application execution.

See also:

● Timeline window, page 168

● Selecting a time interval for profiling information, page 183.

DISPLAYING THE APPLICATION’S POWER PROFILE AND ANALYZING THE RESULT

To view the power profile:

1 Choose J-Link>Timeline to open the Timeline window.

2 Right-click in the graph area and choose Enable from the context menu to enable the Power graph.

3 Choose J-Link>Power Log to open the Power Log window.

4 Optionally, before you start executing your application you can configure the viewing range of the Y-axis for the graph. See Viewing Range dialog box, page 173.

5 Click Go on the toolbar to start executing your application. In the Power Log window, all power values are displayed. In the Timeline window, you will see a graphical representation of the power values. For information about how to navigate on the graph, see Timeline window, page 168.

6 To analyze power consumption:

● Double-click on an interesting power value to highlight the corresponding source code is highlighted in the editor window and in the Disassembly window. The corresponding log is highlighted in the Power Log window. For examples of when this can be useful, see Optimizing your source code for power consumption, page 199.

● You can identify peripheral units that can be disabled when not used. You can detect this by analyzing the Power graph in combination with the other graphs in the Timeline window. See also Detecting mistakenly unattended peripherals, page 201.

● For a specific interrupt, you can see whether the power consumption is changed in an unexpected way after the interrupt exits, for example, if the interrupt enables a power-intensive unit and does not turn it off before exit.

● For function profiling, see Selecting a time interval for profiling information, page 183.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 205: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domain

DETECTING UNEXPECTED POWER USAGE DURING APPLICATION EXECUTION

To detect unexpected power consumption:

1 Choose J-Link>Power Setup to open the Power Setup window.

2 In the Power Setup window, specify a threshold value and the appropriate action, for example Log All and Halt CPU Above Threshold.

3 Choose J-Link>Power Log to open the Power Log window. If you continuously want to save the power values to a file, choose Choose Live Log File from the context menu. In this case you also need to choose Enable Live Logging to.

4 Start the execution.

When the power consumption passes the threshold value, the execution will stop and perform the action you specified.

If you saved your logged power values to a file, you can open that file in an external tool for further analysis.

Reference information on power debuggingThis section gives reference information for windows and dialog boxes related to power debugging:

● Power Setup window, page 206

● Power Log window, page 207.

See also:

● Trace window, page 165

● Timeline window, page 168

● Viewing Range dialog box, page 173

● Function Profiler window, page 185.

UCSRX-3

205

Page 206: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

206

Reference information on power debugging

Power Setup windowThe Power Setup window is available from the C-SPY driver menu during a debug session.

Figure 102: Power Setup window

This window is available for the J-Link driver.

Use this window to configure the power measurement.

Note: To enable power logging, choose Enable from the context menu in the Power Log window or from the context menu in the Power Log Graph in the Timeline window.

Display area

This area contains these columns:

ID A unique string that identifies the measurement channel in the probe. Use the check box to activate the channel. If the check box is deselected, logs will not be generated for that channel.

Name Specify a user-defined name.

Shunt [Ohm] This column always contains --.

Threshold Specify a threshold value in the selected unit. The action you specify will be executed when the threshold value is reached.

Unit Selects the unit for power display. Choose between: nA, uA, or mA.

Action Displays which action has been selected for the measurement channel. Choose between: Log All, Log Above Threshold, Log Below Threshold, Log All and Halt CPU Above Threshold, and Log All and Halt CPU Below Threshold.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 207: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domain

Context menu

This context menu is available:

Figure 103: Power Setup window context menu

These commands are available:

Power Log windowThe Power Log window is available from the C-SPY driver menu during a debug session.

Figure 104: Power Log window

nA, uA, mA Selects the unit for the power display. These alternatives are available for channels that measure current.

Log All Logs all values.

Log Above Threshold Logs all values above the threshold.

Log Below Threshold Logs all values below the threshold.

Log All and Halt CPU Above Threshold

Logs all values. If a logged value is above the threshold, execution is stopped.

Log All and Halt CPU Below Threshold

Logs all values. If a logged value is below the threshold, execution is stopped

UCSRX-3

207

Page 208: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

208

Reference information on power debugging

This window is available for the J-Link driver.

This window displays collected power values.

A row with only the Time/Cycles and Program Counter displayed in grey denotes a logged power value for a channel that was active during the actual collection of data but currently is disabled in the Power Setup window.

Note: There is a limit in the number of logged power values. When this limit is exceeded, the entries in the beginning of the buffer are erased.

Display area

This area contains these columns:

Time The time from the application reset until the event.

If the time is displayed in italics, the target system could not collect a correct time, but instead had to approximate it.

This column is available when you have selected Show Time from the context menu.

Cycles The number of cycles from the application reset until the event, based on the operating frequency specified in the Operating Frequency dialog box, see Operating Frequency dialog box, page 56. This information is cleared at reset.

If a cycle is displayed in italics, the target system could not collect a correct time, but instead had to approximate it.

This column is available when you have selected Show Cycles from the context menu.

Program Counter Displays one of these:

An address, which is the content of the PC, that is, the address of an instruction in close to the point where the power value was collected.

---, the target system failed to provide the debugger with any information.

Overflow in red, the communication channel failed to transmit all data from the target system.

Idle, the power value is logged during idle mode.

Name [unit] The power measurement value, expressed in the unit you specified in the Power Setup window.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 209: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugging in the power domain

Context menu

This context menu is available:

Figure 105: Power Log window context menu

These commands are available:

Enable Enables the logging system, which means power values are saved internally within the IDE. The values are displayed in the Power Log window and in the Power Graph in the Timeline window (if enabled). The system will log information also when the window is closed.

Clear Clears the power values saved internally within the IDE. The values will also be cleared when you reset the debugger, or if you change the execution frequency in the Operating Frequency dialog box.

Save to Log File Displays a standard file selection dialog box where you can choose the destination file for the logged power values. This command then saves the current content of the internal log buffer.

For information about the file, see The format of the log file, page 210.

Choose Live Log File Displays a standard file selection dialog box where you can choose a destination file for the logged power values. The power values are continuously saved to that file during execution. The content of the live log file is never automatically cleared, the logged values are simply appended at the end of the file.

For information about the file, see The format of the log file, page 210.

Enable Live Logging to Toggles live logging on or off. The logs are saved in a to the specified file.

UCSRX-3

209

Page 210: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

210

Reference information on power debugging

The format of the log file

The log file has a tab-separated format. The entries in the log file are separated by TAB and line feed. The logged power values are displayed in these columns:

Clear log file Clears the content of the live log file.

Show Time Displays the Time column in the Power Log window. This choice is also reflected in the log files.

Show Cycles Displays the Cycles column in the Power Log window. This choice is also reflected in the log files.

Time/Cycles The time from the application reset until the power value was logged.

Approx An x in the column indicates that the power value has an approximative value for time/cycle.

PC The value of the program counter close to the point where the power value was logged.

Name[unit] The corresponding value from the Power Log window, where Name and unit are according to your settings in the Power Setup window.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 211: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Code coverageThis chapter describes the code coverage functionality in C-SPY®, which helps you verify whether all parts of your code have been executed. More specifically, this means:

● Introduction to code coverage

● Reference information on code coverage.

Introduction to code coverageThis section covers these topics:

● Reasons for using code coverage

● Briefly about code coverage

● Requirements for using code coverage.

REASONS FOR USING CODE COVERAGE

The code coverage functionality is useful when you design your test procedure to verify whether all parts of the code have been executed. It also helps you identify parts of your code that are not reachable.

BRIEFLY ABOUT CODE COVERAGE

The Code Coverage window reports the status of the current code coverage analysis. For every program, module, and function, the analysis shows the percentage of code that has been executed since code coverage was turned on up to the point where the application has stopped. In addition, all statements that have not been executed are listed. The analysis will continue until turned off.

REQUIREMENTS FOR USING CODE COVERAGE

Code coverage is only supported by the C-SPY Simulator.

UCSRX-3

211

Page 212: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

212

Reference information on code coverage

Reference information on code coverageThis section gives reference information about these windows and dialog boxes:

● Code Coverage window, page 212.

See also Single stepping, page 66.

Code Coverage windowThe Code Coverage window is available from the View menu.

Figure 106: Code Coverage window

This window reports the status of the current code coverage analysis. For every program, module, and function, the analysis shows the percentage of code that has been executed since code coverage was turned on up to the point where the application has stopped. In addition, all statements that have not been executed are listed. The analysis will continue until turned off.

An asterisk (*) in the title bar indicates that C-SPY has continued to execute, and that the Code Coverage window must be refreshed because the displayed information is no longer up to date. To update the information, use the Refresh command.

To get started using code coverage:

1 Before using the code coverage functionality you must build your application using these options:

Category Setting

C/C++ Compiler Output>Generate debug information

Linker Output>Include debug information in output

Table 16: Project options for enabling code coverage

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 213: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Code coverage

2 After you have built your application and started C-SPY, choose View>Code Coverage to open the Code Coverage window.

3 Click the Activate button, alternatively choose Activate from the context menu, to switch on code coverage.

4 Start the execution. When the execution stops, for instance because the program exit is reached or a breakpoint is triggered, click the Refresh button to view the code coverage information.

Display area

The code coverage information is displayed in a tree structure, showing the program, module, function, and statement levels. The window displays only source code that was compiled with debug information. Thus, startup code, exit code, and library code is not displayed in the window. Furthermore, coverage information for statements in inlined functions is not displayed. Only the statement containing the inlined function call is marked as executed. The plus sign and minus sign icons allow you to expand and collapse the structure.

These icons give you an overview of the current status on all levels:

The percentage displayed at the end of every program, module, and function line shows the amount of statements that has been covered so far, that is, the number of executed statements divided with the total number of statements.

For statements that have not been executed (yellow diamond), the information displayed is the column number range and the row number of the statement in the source window, followed by the address of the step point:

<column_start>-<column_end>:row address.

Debugger Plugins>Code Coverage

Category Setting

Table 16: Project options for enabling code coverage

Red diamond Signifies that 0% of the modules or functions has been executed.

Green diamond Signifies that 100% of the modules or functions has been executed.

Red and green diamond Signifies that some of the modules or functions have been executed.

Yellow diamond Signifies a statement that has not been executed.

UCSRX-3

213

Page 214: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

214

Reference information on code coverage

A statement is considered to be executed when one of its instructions has been executed. When a statement has been executed, it is removed from the window and the percentage is increased correspondingly.

Double-clicking a statement or a function in the Code Coverage window displays that statement or function as the current position in the source window, which becomes the active window. Double-clicking a module on the program level expands or collapses the tree structure.

Context menu

This context menu is available:

Figure 107: Code coverage window context menu

These commands are available:

Activate Switches code coverage on and off during execution.

Clear Clears the code coverage information. All step points are marked as not executed.

Refresh Updates the code coverage information and refreshes the window. All step points that have been executed since the last refresh are removed from the tree.

Auto-refresh Toggles the automatic reload of code coverage information on and off. When turned on, the code coverage information is reloaded automatically when C-SPY stops at a breakpoint, at a step point, and at program exit.

Save As Saves the current code coverage result in a text file.

Save session Saves your code coverage session data to a *.dat file. This is useful if you for some reason must abort your debug session, but want to continue the session later on. This command is available on the toolbar.

Restore session Restores previously saved code coverage session data. This is useful if you for some reason must abort your debug session, but want to continue the session later on. This command is available on the toolbar.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 215: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

InterruptsThis chapter describes how C-SPY® can help you test the logic of your interrupt service routines and debug the interrupt handling in the target system. Interrupt logging provides you with comprehensive information about the interrupt events. More specifically, this chapter gives:

● Introduction to interrupts

● Procedures for interrupts

● Reference information on interrupts.

Introduction to interruptsThis section introduces you to interrupt logging and to interrupt simulation.

This section covers these topics:

● Briefly about interrupt logging

● Briefly about the interrupt simulation system

● Interrupt characteristics

● Interrupt simulation states

● C-SPY system macros for interrupt simulation

● Target-adapting the interrupt simulation system.

See also:

● Reference information on C-SPY system macros, page 247

● Using breakpoints, page 103

● The IAR C/C++ Development Guide for RX.

BRIEFLY ABOUT INTERRUPT LOGGING

Interrupt logging provides you with comprehensive information about the interrupt events. This might be useful for example, to help you locate which interrupts you can fine-tune to become faster. You can log entrances and exits to and from interrupts. You can also log internal interrupt status information, such as triggered, expired, etc. The

UCSRX-3

215

Page 216: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

216

Introduction to interrupts

logs are displayed in the Interrupt Log window and a summary is available in the Interrupt Log Summary window. The Interrupt Graph in the Timeline window provides a graphical view of the interrupt events during the execution of your application program.

Interrupt logging is supported by the C-SPY simulator.

BRIEFLY ABOUT THE INTERRUPT SIMULATION SYSTEM

By simulating interrupts, you can test the logic of your interrupt service routines and debug the interrupt handling in the target system long before any hardware is available. If you use simulated interrupts in conjunction with C-SPY macros and breakpoints, you can compose a complex simulation of, for instance, interrupt-driven peripheral devices.

The C-SPY Simulator includes an interrupt simulation system where you can simulate the execution of interrupts during debugging. You can configure the interrupt simulation system so that it resembles your hardware interrupt system.

The interrupt system has the following features:

● Simulated interrupt support for the RX microcontroller

● Single-occasion or periodical interrupts based on the cycle counter

● Predefined interrupts for various devices

● Configuration of hold time, probability, and timing variation

● State information for locating timing problems

● Configuration of interrupts using a dialog box or a C-SPY system macro—that is, one interactive and one automating interface. In addition, you can instantly force an interrupt.

● A log window which continuously displays events for each defined interrupt.

● A status window that shows the current interrupt activities.

All interrupts you define using the Interrupt Setup dialog box are preserved between debug sessions, unless you remove them. A forced interrupt, on the other hand, exists only until it has been serviced and is not preserved between sessions.

The interrupt simulation system is activated by default, but if not required, you can turn off the interrupt simulation system to speed up the simulation. To turn it off, use either the Interrupt Setup dialog box or a system macro.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 217: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

INTERRUPT CHARACTERISTICS

The simulated interrupts consist of a set of characteristics which lets you fine-tune each interrupt to make it resemble the real interrupt on your target hardware. You can specify a first activation time, a repeat interval, a hold time, a variance, and a probability.

Figure 108: Simulated interrupt configuration

The interrupt simulation system uses the cycle counter as a clock to determine when an interrupt should be raised in the simulator. You specify the first activation time, which is based on the cycle counter. C-SPY will generate an interrupt when the cycle counter has passed the specified activation time. However, interrupts can only be raised between instructions, which means that a full assembler instruction must have been executed before the interrupt is generated, regardless of how many cycles an instruction takes.

To define the periodicity of the interrupt generation you can specify the repeat interval which defines the amount of cycles after which a new interrupt should be generated. In addition to the repeat interval, the periodicity depends on the two options probability—the probability, in percent, that the interrupt will actually appear in a period—and variance—a time variation range as a percentage of the repeat interval. These options make it possible to randomize the interrupt simulation. You can also specify a hold time which describes how long the interrupt remains pending until removed if it has not been processed. If the hold time is set to infinite, the corresponding pending bit will be set until the interrupt is acknowledged or removed.

INTERRUPT SIMULATION STATES

The interrupt simulation system contains status information that you can use for locating timing problems in your application. The Interrupt Status window displays the available status information. For an interrupt, these states can be displayed: Idle, Pending, Executing, or Suspended.

UCSRX-3

217

Page 218: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

218

Introduction to interrupts

A repeat interval longer than execution time

For a repeatable interrupt that has a specified repeat interval which is longer than the execution time, the status information at different times can look like this:

Figure 109: Simulation states - example 1

Note: The interrupt activation signal—also known as the pending bit—is automatically deactivated the moment the interrupt is acknowledged by the interrupt handler.

A repeat interval shorter than execution time

Assume an interrupt repeat interval that is shorter than the execution time, and that the interrupt is reentrant (or non-maskable). In this case, when the second interrupt invocation occurs, the one currently executing is suspended. It will remain suspended until the currently executing interrupt (number 2) has finished. Then, execution of interrupt number 1 will be resumed.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 219: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

The status information at different times looks like this:

Figure 110: Simulation states - example 2

In this case, the execution time of the interrupt handler is too long compared to the repeat interval, which might indicate that you should rewrite your interrupt handler and make it faster, or that you should specify a longer repeat interval for the interrupt simulation system.

C-SPY SYSTEM MACROS FOR INTERRUPT SIMULATION

Macros are useful when you already have sorted out the details of the simulated interrupt so that it fully meets your requirements. If you write a macro function containing definitions for the simulated interrupts, you can execute the functions automatically when C-SPY starts. Another advantage is that your simulated interrupt definitions will be documented if you use macro files, and if you are several engineers involved in the development project you can share the macro files within the group.

The C-SPY Simulator provides these predefined system macros related to interrupts:

__enableInterrupts

__disableInterrupts

__orderInterrupt

__cancelInterrupt

__cancelAllInterrupts

__popSimulatorInterruptExecutingStack

UCSRX-3

219

Page 220: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

220

Procedures for interrupts

The parameters of the first five macros correspond to the equivalent entries of the Interrupts dialog box.

For more information about each macro, see Reference information on C-SPY system macros, page 247.

TARGET-ADAPTING THE INTERRUPT SIMULATION SYSTEM

The interrupt simulation system is easy to use. However, to take full advantage of the interrupt simulation system you should be familiar with how to adapt it for the processor you are using.

The interrupt simulation has the same behavior as the hardware. This means that the execution of an interrupt is dependent on the status of the global interrupt enable bit. The execution of maskable interrupts is also dependent on the status of the individual interrupt enable bits.

To perform these actions for various devices, the interrupt system must have detailed information about each available interrupt. Except for default settings, this information is provided in the device description files. The default settings are used if no device description file has been specified.

For information about device description files, see Selecting a device description file, page 41.

Procedures for interruptsThis section gives you step-by-step descriptions about how to use the interrupt simulation system.

More specifically, you will get information about:

● Simulating a simple interrupt

● Simulating an interrupt in a multi-task system

See also:

● Registering and executing using setup macros and setup files, page 238 for details about how to use a setup file to define simulated interrupts at C-SPY startup

● The tutorial Simulating an interrupt in the Information Center.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 221: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

SIMULATING A SIMPLE INTERRUPT

This example demonstrates the method for simulating a timer interrupt. However, the procedure can also be used for other types of interrupts.

To simulate and debug an interrupt:

1 Assume this simple application which contains an interrupt service routine for a timer, which increments a tick variable. The main function sets the necessary status registers. The application exits when 100 interrupts have been generated.

#include <stdio.h>#include "ior5f56108.h"#include <intrinsics.h>

volatile int ticks = 0;void main (void){ /* Add your timer setup code here */

__enable_interrupt(); /* Enable interrupts */ while (ticks < 100); /* Endless loop */ printf("Done\n");}

/* Timer interrupt service routine */#pragma vector = INT_TIMER__interrupt void basic_timer(void){ ticks += 1;}

2 Add your interrupt service routine to your application source code and add the file to your project.

3 Choose Project>Options>Debugger>Setup to see the name and location of the device description file that is being used. Open it to define an interrupt that C-SPY can simulate. The device description file contains the information you need.

4 Build your project and start the simulator.

UCSRX-3

221

Page 222: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

222

Procedures for interrupts

5 Choose Simulator>Interrupt Setup to open the Interrupts Setup dialog box. Select the Enable interrupt simulation option to enable interrupt simulation. Click New to open the Edit Interrupt dialog box. For the Timer example, verify these settings:

Click OK.

6 Execute your application. If you have enabled the interrupt properly in your application source code, C-SPY will:

● Generate an interrupt when the cycle counter has passed 4000

● Continuously repeat the interrupt after approximately 2000 cycles.

7 To watch the interrupt in action, choose Simulator>Interrupt Log to open the Interrupt Log window.

8 From the context menu, available in the Interrupt Log window, choose Enable to enable the logging. If you restart program execution, status information about entrances and exits to and from interrupts will now appear in the Interrupt Log window.

For information about how to get a graphical representation of the interrupts correlated with a time axis, see Timeline window, page 168.

SIMULATING AN INTERRUPT IN A MULTI-TASK SYSTEM

If you are using interrupts in such a way that the normal instruction used for returning from an interrupt handler is not used, for example in an operating system with task-switching, the simulator cannot automatically detect that the interrupt has finished executing. The interrupt simulation system will work correctly, but the status information in the Interrupt Setup dialog box might not look as you expect. If too many interrupts are executing simultaneously, a warning might be issued.

To simulate a normal interrupt exit:

1 Set a code breakpoint on the instruction that returns from the interrupt function.

2 Specify the __popSimulatorInterruptExecutingStack macro as a condition to the breakpoint.

Option Settings

Interrupt INT_TIMER

First activation 4000

Repeat interval 2000

Hold time 10

Probability (%) 100

Variance (%) 0

Table 17: Timer interrupt settings

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 223: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

When the breakpoint is triggered, the macro is executed and then the application continues to execute automatically.

Reference information on interruptsThis section gives reference information about these windows and dialog boxes:

● Interrupt Setup dialog box, page 223

● Edit Interrupt dialog box, page 225

● Forced Interrupt window, page 226

● Interrupt Status window, page 227

● Interrupt Log window, page 229

● Interrupt Log Summary window, page 231.

Interrupt Setup dialog boxThe Interrupt Setup dialog box is available by choosing Simulator>Interrupt Setup.

Figure 111: Interrupt Setup dialog box

This dialog box lists all defined interrupts. Use this dialog box to enable or disable the interrupt simulation system, as well as to enable or disable individual interrupts.

Enable interrupt simulation

Enables or disables interrupt simulation. If the interrupt simulation is disabled, the definitions remain but no interrupts are generated. Note that you can also enable and disable installed interrupts individually by using the check box to the left of the interrupt name in the list of installed interrupts.

UCSRX-3

223

Page 224: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

224

Reference information on interrupts

Display area

This area contains these columns:

Buttons

These buttons are available:

Interrupt Lists all interrupts. Use the checkbox to enable or disable the interrupt.

ID A unique interrupt identifier.

Type Shows the type of the interrupt. The type can be one of:

Forced, a single-occasion interrupt defined in the Forced Interrupt Window.

Single, a single-occasion interrupt.Repeat, a periodically occurring interrupt.

If the interrupt has been set from a C-SPY macro, the additional part (macro) is added, for example: Repeat(macro).

Timing The timing of the interrupt. For a Single and Forced interrupt, the activation time is displayed. For a Repeat interrupt, the information has the form: Activation Time + n*Repeat Time. For example, 2000 + n*2345. This means that the first time this interrupt is triggered, is at 2000 cycles and after that with an interval of 2345 cycles.

New Opens the Edit Interrupt dialog box, see Edit Interrupt dialog box, page 225.

Edit Opens the Edit Interrupt dialog box, see Edit Interrupt dialog box, page 225.

Delete Removes the selected interrupt.

Delete All Removes all interrupts.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 225: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

Edit Interrupt dialog boxThe Edit Interrupt dialog box is available from the Interrupt Setup dialog box.

Figure 112: Edit Interrupt dialog box

Use this dialog box to interactively fine-tune the interrupt parameters. You can add the parameters and quickly test that the interrupt is generated according to your needs.

Note: You can only edit or remove non-forced interrupts.

Interrupt

Selects the interrupt that you want to edit. The drop-down list contains all available interrupts. Your selection will automatically update the Description box. The list is populated with entries from the device description file that you have selected.

Description

A description of the selected interrupt, if available. The description is retrieved from the selected device description file. See this file for a detailed description. For interrupts specified using the system macro __orderInterrupt, the Description box is empty.

First activation

Specify the value of the cycle counter after which the specified type of interrupt will be generated.

Repeat interval

Specify the periodicity of the interrupt in cycles.

UCSRX-3

225

Page 226: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

226

Reference information on interrupts

Variance %

Selects a timing variation range, as a percentage of the repeat interval, in which the interrupt might occur for a period. For example, if the repeat interval is 100 and the variance 5%, the interrupt might occur anywhere between T=95 and T=105, to simulate a variation in the timing.

Hold time

Specify how long, in cycles, the interrupt remains pending until removed if it has not been processed. If you select Infinite, the corresponding pending bit will be set until the interrupt is acknowledged or removed.

Probability %

Selects the probability, in percent, that the interrupt will actually occur within the specified period.

Forced Interrupt windowThe Forced Interrupt window is available from the Simulator menu.

Figure 113: Forced Interrupt window

Use this window to force an interrupt instantly. This is useful when you want to check your interrupt logistics and interrupt routines.

The hold time for a forced interrupt is infinite, and the interrupt exists until it has been serviced or until a reset of the debug session.

To force an interrupt:

1 Enable the interrupt simulation system, see Interrupt Setup dialog box, page 223.

2 Double-click the interrupt in the Forced Interrupt window, or select the interrupt and click Trigger.

Display area

Lists all available interrupts and their definitions. The description field is editable and the information is retrieved from the selected device description file. See this file for a detailed description.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 227: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

Trigger

Triggers the interrupt you selected in the display area.

Interrupt Status windowThe Interrupt Status window is available from the Simulator menu.

Figure 114: Interrupt Status window

This window shows the status of all the currently active interrupts.

Display area

This area contains these columns:

Interrupt Lists all interrupts.

ID A unique interrupt identifier.

Type Shows the type of the interrupt. The type can be one of:

Forced, a single-occasion interrupt defined in the Forced Interrupt Window.

Single, a single-occasion interrupt.Repeat, a periodically occurring interrupt.

If the interrupt has been set from a C-SPY macro, the additional part (macro) is added, for example: Repeat(macro).

For repeatable interrupts there might be additional information about how many interrupts of the same type that are simultaneously executing (n executing). If n is larger than one, there is a reentrant interrupt in your interrupt simulation system that never finishes executing, which might indicate that there is a problem in your application.

UCSRX-3

227

Page 228: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

228

Reference information on interrupts

Status Shows the state of the interrupt:

Idle, the interrupt activation signal is low (deactivated).Pending, the interrupt activation signal is active, but the

interrupt has not been acknowledged yet by the interrupt handler.

Executing, the interrupt is currently being serviced, that is the interrupt handler function is executing.

Suspended, the interrupt is currently suspended.

Next Time Displays the next time the interrupt is triggered. Interrupts that do not have a next time will show --.

Timing The timing of the interrupt. For a Single and Forced interrupt, the activation time is displayed. For a Repeat interrupt, the information has the form: Activation Time + n*Repeat Time. For example, 2000 + n*2345. This means that the first time this interrupt is triggered, is at 2000 cycles and after that with an interval of 2345 cycles.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 229: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

Interrupt Log windowThe Interrupt Log window is available from the Simulator menu.

Figure 115: Interrupt Log window

This window logs entrances and exits to and from interrupts. The information is useful for debugging the interrupt handling in the target system. When the Interrupt Log window is open, it is updated continuously at runtime.

Note: There is a limit on the number of saved logs. When this limit is exceeded, the entries in the beginning of the buffer are erased.

Display area

This area contains these columns:

Grey rows indicateexits from interrupts

White rowsindicate entrances

to interrupts

Interrupt that occurswithin another interrupt

Time The time for the interrupt entrance, based on an internally specified clock frequency.

This column is available when you have selected Show time from the context menu.

UCSRX-3

229

Page 230: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

230

Reference information on interrupts

Interrupt Log window context menu

This context menu is available in the Interrupt Log window and in the Interrupt Log Summary window:

Figure 116: Interrupt Log window context menu

Note: The commands are the same in both windows, but they only operate on the specific window.

These commands are available:

Cycles The number of cycles from the start of the execution until the event.

This column is available when you have selected Show cycles from the context menu.

Interrupt The interrupt as defined in the device description file.

Status Shows the event status of the interrupt:

Triggered, the interrupt has passed its activation time.Forced, the same as Triggered, but the interrupt was forced from

the Forced Interrupt window.Enter, the interrupt is currently executing.Leave, the interrupt has been executed.Expired, the interrupt hold time has expired without the interrupt

being executed.Rejected, the interrupt has been rejected because the necessary

interrupt registers were not set up to accept the interrupt.

Program Counter The value of the program counter when the event occurred.

Execution Time/Cycles

The time spent in the interrupt, calculated using the Enter and Leave timestamps. This includes time spent in any subroutines or other interrupts that occurred in the specific interrupt.

Enable Enables the logging system. The system will log information also when the window is closed.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 231: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Interrupts

Interrupt Log Summary windowThe Interrupt Log Summary window is available from the Simulator menu.

Figure 117: Interrupt Log Summary window

This window displays a summary of logs of entrances and exits to and from interrupts.

For information about how to get a graphical view of the interrupt events during the execution of your application, see Timeline window, page 168.

Display area

Each row in this area displays some statistics about the specific interrupt based on the log information in these columns:

Show time Displays the Time column in the Interrupt Log window.

Show cycles Displays the Cycles column in the Interrupt Log window.

Clear Deletes the log information. Note that this will happen also when you reset the debugger.

Save to log file Displays a dialog box where you can select the destination file for the log information. The entries in the log file are separated by TAB and LF. An X in the Approx column indicates that the time stamp is an approximation.

Interrupt* The type of interrupt that occurred.

Count The number of times the interrupt occurred.

First time The first time the interrupt was executed.

Total time** The accumulated time spent in the interrupt.

Fastest** The fastest execution of a single interrupt of this type.

Slowest** The slowest execution of a single interrupt of this type.

UCSRX-3

231

Page 232: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

232

Reference information on interrupts

* At the bottom of the column, the current time or cycles is displayed—the number of cycles or the execution time since the start of execution. Overflow count and approximative time count is always zero.** Calculated in the same way as for the Execution time/cycles in the Interrupt Log window.† The interval is specified as the time interval between the entry time for two consecutive interrupts.

Context menu

See Interrupt Log window context menu, page 230.

Max interval† The longest time between two interrupts of this type.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 233: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros C-SPY® includes a comprehensive macro language which allows you to automate the debugging process and to simulate peripheral devices.

This chapter describes the C-SPY macro language, its features, for what purpose these features can be used, and how to use them. More specifically, this means:

● Introduction to C-SPY macros

● Procedures for using C-SPY macros

● Reference information on the macro language

● Reference information on reserved setup macro function names

● Reference information on C-SPY system macros.

Introduction to C-SPY macrosThis section covers these topics:

● Reasons for using C-SPY macros

● Briefly about using C-SPY macros

● Briefly about setup macro functions and files

● Briefly about the macro language.

REASONS FOR USING C-SPY MACROS

You can use C-SPY macros either by themselves or in conjunction with complex breakpoints and interrupt simulation to perform a wide variety of tasks. Some examples where macros can be useful:

● Automating the debug session, for instance with trace printouts, printing values of variables, and setting breakpoints.

● Hardware configuring, such as initializing hardware registers.

● Feeding your application with simulated data during runtime.

UCSRX-3

233

Page 234: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

234

Introduction to C-SPY macros

● Simulating peripheral devices, see the chapter Interrupts. This only applies if you are using the simulator driver.

● Developing small debug utility functions, for instance calculating the stack depth.

BRIEFLY ABOUT USING C-SPY MACROS

To use C-SPY macros, you should:

● Write your macro variables and functions and collect them in in one or several macro files

● Register your macros

● Execute your macros.

For registering and executing macros, there are several methods to choose between. Which method you choose depends on which level of interaction or automation you want, and depending on at which stage you want to register or execute your macro.

BRIEFLY ABOUT SETUP MACRO FUNCTIONS AND FILES

There are some reserved setup macro function names that you can use for defining macro functions which will be called at specific times, such as:

● Once after communication with the target system has been established but before downloading the application software

● Once after your application software has been downloaded

● Each time the reset command is issued

● Once when the debug session ends.

To define a macro function to be called at a specific stage, you should define and register a macro function with one of the reserved names. For instance, if you want to clear a specific memory area before you load your application software, the macro setup function execUserPreload should be used. This function is also suitable if you want to initialize some CPU registers or memory-mapped peripheral units before you load your application software.

You should define these functions in a setup macro file, which you can load before C-SPY starts. Your macro functions will then be automatically registered each time you start C-SPY. This is convenient if you want to automate the initialization of C-SPY, or if you want to register multiple setup macros.

For more information about each setup macro function, see Reference information on reserved setup macro function names, page 246.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 235: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

BRIEFLY ABOUT THE MACRO LANGUAGE

The syntax of the macro language is very similar to the C language. There are:

● Macro statements, which are similar to C statements.

● Macro functions, which you can define with or without parameters and return values.

● Predefined built-in system macros, similar to C library functions, which perform useful tasks such as opening and closing files, setting breakpoints, and defining simulated interrupts.

● Macro variables, which can be global or local, and can be used in C-SPY expressions.

● Macro strings, which you can manipulate using predefined system macros.

For more information about the macro language components, see Reference information on the macro language, page 241.

Example

Consider this example of a macro function which illustrates the various components of the macro language:

__var oldVal;CheckLatest(val){ if (oldval != val) { __message "Message: Changed from ", oldval, " to ", val, "\n"; oldval = val; }}

Note: Reserved macro words begin with double underscores to prevent name conflicts.

Procedures for using C-SPY macrosThis section gives you step-by-step descriptions about how to register and execute C-SPY macros.

More specifically, you will get information about:

● Registering C-SPY macros—an overview

● Executing C-SPY macros—an overview

● Using the Macro Configuration dialog box

● Registering and executing using setup macros and setup files

UCSRX-3

235

Page 236: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

236

Procedures for using C-SPY macros

● Executing macros using Quick Watch

● Executing a macro by connecting it to a breakpoint.

For more examples using C-SPY macros, see:

● The tutorial Simulating an interrupt in the Information Center

● Initializing target hardware before C-SPY starts, page 46.

REGISTERING C-SPY MACROS—AN OVERVIEW

C-SPY must know that you intend to use your defined macro functions, and thus you must register your macros. There are various ways to register macro functions:

● You can register macros interactively in the Macro Configuration dialog box, see Using the Macro Configuration dialog box, page 237.

● You can register macro functions during the C-SPY startup sequence, see Registering and executing using setup macros and setup files, page 238.

● You can register a file containing macro function definitions, using the system macro __registerMacroFile. This means that you can dynamically select which macro files to register, depending on the runtime conditions. Using the system macro also lets you register multiple files at the same moment. For information about the system macro, see __registerMacroFile, page 260.

Which method you choose depends on which level of interaction or automation you want, and depending on at which stage you want to register your macro.

EXECUTING C-SPY MACROS—AN OVERVIEW

There are various ways to execute macro functions:

● You can execute macro functions during the C-SPY startup sequence and at other predefined stages during the debug session by defining setup macro functions in a setup macro file, see Registering and executing using setup macros and setup files, page 238.

● The Quick Watch window lets you evaluate expressions, and can thus be used for executing macro functions. For an example, see Executing macros using Quick Watch, page 239.

● A macro can be connected to a breakpoint; when the breakpoint is triggered the macro is executed. For an example, see Executing a macro by connecting it to a breakpoint, page 240.

Which method you choose depends on which level of interaction or automation you want, and depending on at which stage you want to execute your macro.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 237: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

USING THE MACRO CONFIGURATION DIALOG BOX

The Macro Configuration dialog box is available by choosing Debug>Macros.

Figure 118: Macro Configuration dialog box

Use this dialog box to list, register, and edit your macro files and functions. The dialog box offers you an interactive interface for registering your macro functions which is convenient when you develop macro functions and continuously want to load and test them.

Macro functions that have been registered using the dialog box are deactivated when you exit the debug session, and will not automatically be registered at the next debug session.

To register a macro file:

1 Select the macro files you want to register in the file selection list, and click Add or Add All to add them to the Selected Macro Files list. Conversely, you can remove files from the Selected Macro Files list using Remove or Remove All.

UCSRX-3

237

Page 238: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

238

Procedures for using C-SPY macros

2 Click Register to register the macro functions, replacing any previously defined macro functions or variables. Registered macro functions are displayed in the scroll list under Registered Macros.

Note: System macros cannot be removed from the list, they are always registered.

To list macro functions:

1 Select All to display all macro functions, select User to display all user-defined macros, or select System to display all system macros.

2 Click either Name or File under Registered Macros to display the column contents sorted by macro names or by file. Clicking a second time sorts the contents in the reverse order.

To modify a macro file:

Double-click a user-defined macro function in the Name column to open the file where the function is defined, allowing you to modify it.

REGISTERING AND EXECUTING USING SETUP MACROS AND SETUP FILES

It can be convenient to register a macro file during the C-SPY startup sequence. To do this, specify a macro file which you load before starting the debugger. Your macro functions will be automatically registered each time you start the debugger.

If you use the reserved setup macro function names to define the macro functions, you can define exactly at which stage you want the macro function to be executed.

To define a setup macro function and load it during C-SPY startup:

1 Create a new text file where you can define your macro function.

For example:

execUserSetup(){ ... __registerMacroFile("MyMacroUtils.mac"); __registerMacroFile("MyDeviceSimulation.mac");

}

This macro function registers the additional macro files MyMacroUtils.mac and MyDeviceSimulation.mac. Because the macro function is defined with the function name execUserSetup, it will be executed directly after your application has been downloaded.

2 Save the file using the filename extension mac.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 239: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

3 Before you start C-SPY, choose Project>Options>Debugger>Setup. Select Use Setup file and choose the macro file you just created.

The macros will now be registered during the C-SPY startup sequence.

EXECUTING MACROS USING QUICK WATCH

The Quick Watch window lets you dynamically choose when to execute a macro function.

1 Consider this simple macro function that checks the status of a watchdog timer interrupt enable bit:

WDTstatus(){ if ((WDreg & 0x01) != 0) /* Checks the status of WDreg */ return "Timer enabled"; /* C-SPY macro string used */ else return "Timer disabled"; /* C-SPY macro string used */}

2 Save the macro function using the filename extension mac.

3 To register the macro file, choose Debug>Macros. The Macro Configuration dialog box appears.

4 Locate the file, click Add and then Register. The macro function appears in the list of registered macros.

5 Choose View>Quick Watch to open the Quick Watch window, type the macro call WDTstatus() in the text field and press Return,

Alternatively, in the macro file editor window, select the macro function name WDTstatus(). Right-click, and choose Quick Watch from the context menu that appears.

Figure 119: Quick Watch window

The macro will automatically be displayed in the Quick Watch window.

For more information, see Quick Watch window, page 99.

UCSRX-3

239

Page 240: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

240

Procedures for using C-SPY macros

EXECUTING A MACRO BY CONNECTING IT TO A BREAKPOINT

You can connect a macro to a breakpoint. The macro will then be executed when the breakpoint is triggered. The advantage is that you can stop the execution at locations of particular interest and perform specific actions there.

For instance, you can easily produce log reports containing information such as how the values of variables, symbols, or registers change. To do this you might set a breakpoint on a suspicious location and connect a log macro to the breakpoint. After the execution you can study how the values of the registers have changed.

To create a log macro and connect it to a breakpoint:

1 Assume this skeleton of a C function in your application source code:

int fact(int x){ ...}

2 Create a simple log macro function like this example:

logfact(){ __message "fact(" ,x, ")";}

The __message statement will log messages to the Log window.

Save the macro function in a macro file, with the filename extension mac.

3 To register the macro, choose Debug>Macros to open the Macro Configuration dialog box and add your macro file to the list Selected Macro Files. Click Register and your macro function will appear in the list Registered Macros. Close the dialog box.

4 To set a code breakpoint, click the Toggle Breakpoint button on the first statement within the function fact in your application source code. Choose View>Breakpoints to open the Breakpoints window. Select your breakpoint in the list of breakpoints and choose the Edit command from the context menu.

5 To connect the log macro function to the breakpoint, type the name of the macro function, logfact(), in the Action field and click Apply. Close the dialog box.

6 Execute your application source code. When the breakpoint is triggered, the macro function will be executed. You can see the result in the Log window.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 241: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Note that the expression in the Action field is evaluated only when the breakpoint causes the execution to really stop. If you want to log a value and then automatically continue execution, you can either:

● Use a Log breakpoint, see Log breakpoints dialog box, page 121

● Use the Condition field instead of the Action field. For an example, see Performing a task and continuing execution, page 112.

7 You can easily enhance the log macro function by, for instance, using the __fmessage statement instead, which will print the log information to a file. For information about the __fmessage statement, see Formatted output, page 244.

For an example where a serial port input buffer is simulated using the method of connecting a macro to a breakpoint, see the tutorial Simulating an interrupt in the Information Center.

Reference information on the macro languageThis section gives reference information on the macro language:

● Macro functions, page 241

● Macro variables, page 242

● Macro strings, page 242

● Macro statements, page 243

● Formatted output, page 244.

MACRO FUNCTIONS

C-SPY macro functions consist of C-SPY variable definitions and macro statements which are executed when the macro is called. An unlimited number of parameters can be passed to a macro function, and macro functions can return a value on exit.

A C-SPY macro has this form:

macroName (parameterList){ macroBody}

where parameterList is a list of macro parameters separated by commas, and macroBody is any series of C-SPY variable definitions and C-SPY statements.

Type checking is neither performed on the values passed to the macro functions nor on the return value.

UCSRX-3

241

Page 242: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

242

Reference information on the macro language

MACRO VARIABLES

A macro variable is a variable defined and allocated outside your application. It can then be used in a C-SPY expression, or you can assign application data—values of the variables in your application—to it. For more information about C-SPY expressions, see C-SPY expressions, page 88.

The syntax for defining one or more macro variables is:

__var nameList;

where nameList is a list of C-SPY variable names separated by commas.

A macro variable defined outside a macro body has global scope, and it exists throughout the whole debugging session. A macro variable defined within a macro body is created when its definition is executed and destroyed on return from the macro.

By default, macro variables are treated as signed integers and initialized to 0. When a C-SPY variable is assigned a value in an expression, it also acquires the type of that expression. For example:

In case of a name conflict between a C symbol and a C-SPY macro variable, C-SPY macro variables have a higher precedence than C variables. Note that macro variables are allocated on the debugger host and do not affect your application.

MACRO STRINGS

In addition to C types, macro variables can hold values of macro strings. Note that macro strings differ from C language strings.

When you write a string literal, such as "Hello!", in a C-SPY expression, the value is a macro string. It is not a C-style character pointer char*, because char* must point to a sequence of characters in target memory and C-SPY cannot expect any string literal to actually exist in target memory.

You can manipulate a macro string using a few built-in macro functions, for example __strFind or __subString. The result can be a new macro string. You can concatenate macro strings using the + operator, for example str + "tail". You can also access individual characters using subscription, for example str[3]. You can get the length of a string using sizeof(str). Note that a macro string is not NULL-terminated.

Expression What it means

myvar = 3.5; myvar is now type float, value 3.5.

myvar = (int*)i; myvar is now type pointer to int, and the value is the same as i.

Table 18: Examples of C-SPY macro variables

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 243: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

The macro function __toString is used for converting from a NULL-terminated C string in your application (char* or char[]) to a macro string. For example, assume this definition of a C string in your application:

char const *cstr = "Hello";

Then examine these macro examples:

__var str; /* A macro variable */str = cstr /* str is now just a pointer to char */sizeof str /* same as sizeof (char*), typically 2 or 4 */str = __toString(cstr,512) /* str is now a macro string */sizeof str /* 5, the length of the string */str[1] /* 101, the ASCII code for 'e' */str += " World!" /* str is now "Hello World!" */

See also Formatted output, page 244.

MACRO STATEMENTS

Statements are expected to behave in the same way as the corresponding C statements would do. The following C-SPY macro statements are accepted:

Expressions

expression;

For more information about C-SPY expressions, see C-SPY expressions, page 88.

Conditional statements

if (expression) statement

if (expression) statementelse statement

Loop statements

for (init_expression; cond_expression; update_expression) statement

while (expression) statement

UCSRX-3

243

Page 244: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

244

Reference information on the macro language

do statementwhile (expression);

Return statements

return;

return expression;

If the return value is not explicitly set, signed int 0 is returned by default.

Blocks

Statements can be grouped in blocks.

{ statement1 statement2 . . . statementN}

FORMATTED OUTPUT

C-SPY provides various methods for producing formatted output:

where argList is a comma-separated list of C-SPY expressions or strings, and file is the result of the __openFile system macro, see __openFile, page 255.

To produce messages in the Debug Log window:var1 = 42;var2 = 37;__message "This line prints the values ", var1, " and ", var2, " in the Log window.";

This produces this message in the Log window:

This line prints the values 42 and 37 in the Log window.

__message argList; Prints the output to the Debug Log window.

__fmessage file, argList; Prints the output to the designated file.

__smessage argList; Returns a string containing the formatted output.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 245: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

To write the output to a designated file:__fmessage myfile, "Result is ", res, "!\n";

To produce strings:myMacroVar = __smessage 42, " is the answer.";

myMacroVar now contains the string "42 is the answer.".

Specifying display format of arguments

To override the default display format of a scalar argument (number or pointer) in argList, suffix it with a : followed by a format specifier. Available specifiers are:

These match the formats available in the Watch and Locals windows, but number prefixes and quotes around strings and characters are not printed. Another example:

__message "The character '", cvar:%c, "' has the decimal value ", cvar;

Depending on the value of the variables, this produces this message:

The character 'A' has the decimal value 65

Note: A character enclosed in single quotes (a character literal) is an integer constant and is not automatically formatted as a character. For example:

__message 'A', " is the numeric value of the character ", 'A':%c;

would produce:

65 is the numeric value of the character A

Note: The default format for certain types is primarily designed to be useful in the Watch window and other related windows. For example, a value of type char is formatted as 'A' (0x41), while a pointer to a character (potentially a C string) is formatted as 0x8102 "Hello", where the string part shows the beginning of the string (currently up to 60 characters).

%b for binary scalar arguments

%o for octal scalar arguments

%d for decimal scalar arguments

%x for hexadecimal scalar arguments

%c for character scalar arguments

UCSRX-3

245

Page 246: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

246

Reference information on reserved setup macro function names

When printing a value of type char*, use the %x format specifier to print just the pointer value in hexadecimal notation, or use the system macro __toString to get the full string value.

Reference information on reserved setup macro function namesThere are reserved setup macro function names that you can use for defining your setup macro functions. By using these reserved names, your function will be executed at defined stages during execution. For more information, see Briefly about setup macro functions and files, page 234.

This table summarizes the reserved setup macro function names:

If you define interrupts or breakpoints in a macro file that is executed at system start (using execUserSetup) we strongly recommend that you also make sure that they are removed at system shutdown (using execUserExit). An example is available in SetupSimple.mac, see Simulating an interrupt in the Information Center.

The reason for this is that the simulator saves interrupt settings between sessions and if they are not removed they will get duplicated every time execUserSetup is executed again. This seriously affects the execution speed.

Macro Description

execUserPreload Called after communication with the target system is established but before downloading the target application. Implement this macro to initialize memory locations and/or registers which are vital for loading data properly.

execUserSetup Called once after the target application is downloaded.Implement this macro to set up the memory map, breakpoints, interrupts, register macro files, etc.

execUserPreReset Called each time just before the reset command is issued.Implement this macro to set up any required device state.

execUserReset Called each time just after the reset command is issued.Implement this macro to set up and restore data.

execUserExit Called once when the debug session ends. Implement this macro to save status data etc.

Table 19: C-SPY setup macros

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 247: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Reference information on C-SPY system macrosThis section gives reference information about each of the C-SPY system macros.

This table summarizes the pre-defined system macros:

Macro Description

__cancelAllInterrupts Cancels all ordered interrupts

__cancelInterrupt Cancels an interrupt

__clearBreak Clears a breakpoint

__closeFile Closes a file that was opened by __openFile

__delay Delays execution

__disableInterrupts Disables generation of interrupts

__driverType Verifies the driver type

__enableInterrupts Enables generation of interrupts

__evaluate Interprets the input string as an expression and evaluates it.

__isBatchMode Checks if C-SPY is running in batch mode or not.

__loadImage Loads an image.

__memoryRestore Restores the contents of a file to a specified memory zone

__memorySave Saves the contents of a specified memory area to a file

__openFile Opens a file for I/O operations

__orderInterrupt Generates an interrupt

__popSimulatorInterruptExec

utingStack

Informs the interrupt simulation system that an interrupt handler has finished executing

__readFile Reads from the specified file

__readFileByte Reads one byte from the specified file

__readMemory8,

__readMemoryByte

Reads one byte from the specified memory location

__readMemory16 Reads two bytes from the specified memory location

__readMemory32 Reads four bytes from the specified memory location

__registerMacroFile Registers macros from the specified file

__resetFile Rewinds a file opened by __openFile

Table 20: Summary of system macros

UCSRX-3

247

Page 248: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

248

Reference information on C-SPY system macros

__setCodeBreak Sets a code breakpoint

__setDataBreak Sets a data breakpoint

__setLogBreak Sets a log breakpoint

__setSimBreak Sets a simulation breakpoint

__setTraceStartBreak Sets a trace start breakpoint

__setTraceStopBreak Sets a trace stop breakpoint

__sourcePosition Returns the file name and source location if the current execution location corresponds to a source location

__strFind Searches a given string for the occurrence of another string

__subString Extracts a substring from another string

__targetDebuggerVersion Returns the version of the target debugger

__toLower Returns a copy of the parameter string where all the characters have been converted to lower case

__toString Prints strings

__toUpper Returns a copy of the parameter string where all the characters have been converted to upper case

__unloadImage Unloads a debug image.

__writeFile Writes to the specified file

__writeFileByte Writes one byte to the specified file

__writeMemory8,

__writeMemoryByte

Writes one byte to the specified memory location

__writeMemory16 Writes a two-byte word to the specified memory location

__writeMemory32 Writes a four-byte word to the specified memory location

Macro Description

Table 20: Summary of system macros (Continued)

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 249: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

__cancelAllInterrupts

Syntax __cancelAllInterrupts()

Return value int 0

Description Cancels all ordered interrupts.

Applicability This system macro is only available in the C-SPY Simulator.

__cancelInterrupt

Syntax __cancelInterrupt(interrupt_id)

Parameter

Return value

Description Cancels the specified interrupt.

Applicability This system macro is only available in the C-SPY Simulator.

__clearBreak

Syntax __clearBreak(break_id)

Parameter

Return value int 0

Description Clears a user-defined breakpoint.

See also Using breakpoints, page 103.

interrupt_id The value returned by the corresponding __orderInterrupt macro call (unsigned long)

Result Value

Successful int 0

Unsuccessful Non-zero error number

Table 21: __cancelInterrupt return values

break_id The value returned by any of the set breakpoint macros

UCSRX-3

249

Page 250: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

250

Reference information on C-SPY system macros

__closeFile

Syntax __closeFile(fileHandle)

Parameter

Return value int 0

Description Closes a file previously opened by __openFile.

__delay

Syntax __delay(value)

Parameter

Return value int 0

Description Delays execution the specified number of milliseconds.

__disableInterrupts

Syntax __disableInterrupts()

Return value

Description Disables the generation of interrupts.

Applicability This system macro is only available in the C-SPY Simulator.

fileHandle The macro variable used as filehandle by the __openFile macro

value The number of milliseconds to delay execution

Result Value

Successful int 0

Unsuccessful Non-zero error number

Table 22: __disableInterrupts return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 251: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

__driverType

Syntax __driverType(driver_id)

Parameter

Return value

Description Checks to see if the current C-SPY driver is identical to the driver type of the driver_id parameter.

Example __driverType("sim")

If the simulator is the current driver, the value 1 is returned. Otherwise 0 is returned.

__enableInterrupts

Syntax __enableInterrupts()

Return value

Description Enables the generation of interrupts.

Applicability This system macro is only available in the C-SPY Simulator.

driver_id A string corresponding to the driver you want to check for. Choose one of these:

"sim" corresponds to the simulator driver."emue20" corresponds to the E1/E20 driver."jlink" corresponds to the J-Link driver.

Result Value

Successful 1

Unsuccessful 0

Table 23: __driverType return values

Result Value

Successful int 0

Unsuccessful Non-zero error number

Table 24: __enableInterrupts return values

UCSRX-3

251

Page 252: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

252

Reference information on C-SPY system macros

__evaluate

Syntax __evaluate(string, valuePtr)

Parameter

Return value

Description This macro interprets the input string as an expression and evaluates it. The result is stored in a variable pointed to by valuePtr.

Example This example assumes that the variable i is defined and has the value 5:

__evaluate("i + 3", &myVar)

The macro variable myVar is assigned the value 8.

__isBatchMode

Syntax __isBatchMode()

Return value

Description This macro returns True if the debugger is running in batch mode, otherwise it returns False.

string Expression string

valuePtr Pointer to a macro variable storing the result

Result Value

Successful int 0

Unsuccessful int 1

Table 25: __evaluate return values

Result Value

True int 1

False int 0

Table 26: __isBatchMode return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 253: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

__loadImage

Syntax __loadImage(path, offset, debugInfoOnly)

Parameter

Return value

Description Loads an image (debug file).

Example 1 Your system consists of a ROM library and an application. The application is your active project, but you have a debug file corresponding to the library. In this case you can add this macro call in the execUserSetup macro in a C-SPY macro file, which you associate with your project:

__loadImage(ROMfile, 0x8000, 1);

This macro call loads the debug information for the ROM library ROMfile without downloading its contents (because it is presumably already in ROM). Then you can debug your application together with the library.

Example 2 Your system consists of a ROM library and an application, but your main concern is the library. The library needs to be programmed into flash memory before a debug session. While you are developing the library, the library project must be the active project in the IDE. In this case you can add this macro call in the execUserSetup macro in a C-SPY macro file, which you associate with your project:

__loadImage(ApplicationFile, 0x8000, 0);

path A string that identifies the path to the image to download. The path must either be absolute or use argument variables. For information about argument variables, see the IDE Project Management and Building Guide.

offset An integer that identifies the offset to the destination address for the downloaded image.

debugInfoOnly A non-zero integer value if no code or data should be downloaded to the target system, which means that C-SPY will only read the debug information from the debug file. Or, 0 (zero) for download.

Value Result

Non-zero integer number A unique module identification.

int 0 Loading failed.

Table 27: __loadImage return values

UCSRX-3

253

Page 254: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

254

Reference information on C-SPY system macros

The macro call loads the debug information for the application and downloads its contents (presumably into RAM). Then you can debug your library together with the application.

See also Images, page 294 and Loading multiple images, page 43.

__memoryRestore

Syntax __memoryRestore(zone, filename)

Parameters

Return value int 0

Description Reads the contents of a file and saves it to the specified memory zone.

Example __memoryRestore("Memory", "c:\\temp\\saved_memory.hex");

See also Memory Restore dialog box, page 141.

__memorySave

Syntax __memorySave(start, stop, format, filename)

Parameters

zone The memory zone name (string); for a list of available zones, see C-SPY memory zones, page 133.

filename A string that specifies the file to be read. The filename must include a path, which must either be absolute or use argument variables. For information about argument variables, see the IDE Project Management and Building Guide.

start A string that specifies the first location of the memory area to be saved

stop A string that specifies the last location of the memory area to be saved

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 255: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Return value int 0

Description Saves the contents of a specified memory area to a file.

Example __memorySave("Memory:0x00", "Memory:0xFF", "intel-extended", "c:\\temp\\saved_memory.hex");

See also Memory Save dialog box, page 140.

__openFile

Syntax __openFile(filename, access)

Parameters

format A string that specifies the format to be used for the saved memory. Choose between:

intel-extendedmotorolamotorola-s19motorola-s28

motorola-s37.

filename A string that specifies the file to write to. The filename must include a path, which must either be absolute or use argument variables. For information about argument variables, see the IDE Project Management and Building Guide.

filename The file to be opened. The filename must include a path, which must either be absolute or use argument variables. For information about argument variables, see the IDE Project Management and Building Guide.

UCSRX-3

255

Page 256: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

256

Reference information on C-SPY system macros

Return value

Description Opens a file for I/O operations. The default base directory of this macro is where the currently open project file (*.ewp) is located. The argument to __openFile can specify a location relative to this directory. In addition, you can use argument variables such as $PROJ_DIR$ and $TOOLKIT_DIR$ in the path argument.

Example __var myFileHandle; /* The macro variable to contain */ /* the file handle */myFileHandle = __openFile("$PROJ_DIR$\\Debug\\Exe\\test.tst", "r");if (myFileHandle){ /* successful opening */}

See also For information about argument variables, see the IDE Project Management and Building Guide.

access The access type (string).

These are mandatory but mutually exclusive:

"a" append, new data will be appended at the end of the open file"r" read"w" write

These are optional and mutually exclusive:

"b" binary, opens the file in binary mode"t" ASCII text, opens the file in text mode

This access type is optional:

"+" together with r, w, or a; r+ or w+ is read and write, while a+ is read and append

Result Value

Successful The file handle

Unsuccessful An invalid file handle, which tests as False

Table 28: __openFile return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 257: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

__orderInterrupt

Syntax __orderInterrupt(specification, first_activation, repeat_interval, variance, infinite_hold_time, hold_time, probability)

Parameters

Return value The macro returns an interrupt identifier (unsigned long).

If the syntax of specification is incorrect, it returns -1.

Description Generates an interrupt.

Applicability This system macro is only available in the C-SPY Simulator.

Example This example generates a repeating interrupt using an infinite hold time first activated after 4000 cycles:

__orderInterrupt( "SCI0_RXI0", 4000, 2000, 0, 1, 0, 100 );

__popSimulatorInterruptExecutingStack

Syntax __popSimulatorInterruptExecutingStack(void)

Return value This macro has no return value.

specification The interrupt (string). The specification can either be the full specification used in the device description file (ddf) or only the name. In the latter case the interrupt system will automatically get the description from the device description file.

first_activation The first activation time in cycles (integer)

repeat_interval The periodicity in cycles (integer)

variance The timing variation range in percent (integer between 0 and 100)

infinite_hold_time 1 if infinite, otherwise 0.

hold_time The hold time (integer)

probability The probability in percent (integer between 0 and 100)

UCSRX-3

257

Page 258: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

258

Reference information on C-SPY system macros

Description Informs the interrupt simulation system that an interrupt handler has finished executing, as if the normal instruction used for returning from an interrupt handler was executed.

This is useful if you are using interrupts in such a way that the normal instruction for returning from an interrupt handler is not used, for example in an operating system with task-switching. In this case, the interrupt simulation system cannot automatically detect that the interrupt has finished executing.

Applicability This system macro is only available in the C-SPY Simulator.

See also Simulating an interrupt in a multi-task system, page 222.

__readFile

Syntax __readFile(fileHandle, valuePtr)

Parameters

Return value

Description Reads a sequence of hexadecimal digits from the given file and converts them to an unsigned long which is assigned to the value parameter, which should be a pointer to a macro variable.

Example __var number;if (__readFile(myFileHandle, &number) == 0){ // Do something with number}

fileHandle A macro variable used as filehandle by the __openFile macro

valuePtr A pointer to a variable

Result Value

Successful 0

Unsuccessful Non-zero error number

Table 29: __readFile return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 259: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

__readFileByte

Syntax __readFileByte(fileHandle)

Parameter

Return value -1 upon error or end-of-file, otherwise a value between 0 and 255.

Description Reads one byte from a file.

Example __var byte;while ( (byte = __readFileByte(myFileHandle)) != -1 ){ /* Do something with byte */}

__readMemory8, __readMemoryByte

Syntax __readMemory8(address, zone)__readMemoryByte(address, zone)

Parameters

Return value The macro returns the value from memory.

Description Reads one byte from a given memory location.

Example __readMemory8(0x0108, "Memory");

__readMemory16

Syntax __readMemory16(address, zone)

Parameters

fileHandle A macro variable used as filehandle by the __openFile macro

address The memory address (integer)

zone The memory zone name (string); for more information about available zones, see C-SPY memory zones, page 133.

address The memory address (integer)

UCSRX-3

259

Page 260: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

260

Reference information on C-SPY system macros

Return value The macro returns the value from memory.

Description Reads a two-byte word from a given memory location.

Example __readMemory16(0x0108, "Memory");

__readMemory32

Syntax __readMemory32(address, zone)

Parameters

Return value The macro returns the value from memory.

Description Reads a four-byte word from a given memory location.

Example __readMemory32(0x0108, "Memory");

__registerMacroFile

Syntax __registerMacroFile(filename)

Parameter

Return value int 0

Description Registers macros from a setup macro file. With this function you can register multiple macro files during C-SPY startup.

zone The memory zone name (string); for more information about available zones, see C-SPY memory zones, page 133.

address The memory address (integer)

zone The memory zone name (string); for more information about available zones, see C-SPY memory zones, page 133.

filename A file containing the macros to be registered (string). The filename must include a path, which must either be absolute or use argument variables. For information about argument variables, see the IDE Project Management and Building Guide.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 261: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Example __registerMacroFile("c:\\testdir\\macro.mac");

See also Registering and executing using setup macros and setup files, page 238.

__resetFile

Syntax __resetFile(fileHandle)

Parameter

Return value int 0

Description Rewinds a file previously opened by __openFile.

__setCodeBreak

Syntax __setCodeBreak(location, count, condition, cond_type, action)

Parameters

fileHandle A macro variable used as filehandle by the __openFile macro

location A string with a location description. Choose between:

A C-SPY expression, whose value evaluates to a valid address, such as a function, for example main. For more information about C-SPY expressions, see C-SPY expressions, page 88.

An absolute address, on the form zone:hexaddress or simply hexaddress (for example Memory:42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

A source location in your C source code, using the syntax {filename}.row.col. For example{D:\\src\\prog.c}.22.3 sets a breakpoint on the third character position on row 22 in the source file prog.c. Note that the Source location type is usually meaningful only for code breakpoints.

count The number of times that a breakpoint condition must be fulfilled before a break occurs (integer)

condition The breakpoint condition (string)

UCSRX-3

261

Page 262: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

262

Reference information on C-SPY system macros

Return value

Description Sets a code breakpoint, that is, a breakpoint which is triggered just before the processor fetches an instruction at the specified location.

Examples __setCodeBreak("{D:\\src\\prog.c}.12.9", 3, "d>16", "TRUE", "ActionCode()");

This example sets a code breakpoint on the label main in your source:

__setCodeBreak("main", 0, "1", "TRUE", "");

See also Using breakpoints, page 103.

cond_type The condition type; either "CHANGED" or "TRUE" (string)

action An expression, typically a call to a macro, which is evaluated when the breakpoint is detected

Result Value

Successful An unsigned integer uniquely identifying the breakpoint. This value must be used to clear the breakpoint.

Unsuccessful 0

Table 30: __setCodeBreak return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 263: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

__setDataBreak

Syntax __setDataBreak(location, count, condition, cond_type, access, action)

Parameterslocation A string with a location description. Choose between:

A C-SPY expression, whose value evaluates to a valid address, such as a variable name. For example, my_var refers to the location of the variable my_var, and arr[3] refers to the location of the third element of the array arr. For static variables declared with the same name in several functions, use the syntax my_func::my_static_variable to refer to a specific variable. For more information about C-SPY expressions, see C-SPY expressions, page 88.

An absolute address, on the form zone:hexaddress or simply hexaddress (for example Memory:42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

A source location in your C source code, using the syntax {filename}.row.col. For example{D:\\src\\prog.c}.22.3 sets a breakpoint on the third character position on row 22 in the source file prog.c. Note that the Source location type is usually meaningful only for code breakpoints.

count The number of times that a breakpoint condition must be fulfilled before a break occurs (integer)

condition The breakpoint condition (string)

cond_type The condition type; either "CHANGED" or "TRUE" (string)

access The memory access type: "R" for read, "W" for write, or "RW" for read/write

action An expression, typically a call to a macro, which is evaluated when the breakpoint is detected

UCSRX-3

263

Page 264: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

264

Reference information on C-SPY system macros

Return value

Description Sets a data breakpoint, that is, a breakpoint which is triggered directly after the processor has read or written data at the specified location.

Applicability This system macro is only available in the C-SPY Simulator.

Example __var brk;brk = __setDataBreak("0x100", 3, "d>6", "TRUE", "W", "ActionData()");...__clearBreak(brk);

See also Using breakpoints, page 103.

__setLogBreak

Syntax __setLogBreak(location, message, msg_type, condition, cond_type)

Parameters

Result Value

Successful An unsigned integer uniquely identifying the breakpoint. This value must be used to clear the breakpoint.

Unsuccessful 0

Table 31: __setDataBreak return values

location A string with a location description. Choose between:

A C-SPY expression, whose value evaluates to a valid address, such as a function, for example main. For more information about C-SPY expressions, see C-SPY expressions, page 88.

An absolute address, on the form zone:hexaddress or simply hexaddress (for example Memory:42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

A source location in your C source code, using the syntax {filename}.row.col. For example{D:\\src\\prog.c}.22.3 sets a breakpoint on the third character position on row 22 in the source file prog.c. Note that the Source location type is usually meaningful only for code breakpoints.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 265: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Return value

Description Sets a log breakpoint, that is, a breakpoint which is triggered when an instruction is fetched from the specified location. If you have set the breakpoint on a specific machine instruction, the breakpoint will be triggered and the execution will temporarily halt and print the specified message in the C-SPY Debug Log window.

Example __var logBp1;__var logBp2;

logOn(){ logBp1 = __setLogBreak ("{C:\\temp\\Utilities.c}.23.1", "\"Entering trace zone at :\", #PC:%X", "ARGS", "1", "TRUE"); logBp2 = __setLogBreak ("{C:\\temp\\Utilities.c}.30.1", "Leaving trace zone...", "TEXT", "1", "TRUE");}

logOff(){ __clearBreak(logBp1); __clearBreak(logBp2);}

See also Formatted output, page 244 and Using breakpoints, page 103.

message The message text

msg_type The message type; choose between:

TEXT, the message is written word for word.ARGS, the message is interpreted as a comma-separated list

of C-SPY expressions or strings.

condition The breakpoint condition (string)

cond_type The condition type; either "CHANGED" or "TRUE" (string)

Result Value

Successful An unsigned integer uniquely identifying the breakpoint. The same value must be used when you want to clear the breakpoint.

Unsuccessful 0

Table 32: __setLogBreak return values

UCSRX-3

265

Page 266: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

266

Reference information on C-SPY system macros

__setSimBreak

Syntax __setSimBreak(location, access, action)

Parameters

Return value

Description Use this system macro to set immediate breakpoints, which will halt instruction execution only temporarily. This allows a C-SPY macro function to be called when the processor is about to read data from a location or immediately after it has written data. Instruction execution will resume after the action.

location A string with a location description. Choose between:

A C-SPY expression, whose value evaluates to a valid address, such as a variable name. For example, my_var refers to the location of the variable my_var, and arr[3] refers to the location of the third element of the array arr. For static variables declared with the same name in several functions, use the syntax my_func::my_static_variable to refer to a specific variable. For more information about C-SPY expressions, see C-SPY expressions, page 88.

An absolute address, on the form zone:hexaddress or simply hexaddress (for example Memory:42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

A source location in your C source code, using the syntax {filename}.row.col. For example{D:\\src\\prog.c}.22.3 sets a breakpoint on the third character position on row 22 in the source file prog.c. Note that the Source location type is usually meaningful only for code breakpoints.

access The memory access type: "R" for read or "W" for write

action An expression, typically a call to a macro function, which is evaluated when the breakpoint is detected

Result Value

Successful An unsigned integer uniquely identifying the breakpoint. This value must be used to clear the breakpoint.

Unsuccessful 0

Table 33: __setSimBreak return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 267: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

This type of breakpoint is useful for simulating memory-mapped devices of various kinds (for instance serial ports and timers). When the processor reads at a memory-mapped location, a C-SPY macro function can intervene and supply the appropriate data. Conversely, when the processor writes to a memory-mapped location, a C-SPY macro function can act on the value that was written.

Applicability This system macro is only available in the C-SPY Simulator.

__setTraceStartBreak

Syntax __setTraceStartBreak(location)

Parameters

Return value

Description Sets a breakpoint at the specified location. When that breakpoint is triggered, the trace system is started.

Example __var startTraceBp;__var stopTraceBp;

location A string with a location description. Choose between:

A C-SPY expression, whose value evaluates to a valid address, such as a function, for example main. For more information about C-SPY expressions, see C-SPY expressions, page 88.

An absolute address, on the form zone:hexaddress or simply hexaddress (for example Memory:42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

A source location in your C source code, using the syntax {filename}.row.col. For example{D:\\src\\prog.c}.22.3 sets a breakpoint on the third character position on row 22 in the source file prog.c. Note that the Source location type is usually meaningful only for code breakpoints.

Result Value

Successful An unsigned integer uniquely identifying the breakpoint. The same value must be used when you want to clear the breakpoint.

Unsuccessful 0

Table 34: __setTraceStartBreak return values

UCSRX-3

267

Page 268: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

268

Reference information on C-SPY system macros

traceOn(){ startTraceBp = __setTraceStartBreak ("{C:\\TEMP\\Utilities.c}.23.1"); stopTraceBp = __setTraceStopBreak ("{C:\\temp\\Utilities.c}.30.1");}

traceOff(){ __clearBreak(startTraceBp); __clearBreak(stopTraceBp);}

See also Using breakpoints, page 103.

__setTraceStopBreak

Syntax __setTraceStopBreak(location)

Parameterslocation A string with a location description. Choose between:

A C-SPY expression, whose value evaluates to a valid address, such as a function, for example main. For more information about C-SPY expressions, see C-SPY expressions, page 88.

An absolute address, on the form zone:hexaddress or simply hexaddress (for example Memory:42). zone refers to C-SPY memory zones and specifies in which memory the address belongs.

A source location in your C source code, using the syntax {filename}.row.col. For example{D:\\src\\prog.c}.22.3 sets a breakpoint on the third character position on row 22 in the source file prog.c. Note that the Source location type is usually meaningful only for code breakpoints.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 269: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Return value

Description Sets a breakpoint at the specified location. When that breakpoint is triggered, the trace system is stopped.

Example See __setTraceStartBreak, page 267.

See also Using breakpoints, page 103.

__sourcePosition

Syntax __sourcePosition(linePtr, colPtr)

Parameters

Return value

Description If the current execution location corresponds to a source location, this macro returns the filename as a string. It also sets the value of the variables, pointed to by the parameters, to the line and column numbers of the source location.

__strFind

Syntax __strFind(macroString, pattern, position)

Parameters

Result Value

Successful An unsigned integer uniquely identifying the breakpoint. The same value must be used when you want to clear the breakpoint.

Unsuccessful int 0

Table 35: __setTraceStopBreak return values

linePtr Pointer to the variable storing the line number

colPtr Pointer to the variable storing the column number

Result Value

Successful Filename string

Unsuccessful Empty ("") string

Table 36: __sourcePosition return values

macroString The macro string to search in

pattern The string pattern to search for

UCSRX-3

269

Page 270: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

270

Reference information on C-SPY system macros

Return value The position where the pattern was found or -1 if the string is not found.

Description This macro searches a given string for the occurrence of another string.

Example __strFind("Compiler", "pile", 0) = 3__strFind("Compiler", "foo", 0) = -1

See also Macro strings, page 242.

__subString

Syntax __subString(macroString, position, length)

Parameters

Return value A substring extracted from the given macro string.

Description This macro extracts a substring from another string.

Example __subString("Compiler", 0, 2)

The resulting macro string contains Co.

__subString("Compiler", 3, 4)

The resulting macro string contains pile.

See also Macro strings, page 242.

__targetDebuggerVersion

Syntax __targetDebuggerVersion

Return value A string that represents the version number of the C-SPY debugger processor module.

position The position where to start the search. The first position is 0

macroString The macro string from which to extract a substring

position The start position of the substring. The first position is 0.

length The length of the substring

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 271: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Description This macro returns the version number of the C-SPY debugger processor module.

Example __var toolVer;toolVer = __targetDebuggerVersion();__message "The target debugger version is, ", toolVer;

__toLower

Syntax __toLower(macroString)

Parameter

Return value The converted macro string.

Description This macro returns a copy of the parameter string where all the characters have been converted to lower case.

Example __toLower("IAR")

The resulting macro string contains iar.

__toLower("Mix42")

The resulting macro string contains mix42.

See also Macro strings, page 242.

__toString

Syntax __toString(C_string, maxlength)

Parameter

Return value Macro string.

Description This macro is used for converting C strings (char* or char[]) into macro strings.

Example Assuming your application contains this definition:

char const * hptr = "Hello World!";

macroString Any macro string

C_string Any null-terminated C string

maxlength The maximum length of the returned macro string

UCSRX-3

271

Page 272: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

272

Reference information on C-SPY system macros

this macro call:

__toString(hptr, 5)

would return the macro string containing Hello.

See also Macro strings, page 242.

__toUpper

Syntax __toUpper(macroString)

Parameter macroString is any macro string.

Return value The converted string.

Description This macro returns a copy of the parameter macroString where all the characters have been converted to upper case.

Example __toUpper("string")

The resulting macro string contains STRING.

See also Macro strings, page 242.

__unloadImage

Syntax __unloadImage(module_id)

Parameter

Return value

Description Unloads debug information from an already downloaded image.

module_id An integer which represents a unique module identification, which is retrieved as a return value from the corresponding __loadImage C-SPY macro.

Value Result

module_id A unique module identification (the same as the input parameter).

int 0 The unloading failed.

Table 37: __unloadImage return values

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 273: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

See also Loading multiple images, page 43 and Images, page 294.

__writeFile

Syntax __writeFile(fileHandle, value)

Parameters

Return value int 0

Description Prints the integer value in hexadecimal format (with a trailing space) to the file file.

Note: The __fmessage statement can do the same thing. The __writeFile macro is provided for symmetry with __readFile.

__writeFileByte

Syntax __writeFileByte(fileHandle, value)

Parameters

Return value int 0

Description Writes one byte to the file fileHandle.

__writeMemory8, __writeMemoryByte

Syntax __writeMemory8(value, address, zone)__writeMemoryByte(value, address, zone)

Parameters

fileHandle A macro variable used as filehandle by the __openFile macro

value An integer

fileHandle A macro variable used as filehandle by the __openFile macro

value An integer in the range 0-255

value The value to be written (integer)

address The memory address (integer)

UCSRX-3

273

Page 274: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

274

Reference information on C-SPY system macros

Return value int 0

Description Writes one byte to a given memory location.

Example __writeMemory8(0x2F, 0x8020, "Memory");

__writeMemory16

Syntax __writeMemory16(value, address, zone)

Parameters

Return value int 0

Description Writes two bytes to a given memory location.

Example __writeMemory16(0x2FFF, 0x8020, "Memory");

__writeMemory32

Syntax __writeMemory32(value, address, zone)

Parameters

Return value int 0

Description Writes four bytes to a given memory location.

zone The memory zone name (string); for more information about available zones, see C-SPY memory zones, page 133.

value The value to be written (integer)

address The memory address (integer)

zone The memory zone name (string); for more information about available zones, see C-SPY memory zones, page 133.

value The value to be written (integer)

address The memory address (integer)

zone The memory zone name (string); for more information about available zones, see C-SPY memory zones, page 133.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 275: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Using C-SPY macros

Example __writeMemory32(0x5555FFFF, 0x8020, "Memory");

UCSRX-3

275

Page 276: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

276

Reference information on C-SPY system macros

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 277: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybatThis chapter describes how you can execute C-SPY® in batch mode, using the C-SPY Command Line Utility—cspybat.exe. More specifically, this means:

● Using C-SPY in batch mode

● Summary of C-SPY command line options

● Reference information on C-SPY command line options.

Using C-SPY in batch modeYou can execute C-SPY in batch mode if you use the command line utility cspybat, installed in the directory common\bin.

INVOCATION SYNTAX

The invocation syntax for cspybat is:

cspybat processor_DLL driver_DLL debug_file [cspybat_options] --backend driver_options

Note: In those cases where a filename is required—including the DLL files—you are recommended to give a full path to the filename.

Parameters

The parameters are:

Parameter Description

processor_DLL The processor-specific DLL file; available in rx\bin.

driver_DLL The C-SPY driver DLL file; available in rx\bin.

debug_file The object file that you want to debug (filename extension out).

cspybat_options The command line options that you want to pass to cspybat. Note that these options are optional. For information about each option, see Reference information on C-SPY command line options, page 280.

Table 38: cspybat parameters

UCSRX-3

277

Page 278: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

278

Using C-SPY in batch mode

Example

This example starts cspybat using the simulator driver:

EW_DIR\common\bin\cspybat EW_DIR\rx\bin\rxproc.dll EW_DIR\rx\bin\rxsim.dll PROJ_DIR\myproject.out --plugin EW_DIR\rx\bin\rxbat.dll --backend -B --core RX600 -p EW_DIR\rx\config\debugger\iorx600_generic.ddf --double 32 --endian l --int 32

where EW_DIR is the full path of the directory where you have installed IAR Embedded Workbench and PROJ_DIR is the path of your project directory.

OUTPUT

When you run cspybat, these types of output can be produced:

● Terminal output from cspybat itself

All such terminal output is directed to stderr. Note that if you run cspybat from the command line without any arguments, the cspybat version number and all available options including brief descriptions are directed to stdout and displayed on your screen.

● Terminal output from the application you are debugging

All such terminal output is directed to stdout, provided that you have used the --plugin option. See --plugin, page 287.

● Error return codes

cspybat return status information to the host operating system that can be tested in a batch file. For successful, the value int 0 is returned, and for unsuccessful the value int 1 is returned.

--backend Marks the beginning of the parameters to the C-SPY driver; all options that follow will be sent to the driver. Note that this option is mandatory.

driver_options The command line options that you want to pass to the C-SPY driver. Note that some of these options are mandatory and some are optional. For information about each option, see Reference information on C-SPY command line options, page 280.

Parameter Description

Table 38: cspybat parameters (Continued)

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 279: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybat

USING AN AUTOMATICALLY GENERATED BATCH FILE

When you use C-SPY in the IDE, C-SPY generates a batch file projectname.cspy.bat every time C-SPY is initialized. You can find the file in the directory $PROJ_DIR$\settings. This batch file contains the same settings as in the IDE, and with minimal modifications, you can use it from the command line to start cspybat. The file also contains information about required modifications.

Summary of C-SPY command line optionsGENERAL CSPYBAT OPTIONS

OPTIONS AVAILABLE FOR ALL C-SPY DRIVERS

--backend Marks the beginning of the parameters to be sent to the C-SPY driver (mandatory).

--code_coverage_file Enables the generation of code coverage information and places it in a specified file.

--cycles Specifies the maximum number of cycles to run.

--download_only Downloads a code image without starting a debug session afterwards.

--macro Specifies a macro file to be used.

--plugin Specifies a plugin file to be used.

--silent Omits the sign-on message.

--timeout Limits the maximum allowed execution time.

-B Enables batch mode (mandatory).

--core Specifies the core to be used.

-d Specifies the C-SPY driver to be used.

--double Specifies the size of the type double.

--endian Specifies the byte order for data.

--int Specifies the size of the type int.

-p Specifies the device description file to be used.

UCSRX-3

279

Page 280: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

280

Reference information on C-SPY command line options

OPTIONS AVAILABLE FOR THE SIMULATOR DRIVER

OPTIONS AVAILABLE FOR ALL C-SPY HARDWARE DRIVERS

OPTIONS AVAILABLE FOR THE E1/E20 DRIVER

OPTIONS AVAILABLE FOR THE J-LINK DRIVER

Reference information on C-SPY command line optionsThis section gives detailed reference information about each cspybat option and each option available to the C-SPY drivers.

-B

Syntax -B

Applicability All C-SPY drivers.

Description Use this option to enable batch mode.

--disable_interrupts Disables the interrupt simulation.

--mapu Activates memory access checking.

--drv_mode Controls the behavior of the debugger when code is downloaded.

--suppress_download Suppresses download of the executable image.

--verify_download Verifies the executable image.

--drv_communication Identifies which emulator you are using.

--device_select Selects a specific device in the JTAG scan chain.

--ir_length Sets the number of IR bits before the device to be debugged.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 281: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybat

--backend

Syntax --backend {driver options}

Parameters

Applicability Sent to cspybat (mandatory).

Description Use this option to send options to the C-SPY driver. All options that follow --backend will be passed to the C-SPY driver, and will not be processed by cspybat itself.

--core

Syntax --core {RX600|RX610}

Parameters

Applicability All C-SPY drivers.

Description Use this option to specify the core you are using.

--code_coverage_file

Syntax --code_coverage_file file

Parameters

Applicability Sent to cspybat.

Description Use this option to enable the generation of code coverage information. The code coverage information will be generated after the execution has completed and you can find it in the specified file.

driver options Any option available to the C-SPY driver you are using.

RX600|RX610 The core you are using. This option reflects the corresponding compiler option. For a description of the cores, see the IAR C/C++ Development Guide for RX.

file The name of the destination file for the code coverage information.

UCSRX-3

281

Page 282: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

282

Reference information on C-SPY command line options

Note that this option requires that the C-SPY driver you are using supports code coverage. If you try to use this option with a C-SPY driver that does not support code coverage, an error message will be directed to stderr.

See also Code coverage, page 211.

--cycles

Syntax --cycles cycles

Parameters

Applicability Sent to cspybat.

Description Use this option to specify the maximum number of cycles to run. If the target program executes longer than the number of cycles specified, the target program will be aborted. Using this option requires that the C-SPY driver you are using supports a cycle counter, and that it can be sampled while executing.

-d

Syntax -d {emue20|jlink|sim}

Parameters

Applicability All C-SPY drivers.

Description Use this option to specify the C-SPY driver to be used.

To set this option, choose Project>Options>Debugger>Setup>Driver

cycles The number of cycles to run.

emue20 Specifies the E1/E20 driver.

jlink Specifies the J-Link driver.

sim Specifies the simulator driver.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 283: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybat

--device_select

Syntax --device_select=position

Parameters

Applicability The C-SPY J-Link driver.

Description If there is more than one device on the JTAG scan chain, use this option to select a specific device.

See also JTAG Scan Chain, page 300.

Project>Options>J-Link RX>JTAG Scan Chain>Device position

--disable_interrupts

Syntax --disable_interrupts

Applicability The C-SPY Simulator driver.

Description Use this option to disable the interrupt simulation.

To set this option, choose Simulator>Interrupt Setup and deselect the Enable interrupt simulation option.

--double

Syntax --double {32|64}

Parameters

Applicability All C-SPY drivers.

Description Use this option to select the precision used by the compiler for representing the floating-point types double and long double.

position The position of the device you want to connect to.

32 (default) 32-bit doubles are used.

64 64-bit doubles are used.

UCSRX-3

283

Page 284: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

284

Reference information on C-SPY command line options

See also The IAR C/C++ Development Guide for RX for more information about the size of the type double.

--download_only

Syntax --download_only

Applicability Sent to cspybat.

Description Use this option to download the code image without starting a debug session afterwards.

To set related options, choose:

Project>Download

--drv_communication

Syntax --drv_communication {USB:serial_no}

Parameters

Applicability The C-SPY E1/E20 driver.

Description If you have more than one Renesas E1 or E20 emulator connected, use this option to identify which emulator you are using.

Example --drv_communication USB:9IM000019

Project>Options>E1/E20 Emulator>Communication>Serial No

--drv_mode

Syntax --drv_mode {debugging|attach_to_program|flash|flash_and_execute}

Parameters

serial_no Specifies the serial number for the USB emulator you want to use.

debugging Makes the emulator operate as a debugger. After downloading your application, you cannot disconnect the debugger and use the target system as a stand-alone unit.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 285: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybat

Applicability All C-SPY hardware debugger drivers.

Description Controls the behavior of the debugger when code is downloaded.

Project>Options>Driver>Download>Mode

--endian

Syntax --endian {b|l}

Parameters

Applicability All C-SPY drivers.

Description Use this option to specify the byte order of the generated data. (Code is always little-endian.)

See also The IAR C/C++ Development Guide for RX for more information about the byte order of data.

--int

Syntax --int {16|32}

Parameters

attach_to_program Makes the debugger continue to execute a running application at its current location, without resetting the target system. The target system must be powered by external power.

flash Makes the emulator operate as a flash memory programmer. You cannot use the emulator as a debugger in this mode.

flash_and_execute Launches your application on the target board when the code has been downloaded.

b Specifies big-endian as the default byte order for data.

l (default) Specifies little-endian as the default byte order for data.

16 The size of the data type int is 16 bits.

32 (default) The size of the data type int is 32 bits.

UCSRX-3

285

Page 286: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

286

Reference information on C-SPY command line options

Applicability All C-SPY drivers.

Description Use this option to select whether the compiler uses 16 or 32 bits to represent the int data type.

See also The IAR C/C++ Development Guide for RX for more information about the size of the type int.

--ir_length

Syntax --ir_length=length

Parameters

Applicability The C-SPY J-Link driver.

Description Use this option to specify the combined length in bits of all instruction registers before the device to debugged, if one or more devices on the JTAG scan chain has a non-standard length (the default length is 8 bits).

See also JTAG Scan Chain, page 300.

Project>Options>J-Link RX>JTAG Scan Chain>Preceding IR bits

--macro

Syntax --macro filename

Parameters

Applicability Sent to cspybat.

Description Use this option to specify a C-SPY macro file to be loaded before executing the target application. This option can be used more than once on the command line.

See also Briefly about using C-SPY macros, page 234.

length The the combined length in bits of all instruction registers before the device to be debugged.

filename The C-SPY macro file to be used (filename extension mac).

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 287: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybat

--mapu

Syntax --mapu

Applicability The C-SPY simulator driver.

Description Specify this option to use the section information in the debug file for memory access checking. During the execution, the simulator will then check for accesses to unspecified memory ranges. If any such access is found, the C function call stack and a message will be printed on stderr and the execution will stop.

See also Memory access checking, page 135.

To set related options, choose:

Simulator>Memory Access Setup

-p

Syntax -p filename

Parameters

Applicability All C-SPY drivers.

Description Use this option to specify the device description file to be used.

See also Selecting a device description file, page 41.

--plugin

Syntax --plugin filename

Parameters

Applicability Sent to cspybat.

filename The device description file to be used.

filename The plugin file to be used (filename extension dll).

UCSRX-3

287

Page 288: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

288

Reference information on C-SPY command line options

Description Certain C/C++ standard library functions, for example printf, can be supported by C-SPY—for example, the C-SPY Terminal I/O window—instead of by real hardware devices. To enable such support in cspybat, a dedicated plugin module called rxLibSupport.dll or rxbat.dll located in the rx\bin directory must be used.

Use this option to include this plugin during the debug session. This option can be used more than once on the command line.

Note: You can use this option to include also other plugin modules, but in that case the module must be able to work with cspybat specifically. This means that the C-SPY plugin modules located in the common\plugin directory cannot normally be used with cspybat.

--silent

Syntax --silent

Applicability Sent to cspybat.

Description Use this option to omit the sign-on message.

--suppress_download

Syntax --suppress_download

Applicability All C-SPY hardware debugger drivers.

Description Use this option to disable the downloading of code, while preserving the present content of the flash memory. This option is useful if you want to debug an application that already resides in target memory.

If this option is combined with the --verify_download option, the debugger will read back the code image from non-volatile memory and verify that it is identical to the debugged application.

Project>Options>Debugger>Driver>Suppress download

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 289: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

The C-SPY Command Line Utility—cspybat

--timeout

Syntax --timeout milliseconds

Parameters

Applicability Sent to cspybat.

Description Use this option to limit the maximum allowed execution time.

This option is not available in the IDE.

--verify_download

Syntax --verify_download

Applicability All C-SPY hardware debugger drivers.

Description Use this option to verify that the downloaded code image can be read back from target memory with the correct contents.

To set this option, choose Project>Options>Debugger>Driver>Verify download

milliseconds The number of milliseconds before the execution stops.

UCSRX-3

289

Page 290: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

290

Reference information on C-SPY command line options

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 291: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugger optionsThis chapter describes the C-SPY® options available in the IAR Embedded Workbench® IDE. More specifically, this means:

● Setting debugger options

● Reference information on debugger options

● Reference information on C-SPY driver options.

Setting debugger optionsBefore you start the C-SPY debugger you must set some options—both C-SPY generic options and options required for the target system (C-SPY driver-specific options). This section gives detailed information about the options in the Debugger category.

To set debugger options in the IDE:

1 Choose Project>Options to display the Options dialog box.

2 Select Debugger in the Category list.

For more information about the generic options, see:

● Setup, page 292

● Images, page 294

● Extra Options, page 295

● Plugins, page 295.

3 On the Setup page, select the appropriate C-SPY driver from the Driver drop-down list.

4 To set the driver-specific options, select the appropriate driver from the Category list. Depending on which C-SPY driver you are using, different sets of option pages appear.

C-SPY driver Available options pages

C-SPY simulator Setup options for the simulator, page 297

C-SPY E1/E20 driver Communication, page 298Download, page 298

Table 39: Options specific to the C-SPY drivers you are using

UCSRX-3

291

Page 292: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

292

Reference information on debugger options

5 To restore all settings to the default factory settings, click the Factory Settings button.

6 When you have set all the required options, click OK in the Options dialog box.

Reference information on debugger optionsThis section gives reference information on C-SPY debugger options.

SetupThe Setup options select the C-SPY driver, the setup macro file, and device description file to use, and specify which default source code location to run to.

Figure 120: Debugger setup options

Driver

Selects the C-SPY driver for the target system you have:

C-SPY J-Link driver Download, page 298JTAG Scan Chain, page 300

C-SPY driver Available options pages

Table 39: Options specific to the C-SPY drivers you are using (Continued)

Simulator

E1/E20 Emulator

J-Link RX

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 293: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugger options

Run to

Specifies the location C-SPY runs to when the debugger starts after a reset. By default, C-SPY runs to the main function.

To override the default location, specify the name of a different location you want C-SPY to run to. You can specify assembler labels or whatever can be evaluated as such, for example function names.

If the option is deselected, the program counter will contain the regular hardware reset address at each reset.

Setup macros

Registers the contents of a setup macro file in the C-SPY startup sequence. Select Use macro file and specify the path and name of the setup file, for example SetupSimple.mac. If no extension is specified, the extension mac is assumed. A browse button is available for your convenience.

Device description file

A default device description file is selected automatically based on your project settings. To override the default file, select Override default and specify an alternative file. A browse button is available for your convenience.

For information about the device description file, see Modifying a device description file, page 45.

Device description files for each RX device are provided in the directory rx\config\debugger\ and have the filename extension ddf.

UCSRX-3

293

Page 294: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

294

Reference information on debugger options

ImagesThe Images options control the use of additional debug files to be downloaded.

Figure 121: Debugger images options

Download extra image

Controls the use of additional debug files to be downloaded:

If you want to download more than three images, use the related C-SPY macro, see __loadImage, page 253.

For more information, see Loading multiple images, page 43.

Path Specify the debug file to be downloaded. A browse button is available for your convenience.

Offset Specify an integer that determines the destination address for the downloaded debug file.

Debug info only Makes the debugger download only debug information, and not the complete debug file.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 295: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugger options

Extra OptionsThe Extra Options page provides you with a command line interface to C-SPY.

Figure 122: Debugger extra options

Use command line options

Specify additional command line arguments to be passed to C-SPY (not supported by the GUI).

PluginsThe Plugins options select the C-SPY plugin modules to be loaded and made available during debug sessions.

Figure 123: Debugger plugin options

UCSRX-3

295

Page 296: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

296

Reference information on debugger options

Select plugins to load

Selects the plugin modules to be loaded and made available during debug sessions. The list contains the plugin modules delivered with the product installation.

Description

Describes the plugin module.

Location

Informs about the location of the plugin module.

Generic plugin modules are stored in the common\plugins directory. Target-specific plugin modules are stored in the rx\plugins directory.

Originator

Informs about the originator of the plugin module, which can be modules provided by IAR Systems or by third-party vendors.

Version

Informs about the version number.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 297: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugger options

Reference information on C-SPY driver optionsThis section gives reference information on C-SPY driver options.

Setup options for the simulator The simulator Setup options control the behavior of the C-SPY simulator.

Figure 124: Simulator setup options

Peripheral simulation

These options set up peripheral simulation, which requires a plugin from a third-party vendor.

UCSRX-3

297

Page 298: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

298

Reference information on C-SPY driver options

Communication The Communication options determine how the E1/E20 emulator communicates with the host computer.

Figure 125: E1/E20 communication options

Serial No

Selects which Renesas emulator to use, if more than one is connected to your host computer via USB.

Download By default, C-SPY downloads the application to RAM or flash when a debug session starts. The Download options let you modify the behavior of the download.

Figure 126: C-SPY Download options

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 299: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Debugger options

Debugging mode

Makes the emulator operate as a debugger. After downloading your application, you cannot disconnect the debugger and use the target system as a stand-alone unit. In this mode, you cannot write ID Codes (that protect the memory from being accessed) to the flash memory.

Attach to program

Makes the debugger attach to a running application at its current location, without resetting the target system. To avoid unexpected behavior when using this option, the Debugger>Setup option Run to should be deselected.

For more information, see Start debugging a running application, page 44.

Flash writing mode

Makes the emulator operate as a flash memory programmer. You cannot use the emulator as a debugger in this mode. After downloading your application, an ID Code (that protects the memory from being accessed) is written to the flash memory.

Execute the user program after ending the debugger

Launches your application on the target board when the code has been downloaded.

Verify download

Verifies that the downloaded code image can be read back from target memory with the correct contents.

Suppress download

Disables the downloading of code, while preserving the present content of the flash memory. This command is useful if you want to debug an application that already resides in target memory.

If this option is combined with the Verify download option, the debugger will read back the code image from non-volatile memory and verify that it is identical to the debugged application.

UCSRX-3

299

Page 300: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

300

Reference information on C-SPY driver options

JTAG Scan Chain Only one device at a time can be debugged. If there is more than one device on the same JTAG scan chain, you must use the J-Link RX>JTAG Scan Chain options to specify which device to debug.

Figure 127: J-Link JTAG Scan Chain options

JTAG scan chain with multiple targets

Informs the debugger that there is more than one device on the JTAG scan chain.

Device position

Specify the position of the device you want to debug. The first device has position 0.

Use devices with deviant instruction register lengths

Informs the debugger that the JTAG instruction register of one or more devices on the JTAG scan chain has a non-standard length (the default length is 8 bits).

Preceding IR bits

Specify the combined length of the instruction registers of all devices that precede the device being debugged.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 301: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Additional information on C-SPY driversThis chapter describes the additional menus and features provided by the C-SPY® drivers. More specifically, this means:

● Reference information on the C-SPY driver menus

● Resolving problems.

Reference information on the C-SPY driver menusThis section describes the C-SPY driver menus.

Simulator menuWhen you use the simulator driver, the Simulator menu is added to the menu bar.

Figure 128: Simulator menu

These commands are available on the menu:

Interrupt Setup Displays a dialog box where you can configure C-SPY interrupt simulation, see Interrupt Setup dialog box, page 223.

Forced Interrupts Opens a window from where you can instantly trigger an interrupt, see Forced Interrupt window, page 226.

UCSRX-3

301

Page 302: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

302

Reference information on the C-SPY driver menus

Interrupt Status Opens a window which displays the status of all defined interrupts, see Interrupt Status window, page 227.

Interrupt Log Opens a window which logs entrances and exits to and from interrupts, see Interrupt Log window, page 229.

Interrupt Log Summary

Opens a window which displays a summary of the status of all defined interrupts, see Interrupt Log Summary window, page 231.

Memory Access Setup Displays a dialog box to simulate memory access checking by specifying memory areas with different access types, see Memory Access Setup dialog box, page 155.

Trace Opens a window which displays the collected trace data, see Trace window, page 165.

Function Trace Opens a window which displays the trace data for function calls and function returns, see Function Trace window, page 167.

Function Profiler Opens a window which shows timing information for the functions, see Function Profiler window, page 185.

Timeline Opens a window which shows trace data for interrupt logs and for the call stack, see Timeline window, page 168.

Breakpoint Usage Displays a dialog box which lists all active breakpoints, see Breakpoint Usage dialog box, page 116.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 303: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Additional information on C-SPY drivers

E1/E20 Emulator menuWhen you are using the C-SPY E1/E20 driver, the E1/E20 Emulator menu is added to the menu bar.

Figure 129: The E1/E20 Emulator menu

These commands are available on the menu:

Hardware Setup Displays a dialog box where you can configure how the emulator operates, see Hardware Setup dialog box (E1/E20), page 57.

Download Firmware Displays a dialog box where you can update the firmware of your emulator if needed, see Download Emulator Firmware dialog box, page 55.

Trace Opens a window which displays the collected trace data, see Trace window, page 165.

Function Trace Opens a window which displays the trace data for function calls and function returns, see Function Trace window, page 167.

Trace Settings Displays a dialog box where you can configure the trace generation and collection, see Trace Settings dialog box, page 163.

Function Profiler Opens a window which shows timing information for the functions, see Function Profiler window, page 185.

UCSRX-3

303

Page 304: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

304

Reference information on the C-SPY driver menus

J-Link menuWhen you are using the C-SPY J-Link driver, the J-Link menu is added to the menu bar.

Figure 130: The J-Link menu

Operating Frequency Displays a dialog box where you can inform the emulator of the operating frequency that the MCU is running at, see Operating Frequency dialog box, page 56.

Performance Analysis Opens a window which displays the results of the code performance analysis, see Performance Analysis window, page 193.

Performance Analysis Settings

Displays a dialog box where you can configure the code performance analysis, see Performance Analysis Setup dialog box, page 191.

RAM Monitor Setup Displays a dialog box where you configure the memory areas for data coverage, see RAM Monitor Setup dialog box, page 143.

Breakpoint Usage Displays a dialog box which lists all active breakpoints, see Breakpoint Usage dialog box, page 116.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 305: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Additional information on C-SPY drivers

These commands are available on the menu:

Hardware Setup Displays a dialog box where you can configure how the emulator operates, see Hardware Setup dialog box (J-Link), page 61.

Download Firmware Displays a dialog box where you can update the firmware of your emulator if needed, see Download Emulator Firmware dialog box, page 55.

Trace Opens a window which displays the collected trace data, see Trace window, page 165.

Function Trace Opens a window which displays the trace data for function calls and function returns, see Function Trace window, page 167.

Trace Settings Displays a dialog box where you can configure the trace generation and collection, see Trace Settings dialog box, page 163.

Function Profiler Opens a window which shows timing information for the functions, see Function Profiler window, page 185.

Operating Frequency Displays a dialog box where you can inform the emulator of the operating frequency that the MCU is running at, see Operating Frequency dialog box, page 56.

Performance Analysis Opens a window that displays the results of the code performance analysis, see Performance Analysis window, page 193.

Performance Analysis Settings

Displays a dialog box where you can configure the code performance analysis, see Performance Analysis Setup dialog box, page 191.

Power Setup Window Opens a window where you can configure the power measurement, see Power Setup window, page 206.

Power Log Window Opens a window that displays collected power values, see Power Log window, page 207.

Timeline Opens a window that shows trace data for power logs, see Timeline window, page 168.

Breakpoint Usage Displays a dialog box which lists all active breakpoints, see Breakpoint Usage dialog box, page 116.

UCSRX-3

305

Page 306: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

306

Resolving problems

Resolving problemsDebugging using the C-SPY hardware debugger systems requires interaction between many systems, independent from each other. For this reason, setting up this debug system can be a complex task. If something goes wrong, it might at first be difficult to locate the cause of the problem.

This section includes suggestions for resolving the most common problems that can occur when debugging with the C-SPY hardware debugger systems.

For problems concerning the operation of the evaluation board, refer to the documentation supplied with it, or contact your hardware distributor.

WRITE FAILURE DURING LOAD

There are several possible reasons for write failure during load. The most common is that your application has been incorrectly linked:

● Check the contents of your linker configuration file and make sure that your application has not been linked to the wrong address

● Check that you are using the correct linker configuration file.

If you are using the IAR Embedded Workbench IDE, the linker configuration file is automatically selected based on your choice of device.

To choose a device:

1 Choose Project>Options.

2 Select the General Options category.

3 Click the Target tab.

4 Choose the appropriate device from the Device drop-down list.

To override the default linker configuration file:

1 Choose Project>Options.

2 Select the Linker category.

3 Click the Config tab.

4 Choose the appropriate linker configuration file in the Linker configuration file area.

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 307: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Additional information on C-SPY drivers

NO CONTACT WITH THE TARGET HARDWARE

There are several possible reasons for C-SPY to fail to establish contact with the target hardware. Do this:

● Check the communication devices on your host computer

● Verify that the cable is properly plugged in and not damaged or of the wrong type

● Check that you have installed the correct USB driver for the emulator. If not, uninstall the USB driver and install the correct one

● Make sure that the evaluation board is supplied with sufficient power

● Check that the correct options for communication have been specified in the IAR Embedded Workbench IDE, see Communication, page 298.

Examine the linker configuration file to make sure that the application has not been linked to the wrong address. The easiest way to see if this is the problem is by checking the contents of the linker list file (.map)

UCSRX-3

307

Page 308: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

308

Resolving problems

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 309: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

Index

AAbort (Report Assert option) . . . . . . . . . . . . . . . . . . . . . . . 81absolute location, specifying for a breakpoint. . . . . . . . . . 128Access type (Edit Memory Access option) . . . . . . . . . . . . 158Access Type (Immediate breakpoints option) . . . . . . . . . . 127Access (Edit SFR option) . . . . . . . . . . . . . . . . . . . . . . . . . 155Action (Code breakpoints option) . . . . . . . . . . . . . . . . . . . 118Action (Hardware Code breakpoints option). . . . . . . . . . . 119Action (Immediate breakpoints option) . . . . . . . . . . . . . . 127Action (Software Code breakpoints option) . . . . . . . . . . . 120Add to Watch Window (SymbolicMemory window context menu) . . . . . . . . . . . . . . . . . . . . 147Add (SFR Setup window context menu). . . . . . . . . . . . . . 153Add (Watch window context menu) . . . . . . . . . . . . . . . . . . 94Address Range (Find in Trace option) . . . . . . . . . . . . . . . 178Address (Edit SFR option) . . . . . . . . . . . . . . . . . . . . . . . . 154Allow clock source change whenwriting internal flash (E1/E20 Hardware Setup) . . . . . . . . . 58Ambiguous symbol (Resolve Symbol Ambiguity option). 101application, built outside the IDE . . . . . . . . . . . . . . . . . . . . 42assembler labels, viewing . . . . . . . . . . . . . . . . . . . . . . . . . . 91assembler source code, fine-tuning . . . . . . . . . . . . . . . . . . 179assembler symbols, using in C-SPY expressions . . . . . . . . 89assembler variables, viewing. . . . . . . . . . . . . . . . . . . . . . . . 91assumptions, programming experience . . . . . . . . . . . . . . . . 21Attach to program (debugger option) . . . . . . . . . . . . . . . . 299Attach to program (E1/E20 option)

example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Auto Scroll (Timeline window context menu) . . . . . . . . . 171Auto window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93Autostep settings dialog box . . . . . . . . . . . . . . . . . . . . . . . . 85Autostep (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

B-B (C-SPY command line option). . . . . . . . . . . . . . . . . . . 280--backend (C-SPY command line option) . . . . . . . . . . . . . 281

backtrace informationgenerated by compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 69viewing in Call Stack window . . . . . . . . . . . . . . . . . . . . 75

batch mode, using C-SPY in . . . . . . . . . . . . . . . . . . . . . . . 277Big Endian (Memory window context menu) . . . . . . . . . . 138blocks, in C-SPY macros . . . . . . . . . . . . . . . . . . . . . . . . . 244bold style, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Break At (Code breakpoints option) . . . . . . . . . . . . . . . . . 117Break At (Hardware Code breakpoints option) . . . . . . . . . 119Break At (Immediate breakpoints option) . . . . . . . . . . . . . 127Break At (Log breakpoints option) . . . . . . . . . . . . . . . . . . 122Break At (Software Code breakpoints option) . . . . . . . . . 120Break (Debug menu). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50breakpoint condition, example . . . . . . . . . . . . . . . . . . . . . 112Breakpoint Usage dialog box . . . . . . . . . . . . . . . . . . . . . . 116Breakpoint Usage (E1/E20 Emulator menu) . . . . . . . . . . . 304Breakpoint Usage (J-Link menu) . . . . . . . . . . . . . . . . . . . 305Breakpoint Usage (Simulator menu). . . . . . . . . . . . . . . . . 302breakpoints

code, example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262connecting a C-SPY macro . . . . . . . . . . . . . . . . . . . . . 240consumers of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264description of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104disabling used by Stack window . . . . . . . . . . . . . . . . . 108icons for in the IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . 106in Memory window . . . . . . . . . . . . . . . . . . . . . . . . . . . 110listing all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265reasons for using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103setting

in memory window . . . . . . . . . . . . . . . . . . . . . . . . . 110using system macros . . . . . . . . . . . . . . . . . . . . . . . . 111using the dialog box . . . . . . . . . . . . . . . . . . . . . . . . 109

single-stepping if not available. . . . . . . . . . . . . . . . . . . . 40toggling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

UCSRX-3

309

Page 310: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

310

trace start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

trace stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

types of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104useful tips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Breakpoints dialog boxCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Data (E1/E20 and J-Link) . . . . . . . . . . . . . . . . . . . . . . 125Data (simulator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Hardware Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Immediate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121Performance Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195Performance Stop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196Software Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120Trace Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174Trace Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

Breakpoints window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114Browse (Trace toolbar) . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Bus width (External Area option) . . . . . . . . . . . . . . . . . . . . 63Byte order (External Area option). . . . . . . . . . . . . . . . . . . . 63Byte order (E1/E20 Hardware Setup) . . . . . . . . . . . . . . . . . 58

CC function information, in C-SPY. . . . . . . . . . . . . . . . . . . . 69C symbols, using in C-SPY expressions . . . . . . . . . . . . . . . 88C variables, using in C-SPY expressions . . . . . . . . . . . . . . 88call chain, displaying in C-SPY . . . . . . . . . . . . . . . . . . . . . 69Call stack information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Call Stack window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

for backtrace information. . . . . . . . . . . . . . . . . . . . . . . . 69Call Stack (Timeline window context menu) . . . . . . . . . . 172__cancelAllInterrupts (C-SPY system macro) . . . . . . . . . 249__cancelInterrupt (C-SPY system macro). . . . . . . . . . . . . 249Clear All (Debug Log window context menu) . . . . . . . . . . 79Clear trace data (Trace toolbar). . . . . . . . . . . . . . . . . . . . . 165Clear (Interrupt Log window context menu) . . . . . . . . . . . 231

Clear (Power Log window context menu). . . . . . . . . . . . . 209__clearBreak (C-SPY system macro) . . . . . . . . . . . . . . . . 249__closeFile (C-SPY system macro) . . . . . . . . . . . . . . . . . 250code

covering execution of. . . . . . . . . . . . . . . . . . . . . . . . . . 212options for downloading . . . . . . . . . . . . . . . . . . . . . . . 298

code breakpoints, overview. . . . . . . . . . . . . . . . . . . . . . . . 104Code Coverage window . . . . . . . . . . . . . . . . . . . . . . . . . . 212Code Coverage (Disassembly window context menu) . . . . 73code performance, analyzing . . . . . . . . . . . . . . . . . . . . . . 189--code_coverage_file (C-SPY command line option) . . . . 281command line options. . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

typographic convention . . . . . . . . . . . . . . . . . . . . . . . . . 25command prompt icon, in this guide . . . . . . . . . . . . . . . . . . 25communication setup, hardware drivers . . . . . . . . . . . . . . 298Communication (E1/E20 Hardware Setup). . . . . . . . . . . . . 59computer style, typographic convention . . . . . . . . . . . . . . . 25Condition (Performance Analysis option). . . . . . . . . . . . . 192conditional statements, in C-SPY macros . . . . . . . . . . . . . 243Conditions (Code breakpoints option) . . . . . . . . . . . . . . . 118Conditions (Hardware Code breakpoints option) . . . . . . . 119Conditions (Log breakpoints option) . . . . . . . . . . . . . . . . 122Conditions (Software Code breakpoints option) . . . . . . . . 121context menu, in windows. . . . . . . . . . . . . . . . . . . . . . . . . . 91conventions, used in this guide . . . . . . . . . . . . . . . . . . . . . . 24Copy WindowContents (Disassembly window context menu). . . . . . . . . . 75Copy (Debug Log window context menu) . . . . . . . . . . . . . 79copyright notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2--core (C-SPY command line option) . . . . . . . . . . . . . . . . 281cspybat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277current position, in C-SPY Disassembly window . . . . . . . . 72cursor, in C-SPY Disassembly window. . . . . . . . . . . . . . . . 72--cycles (C-SPY command line option) . . . . . . . . . . . . . . 282C-SPY

batch mode, using in . . . . . . . . . . . . . . . . . . . . . . . . . . 277debugger systems, overview of . . . . . . . . . . . . . . . . . . . 30differences between drivers . . . . . . . . . . . . . . . . . . . . . . 33environment overview . . . . . . . . . . . . . . . . . . . . . . . . . . 27plugin modules, loading. . . . . . . . . . . . . . . . . . . . . . . . . 41

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 311: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

setting up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39–40starting the debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

C-SPY driversE1/E20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34J-Link. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32specifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

C-SPY expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88evaluating. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99in C-SPY macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Tooltip watch, using. . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Watch window, using . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

C-SPY macro "__message"style (Log breakpoints option) . . . . . . . . . . . . . . . . . . . . . 122C-SPY macros

blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244conditional statements . . . . . . . . . . . . . . . . . . . . . . . . . 243C-SPY expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 243dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

checking status of register. . . . . . . . . . . . . . . . . . . . 239checking the status of WDT . . . . . . . . . . . . . . . . . . 239creating a log macro . . . . . . . . . . . . . . . . . . . . . . . . 240

executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235connecting to a breakpoint . . . . . . . . . . . . . . . . . . . 240using Quick Watch . . . . . . . . . . . . . . . . . . . . . . . . . 239using setup macro and setup file . . . . . . . . . . . . . . . 238

functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89, 241loop statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243macro statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243setup macro file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

executing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238setup macro functions . . . . . . . . . . . . . . . . . . . . . . . . . 234

summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246system macros, summary of. . . . . . . . . . . . . . . . . . . . . 247using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89, 242

C-SPY options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291Extra Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

C-SPYLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32C++ Exceptions>Break on Throw (Debug menu) . . . . . . . . 51C++ Exceptions>Break on Uncaught Exception (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51C++ terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

D-d (C-SPY command line option) . . . . . . . . . . . . . . . . . . . 282data breakpoints, overview . . . . . . . . . . . . . . . . . . . . . . . . 105Data Coverage (Memory window context menu) . . . . . . . 139data coverage, in Memory window . . . . . . . . . . . . . . . . . . 137DATA_FLASH (memory zone) . . . . . . . . . . . . . . . . . . . . 133ddf (filename extension), selecting a file. . . . . . . . . . . . . . . 41Debug Log window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Debug Log window context menu . . . . . . . . . . . . . . . . . . . 79Debug menu (C-SPY main window). . . . . . . . . . . . . . . . . . 50Debug the program re-writingthe DATA FLASH (E1/E20 Hardware Setup) . . . . . . . . . . . 59Debug the program re-writingthe PROGRAM ROM (E1/E20 Hardware Setup) . . . . . . . . 59Debug the program usingthe CPU rewrite mode (J-Link Hardware Setup). . . . . . . . . 62Debug (Report Assert option) . . . . . . . . . . . . . . . . . . . . . . . 81debugger concepts, definitions of . . . . . . . . . . . . . . . . . . . . 30debugger drivers

E1/E20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34J-Link. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

debugger system overview . . . . . . . . . . . . . . . . . . . . . . . . . 30Debugging mode (debugger option) . . . . . . . . . . . . . . . . . 299debugging projects

externally built applications . . . . . . . . . . . . . . . . . . . . . . 42loading multiple images. . . . . . . . . . . . . . . . . . . . . . . . . 43

debugging, RTOS awareness. . . . . . . . . . . . . . . . . . . . . . . . 29__delay (C-SPY system macro) . . . . . . . . . . . . . . . . . . . . 250Delay (Autostep Settings option) . . . . . . . . . . . . . . . . . . . . 85Delete (Breakpoints window context menu) . . . . . . . . . . . 115

UCSRX-3

311

Page 312: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

312

Delete (SFR Setup window context menu) . . . . . . . . . . . . 153Delete/revert All Custom SFRs (SFR Setup window context menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Description (Edit Interrupt option) . . . . . . . . . . . . . . . . . . 225description (interrupt property) . . . . . . . . . . . . . . . . . . . . . 225Device description file (debugger option) . . . . . . . . . . . . . 293device description files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

definition of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45memory zones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133modifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45register zone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133specifying interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . 257

Device position (J-Link debugger option). . . . . . . . . . . . . 300--device_select (C-SPY command line option) . . . . . . . . . 283Disable All (Breakpoints window context menu) . . . . . . . 115Disable (Breakpoints window context menu) . . . . . . . . . . 115__disableInterrupts (C-SPY system macro) . . . . . . . . . . . 250--disable_interrupts (C-SPY command line option) . . . . . 283Disassembly window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

context menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Display the cycle as a timespan (Performance Analysis option) . . . . . . . . . . . . . . . . . 193DLIB, documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23do (macro statement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244document conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24documentation

overview of guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23overview of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . 22this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

--double (C-SPY command line option) . . . . . . . . . . . . . . 283Download extra image (debugger option) . . . . . . . . . . . . . 294Download Firmware (E1/E20 Emulator menu). . . . . . . . . 303Download Firmware (J-Link menu) . . . . . . . . . . . . . . . . . 305--download_only (C-SPY command line option) . . . . . . . 284Driver (debugger option). . . . . . . . . . . . . . . . . . . . . . . . . . 292__driverType (C-SPY system macro) . . . . . . . . . . . . . . . . 251--drv_communication (C-SPY command line option). . . . 284--drv_mode (C-SPY command line option) . . . . . . . . . . . 284

EEdit Expressions (Trace toolbar). . . . . . . . . . . . . . . . . . . . 166Edit Interrupt dialog box. . . . . . . . . . . . . . . . . . . . . . . . . . 225Edit Memory Access dialog box . . . . . . . . . . . . . . . . . . . . 157Edit Memory Range dialog box . . . . . . . . . . . . . . . . . . . . 154Edit RAM monitor block dialog box. . . . . . . . . . . . . . . . . 144Edit Settings (Trace toolbar) . . . . . . . . . . . . . . . . . . . . . . . 166Edit (Breakpoints window context menu) . . . . . . . . . . . . . 115Edit (SFR Setup window context menu) . . . . . . . . . . . . . . 153edition, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Embedded C++ Technical Committee . . . . . . . . . . . . . . . . 24emulator firmware, updating. . . . . . . . . . . . . . . . . . . . . . . . 55Emulator mode (E1/E20 Hardware Setup) . . . . . . . . . . . . . 60Enable All (Breakpoints window context menu). . . . . . . . 115Enable interrupt simulation (Interrupt Setup option). . . . . 223Enable Log File (Log File option). . . . . . . . . . . . . . . . . . . . 80Enable start routine (Start/Stop Function Settings option) . 83Enable stop routine (Start/Stop Function Settings option). . 84Enable (Breakpoints window context menu). . . . . . . . . . . 115Enable (Interrupt Log window context menu). . . . . . . . . . 230Enable (Power Log window context menu) . . . . . . . . . . . 209Enable (Timeline window context menu) . . . . . . . . . . . . . 172__enableInterrupts (C-SPY system macro) . . . . . . . . . . . . 251Enable/Disable Breakpoint (CallStack window context menu) . . . . . . . . . . . . . . . . . . . . . . . 76Enable/Disable Breakpoint (Disassemblywindow context menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Enable/Disable (Trace toolbar) . . . . . . . . . . . . . . . . . . . . . 165End address (Edit Memory Access option) . . . . . . . . . . . . 158--endian (C-SPY command line option) . . . . . . . . . . . . . . 285Enter Location dialog box. . . . . . . . . . . . . . . . . . . . . . . . . 128__evaluate (C-SPY system macro) . . . . . . . . . . . . . . . . . . 252examples

C-SPY macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221macros

checking status of register. . . . . . . . . . . . . . . . . . . . 239checking status of WDT . . . . . . . . . . . . . . . . . . . . . 239

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 313: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

creating a log macro . . . . . . . . . . . . . . . . . . . . . . . . 240using Quick Watch . . . . . . . . . . . . . . . . . . . . . . . . . 239

performing tasks and continue execution . . . . . . . . . . . 112tracing incorrect function arguments . . . . . . . . . . . . . . 112

execUserExit (C-SPY setup macro) . . . . . . . . . . . . . . . . . 246execUserPreload (C-SPY setup macro). . . . . . . . . . . . . . . 246execUserPreReset (C-SPY setup macro). . . . . . . . . . . . . . 246execUserReset (C-SPY setup macro) . . . . . . . . . . . . . . . . 246execUserSetup (C-SPY setup macro) . . . . . . . . . . . . . . . . 246Execute the user programafter ending the debugger (debugger option). . . . . . . . . . . 299executed code, covering . . . . . . . . . . . . . . . . . . . . . . . . . . 212execution history, tracing . . . . . . . . . . . . . . . . . . . . . . . . . 162expressions. See C-SPY expressionsExternal memory areas (E1/E20 Hardware Setup) . . . . . . . 58External memory areas (J-Link Hardware Setup) . . . . . . . . 62external memory area, defining. . . . . . . . . . . . . . . . . . . . . . 63Extra Options for C-SPY . . . . . . . . . . . . . . . . . . . . . . . . . 295E1/E20 (C-SPY driver) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

hardware installation . . . . . . . . . . . . . . . . . . . . . . . . . . . 35menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

FFile format (Memory Save option) . . . . . . . . . . . . . . . . . . 140file types

device description, specifying in IDE . . . . . . . . . . . . . . 41macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41, 293

filename extensionsddf, selecting device description file . . . . . . . . . . . . . . . 41mac, using macro file . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Filename (Memory Restore option) . . . . . . . . . . . . . . . . . 141Filename (Memory Save option). . . . . . . . . . . . . . . . . . . . 140Fill dialog box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Find in Trace dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . 177Find in Trace window . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178Find (Memory window context menu) . . . . . . . . . . . . . . . 139Find (Trace toolbar) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166firmware (emulator), updating . . . . . . . . . . . . . . . . . . . . . . 55

first activation time (interrupt property)definition of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217First activation (Edit Interrupt option). . . . . . . . . . . . . . . . 225flash memory areas, configuring. . . . . . . . . . . . . . . . . . . . . 64flash memory, load library module to . . . . . . . . . . . . . . . . 253Flash writing mode (debugger option) . . . . . . . . . . . . . . . 299for (macro statement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Forced Interrupt window. . . . . . . . . . . . . . . . . . . . . . . . . . 226Forced Interrupts (Simulator menu) . . . . . . . . . . . . . . . . . 301Function Profiler window . . . . . . . . . . . . . . . . . . . . . . . . . 185Function Profiler (E1/E20 Emulator menu) . . . . . . . . . . . 303Function Profiler (J-Link menu) . . . . . . . . . . . . . . . . . . . . 305Function Profiler (Simulator menu) . . . . . . . . . . . . . . . . . 302Function Trace window. . . . . . . . . . . . . . . . . . . . . . . . . . . 167Function Trace (E1/E20 Emulator menu) . . . . . . . . . . . . . 303Function Trace (J-Link menu). . . . . . . . . . . . . . . . . . . . . . 305Function Trace (Simulator menu) . . . . . . . . . . . . . . . . . . . 302functions, C-SPY running to when starting. . . . . . . . . 40, 293

GGo to Source (Breakpoints window context menu) . . . . . . 115Go to Source (Call Stack window context menu) . . . . . . . . 76Go To Source (Timeline window context menu). . . . . . . . 172Go (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50, 68

Hhardware code breakpoints, overview . . . . . . . . . . . . . . . . 105Hardware Setup dialog box (E1/E20) . . . . . . . . . . . . . . . . . 57Hardware Setup dialog box (J-Link) . . . . . . . . . . . . . . . . . . 61Hardware Setup (E1/E20 Emulator menu) . . . . . . . . . . . . 303Hardware Setup (J-Link menu) . . . . . . . . . . . . . . . . . . . . . 305hardware setup, power consumption because of . . . . . . . . 203highlighting, in C-SPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Hold time (Edit Interrupt option) . . . . . . . . . . . . . . . . . . . 226hold time (interrupt property), definition of . . . . . . . . . . . 217

UCSRX-3

313

Page 314: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

314

Iicons, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25ID Code verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85if else (macro statement) . . . . . . . . . . . . . . . . . . . . . . . . . . 243if (macro statement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243Ignore (Report Assert option) . . . . . . . . . . . . . . . . . . . . . . . 81illegal memory accesses, checking for . . . . . . . . . . . . . . . 135Images window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53images, loading multiple. . . . . . . . . . . . . . . . . . . . . . . . . . 294immediate breakpoints, overview . . . . . . . . . . . . . . . . . . . 105Include (Log File option) . . . . . . . . . . . . . . . . . . . . . . . . . . 80Input clock (EXTAL) (E1/E20 Hardware Setup) . . . . . . . . 58Input clock (EXTAL) (J-Link Hardware Setup) . . . . . . . . . 62Input Mode dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78input, special characters in Terminal I/O window . . . . . . . . 77installation directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Instruction Profiling (Disassembly window context menu). 73--int (C-SPY command line option) . . . . . . . . . . . . . . . . . 285Intel-extended, C-SPY output format . . . . . . . . . . . . . . . . . 32interference, power consumption because of. . . . . . . . . . . 203internal flash memory areas, configuring . . . . . . . . . . . . . . 64Internal flash memory overwrite (E1/E20 Hardware Setup) 59interrupt handling, power consumption during . . . . . . . . . 201Interrupt Log Summary window . . . . . . . . . . . . . . . . . . . . 231Interrupt Log Summary (Simulator menu) . . . . . . . . . . . . 302Interrupt Log window . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Interrupt Log (Simulator menu) . . . . . . . . . . . . . . . . . . . . 302Interrupt Setup dialog box . . . . . . . . . . . . . . . . . . . . . . . . 223Interrupt Setup (Simulator menu) . . . . . . . . . . . . . . . . . . . 301Interrupt Status window . . . . . . . . . . . . . . . . . . . . . . . . . . 227Interrupt Status (Simulator menu). . . . . . . . . . . . . . . . . . . 302interrupt system, using device description file . . . . . . . . . 220Interrupt (Edit Interrupt option) . . . . . . . . . . . . . . . . . . . . 225Interrupt (Timeline window context menu). . . . . . . . . . . . 172interrupts

adapting C-SPY system for target hardware . . . . . . . . 220simulated, introduction to . . . . . . . . . . . . . . . . . . . . . . 215timer, example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

using system macros . . . . . . . . . . . . . . . . . . . . . . . . . . 219IO (memory zone). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133IO1 (memory zone). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133IO2 (memory zone). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133--ir_length (C-SPY command line option) . . . . . . . . . . . . 286__isBatchMode (C-SPY system macro) . . . . . . . . . . . . . . 252italic style, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

JJTAG scan chain with multiple targets (J-Linkdebugger option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300JTAG (J-Link Hardware Setup). . . . . . . . . . . . . . . . . . . . . . 62J-Link (C-SPY driver). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

hardware installation . . . . . . . . . . . . . . . . . . . . . . . . . . . 37menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

Llabels (assembler), viewing. . . . . . . . . . . . . . . . . . . . . . . . . 91Length (Fill option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142lightbulb icon, in this guide. . . . . . . . . . . . . . . . . . . . . . . . . 25Little Endian (Memory window context menu) . . . . . . . . 138Live Watch window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95__loadImage(C-SPY system macro) . . . . . . . . . . . . . . . . . 253loading multiple debug files, list currently loaded. . . . . . . . 53loading multiple images . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Locals window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93log breakpoints, overview . . . . . . . . . . . . . . . . . . . . . . . . . 104Log File dialog box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Logging>Set Log file (Debug menu) . . . . . . . . . . . . . . . . . 51Logging>Set Terminal I/O Log file (Debug menu) . . . . . . . 51loop statements, in C-SPY macros . . . . . . . . . . . . . . . . . . 243low-power mode, power consumption during . . . . . . . . . . 200

Mmac (filename extension), using a macro file . . . . . . . . . . . 41--macro (C-SPY command line option) . . . . . . . . . . . . . . 286

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 315: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

Macro Configuration dialog box . . . . . . . . . . . . . . . . . . . . 237macro files, specifying . . . . . . . . . . . . . . . . . . . . . . . . 41, 293macro statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243macros

executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

Macros (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51main function, C-SPY running to when starting . . . . . 40, 293--mapu (C-SPY command line option) . . . . . . . . . . . . . . . 287MCU operation

configuring (E1/E20) . . . . . . . . . . . . . . . . . . . . . . . . 57–58configuring (J-Link). . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

MCU speed, specifying. . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Measure the performance onlyonce (Performance Analysis option) . . . . . . . . . . . . . . . . . 193memory access checking. . . . . . . . . . . . . . . . . . . . . . . . . . 135Memory access checking (Memory Access Setup option) 156Memory Access Setup dialog box. . . . . . . . . . . . . . . . . . . 155Memory Access Setup (Simulator menu) . . . . . . . . . . . . . 302memory accesses, illegal. . . . . . . . . . . . . . . . . . . . . . . . . . 135Memory Fill (Memory window context menu) . . . . . . . . . 139memory map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155Memory range (Edit Memory Access option) . . . . . . . . . . 158Memory Restore dialog box . . . . . . . . . . . . . . . . . . . . . . . 141Memory Restore (Memory window context menu). . . . . . 139Memory Save dialog box . . . . . . . . . . . . . . . . . . . . . . . . . 140Memory Save (Memory window context menu) . . . . . . . . 139Memory window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136memory zones. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

in device description file . . . . . . . . . . . . . . . . . . . . . . . 133__memoryRestore (C-SPY system macro) . . . . . . . . . . . . 254__memorySave (C-SPY system macro) . . . . . . . . . . . . . . 254Memory>Restore (Debug menu) . . . . . . . . . . . . . . . . . . . . 51Memory>Save (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . 51menu bar, C-SPY-specific . . . . . . . . . . . . . . . . . . . . . . . . . . 49Message (Log breakpoints option) . . . . . . . . . . . . . . . . . . 122MISRA C, documentation . . . . . . . . . . . . . . . . . . . . . . . . . 23Mixed Mode (Disassembly window context menu) . . . . . . 75Mode (J-Link Hardware Setup) . . . . . . . . . . . . . . . . . . . . . 61Motorola, C-SPY output format . . . . . . . . . . . . . . . . . . . . . 32

Move to PC (Disassembly window context menu) . . . . . . . 73

NName (Edit SFR option) . . . . . . . . . . . . . . . . . . . . . . . . . . 154naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Navigate (Timeline window context menu) . . . . . . . . . . . 171New Breakpoint (Breakpoints window context menu) . . . 115Next Statement (Debug menu) . . . . . . . . . . . . . . . . . . . . . . 50Next Symbol (Symbolic Memory window context menu) 146

O__openFile (C-SPY system macro). . . . . . . . . . . . . . . . . . 255Operating Frequency (E1/E20 Emulator menu) . . . . . . . . 304Operating Frequency (J-Link menu) . . . . . . . . . . . . . . . . . 305operating frequency, specifying . . . . . . . . . . . . . . . . . . . . . 56Operation (Fill option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 142operators, sizeof in C-SPY . . . . . . . . . . . . . . . . . . . . . . . . . 90optimizations, effects on variables . . . . . . . . . . . . . . . . . . . 90options

in the IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291on the command line . . . . . . . . . . . . . . . . . . . . . . 280, 295

Options (Stack window context menu) . . . . . . . . . . . . . . . 149__orderInterrupt (C-SPY system macro). . . . . . . . . . . . . . 257Originator (debugger option) . . . . . . . . . . . . . . . . . . . . . . 296Overwrite data in FLASH without erasing the FLASH area block (J-Link Hardware Setup) . . . . . . . . . . . . . . . . . . . . . . 62

P-p (C-SPY command line option) . . . . . . . . . . . . . . . . . . . 287parameters

tracing incorrect values of . . . . . . . . . . . . . . . . . . . . . . . 69typographic convention . . . . . . . . . . . . . . . . . . . . . . . . . 25

part number, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Performance Analysis Settings (J-Link menu) . . . . . 304–305Performance Analysis Setup dialog box . . . . . . . . . . . . . . 191Performance Analysis window . . . . . . . . . . . . . . . . . . . . . 193

UCSRX-3

315

Page 316: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

316

Performance Analysis (E1/E20 Emulator menu) . . . . . . . 304Performance Analysis (J-Link menu) . . . . . . . . . . . . . . . . 305performance start and stop breakpoints, overview. . . . . . . 105Performance Start breakpoints dialog box . . . . . . . . . . . . 195Performance Stop breakpoints dialog box. . . . . . . . . . . . . 196Peripheral simulation (C-SPY simulator option). . . . . . . . 297peripheral units

detecting unattended . . . . . . . . . . . . . . . . . . . . . . . . . . 201device-specific . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45simulating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

Please select one symbol(Resolve Symbol Ambiguity option) . . . . . . . . . . . . . . . . 101--plugin (C-SPY command line option) . . . . . . . . . . . . . . 287plugin modules (C-SPY). . . . . . . . . . . . . . . . . . . . . . . . . . . 32

loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Plugins (C-SPY options). . . . . . . . . . . . . . . . . . . . . . . . . . 295__popSimulatorInterruptExecutingStack (C-SPYsystem macro). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257power consumption, measuring. . . . . . . . . . . . . . . . . 180, 197Power Log window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207Power Log Window (J-Link menu). . . . . . . . . . . . . . . . . . 305Power Log (Timeline window context menu) . . . . . . . . . . 171power sampling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180Power Setup window . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Power Setup Window (J-Link menu) . . . . . . . . . . . . . . . . 305Power target from the emulator (E1/E20 Hardware Setup) . 60Preceding IR bits (J-Link debugger option) . . . . . . . . . . . 300prerequisites, programming experience. . . . . . . . . . . . . . . . 21Previous Symbol (SymbolicMemory window context menu) . . . . . . . . . . . . . . . . . . . . 146probability (interrupt property) . . . . . . . . . . . . . . . . . . . . . 226

definition of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Probability % (Edit Interrupt option) . . . . . . . . . . . . . . . . 226problems, resolving. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306Profile Selection (Timeline window context menu) . . . . . 172profiling

on function level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181on instruction level. . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

profiling information, on functions and instructions . . . . . 179

profiling sourcessampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180, 186trace (calls) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180, 186trace (flat) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180, 186

program execution, in C-SPY . . . . . . . . . . . . . . . . . . . . . . . 65programming experience. . . . . . . . . . . . . . . . . . . . . . . . . . . 21projects, for debugging externally built applications. . . . . . 42publication date, of this guide . . . . . . . . . . . . . . . . . . . . . . . . 2

QQuick Watch window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

executing C-SPY macros . . . . . . . . . . . . . . . . . . . . . . . 239

RRAM Monitor Setup dialog box . . . . . . . . . . . . . . . . . . . . 143RAM Monitor Setup (E1/E20 Emulator menu). . . . . . . . . 304RAM (memory zone) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Range for (Viewing Range option) . . . . . . . . . . . . . . . . . . 173__readFile (C-SPY system macro) . . . . . . . . . . . . . . . . . . 258__readFileByte (C-SPY system macro) . . . . . . . . . . . . . . 259reading guidelines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21__readMemoryByte (C-SPY system macro) . . . . . . . . . . . 259__readMemory8 (C-SPY system macro) . . . . . . . . . . . . . 259__readMemory16 (C-SPY system macro) . . . . . . . . . . . . 259__readMemory32 (C-SPY system macro) . . . . . . . . . . . . 260reference information, typographic convention. . . . . . . . . . 25Refresh (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51register groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

predefined, enabling. . . . . . . . . . . . . . . . . . . . . . . . . . . 150Register setting (E1/E20 Hardware Setup) . . . . . . . . . . . . . 58Register window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150registered trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2__registerMacroFile (C-SPY system macro). . . . . . . . . . . 260registers, displayed in Register window . . . . . . . . . . . . . . 150Remove (Watch window context menu) . . . . . . . . . . . . . . . 94Repeat interval (Edit Interrupt option) . . . . . . . . . . . . . . . 225repeat interval (interrupt property), definition of. . . . . . . . 217

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 317: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

Replace (Memory window context menu) . . . . . . . . . . . . 139Report Assert dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . 81Reset (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50__resetFile (C-SPY system macro) . . . . . . . . . . . . . . . . . . 261Resolve Source Ambiguity dialog box . . . . . . . . . . . . . . . 129Restart emulator when tracebuffer is full (Trace Settings option) . . . . . . . . . . . . . . . . . 164Restore (Memory Restore option). . . . . . . . . . . . . . . . . . . 141return (macro statement) . . . . . . . . . . . . . . . . . . . . . . . . . . 244ROM (memory zone) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133ROM-monitor, definition of . . . . . . . . . . . . . . . . . . . . . . . . 31RTOS awareness debugging . . . . . . . . . . . . . . . . . . . . . . . . 29RTOS awareness (C-SPY plugin module). . . . . . . . . . . . . . 29Run to Cursor (Call Stack window context menu) . . . . . . . 76Run to Cursor (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . 51Run to Cursor (Disassembly window context menu) . . . . . 73Run to Cursor, command for executing. . . . . . . . . . . . . . . . 68Run to (C-SPY option) . . . . . . . . . . . . . . . . . . . . . . . . 40, 293

Ssampling, profiling source. . . . . . . . . . . . . . . . . . . . . 180, 186Save Custom SFRs (SFR Setup window context menu) . . 153Save to log file (Interrupt Log window context menu) . . . 231Save to log file (Power Log window context menu) . . . . . 209Save (Memory Save option) . . . . . . . . . . . . . . . . . . . . . . . 140Save (Trace toolbar) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Scale (Viewing Range option). . . . . . . . . . . . . . . . . . . . . . 174searching in trace data. . . . . . . . . . . . . . . . . . . . . . . . . . . . 162Select All (Debug Log window context menu) . . . . . . . . . . 79Select Graphs (Timeline window context menu). . . . . . . . 172Select plugins to load (debugger option). . . . . . . . . . . . . . 296Select Statics dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . . 98Serial No (E1/E20 option) . . . . . . . . . . . . . . . . . . . . . . . . 298Set Data Breakpoint (Memory window context menu) . . . 139Set Next Statement (Debug menu) . . . . . . . . . . . . . . . . . . . 51Set Next Statement (Disassembly window context menu) . 75__setCodeBreak (C-SPY system macro). . . . . . . . . . . . . . 261__setDataBreak (C-SPY system macro) . . . . . . . . . . . . . . 263

__setLogBreak (C-SPY system macro) . . . . . . . . . . . . . . 264__setSimBreak (C-SPY system macro) . . . . . . . . . . . . . . 266__setTraceStartBreak (C-SPY system macro). . . . . . . . . . 267__setTraceStopBreak (C-SPY system macro). . . . . . . . . . 268setup macro functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

reserved names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246Setup macros (debugger option) . . . . . . . . . . . . . . . . . . . . 293Setup (C-SPY options) . . . . . . . . . . . . . . . . . . . . . . . . . . . 292SFR

in Register window . . . . . . . . . . . . . . . . . . . . . . . . . . . 151using as assembler symbols . . . . . . . . . . . . . . . . . . . . . . 89

SFR Setup window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Show all images (Images window context menu) . . . . . . . . 54Show all variables with staticstorage duration (Select Statics option). . . . . . . . . . . . . . . . 98Show All (SFR Setup window context menu). . . . . . . . . . 153Show Arguments (Call Stack window context menu) . . . . . 76Show As (Watch window context menu) . . . . . . . . . . . . . . 95Show Custom SFRs only (SFRSetup window context menu) . . . . . . . . . . . . . . . . . . . . . . 153Show cycles (Interrupt Log window context menu) . . . . . 231Show Cycles (Power Log window context menu). . . . . . . 210Show Factory SFRs only (SFRSetup window context menu) . . . . . . . . . . . . . . . . . . . . . . 153Show Numerical Value (Timeline window context menu) 172Show offsets (Stack window context menu) . . . . . . . . . . . 149Show only (Image window context menu) . . . . . . . . . . . . . 54Show selected variables only (Select Statics option). . . . . . 98Show time (Interrupt Log window context menu). . . . . . . 231Show Time (Power Log window context menu) . . . . . . . . 210Show variables (Stack window context menu) . . . . . . . . . 149--silent (C-SPY command line option) . . . . . . . . . . . . . . . 288simulating interrupts, enabling/disabling . . . . . . . . . . . . . 223simulator driver, selecting . . . . . . . . . . . . . . . . . . . . . . . . . . 34Simulator menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301simulator, introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Size (Code breakpoints option). . . . . . . . . . . . . . . . . . . . . 117Size (Edit SFR option) . . . . . . . . . . . . . . . . . . . . . . . . . . . 155Size (Timeline window context menu) . . . . . . . . . . . . . . . 172sizeof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

UCSRX-3

317

Page 318: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

318

software code breakpoints, overview . . . . . . . . . . . . . . . . 105software delay, power consumption during . . . . . . . . . . . . 199__sourcePosition (C-SPY system macro) . . . . . . . . . . . . . 269special function registers (SFR)

in Register window . . . . . . . . . . . . . . . . . . . . . . . . . . . 151using as assembler symbols . . . . . . . . . . . . . . . . . . . . . . 89

stack usage, computing . . . . . . . . . . . . . . . . . . . . . . . . . . . 134Stack window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147standard C, sizeof operator in C-SPY . . . . . . . . . . . . . . . . . 90Start address (Edit Memory Access option) . . . . . . . . . . . 158Start address (Fill option) . . . . . . . . . . . . . . . . . . . . . . . . . 142Start address (Memory Save option) . . . . . . . . . . . . . . . . . 140Start routine location (Start/Stop Function Settings option) 83Start/Stop Function Settings dialog box . . . . . . . . . . . . . . . 82Statics window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Step Into (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Step Into, description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Step Out (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Step Out, description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Step Over (Debug menu) . . . . . . . . . . . . . . . . . . . . . . . . . . 50Step Over, description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67step points, definition of . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Stop address (Memory Save option) . . . . . . . . . . . . . . . . . 140Stop Debugging (Debug menu). . . . . . . . . . . . . . . . . . . . . . 50Stop routine location (Start/Stop Function Settings option) 84__strFind (C-SPY system macro) . . . . . . . . . . . . . . . . . . . 269__subString (C-SPY system macro) . . . . . . . . . . . . . . . . . 270Suppress download (debugger option) . . . . . . . . . . . . . . . 299--suppress_download (C-SPY command line option) . . . . 288Symbolic Memory window. . . . . . . . . . . . . . . . . . . . . . . . 145Symbols window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100symbols, using in C-SPY expressions . . . . . . . . . . . . . . . . . 88

Ttarget system, definition of . . . . . . . . . . . . . . . . . . . . . . . . . 31__targetDebuggerVersion (C-SPY system macro) . . . . . . 270Terminal IO Log Files (Terminal IO Log Files option) . . . . 78Terminal I/O Log Files dialog box . . . . . . . . . . . . . . . . . . . 78

Terminal I/O window . . . . . . . . . . . . . . . . . . . . . . . . . . 70, 77terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Text search (Find in Trace option) . . . . . . . . . . . . . . . . . . 177Time Axis Unit (Timeline window context menu) . . . . . . 172time interval, in Timeline window . . . . . . . . . . . . . . . . . . 183Timeline window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168Timeline (J-Link menu) . . . . . . . . . . . . . . . . . . . . . . . . . . 305Timeline (Simulator menu) . . . . . . . . . . . . . . . . . . . . . . . . 302--timeout (C-SPY command line option) . . . . . . . . . . . . . 289timer interrupt, example . . . . . . . . . . . . . . . . . . . . . . . . . . 221Toggle Breakpoint (Code)(Call Stack window context menu) . . . . . . . . . . . . . . . . . . . 76Toggle Breakpoint (Code)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Hardware (Code)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Log)(Call Stack window context menu) . . . . . . . . . . . . . . . . . . . 76Toggle Breakpoint (Log)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Performance Start)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Performance Stop)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Software Code)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Trace Start)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 74Toggle Breakpoint (Trace Stop)(Disassembly window context menu) . . . . . . . . . . . . . . . . . 75Toggle source (Trace toolbar) . . . . . . . . . . . . . . . . . . . . . . 165__toLower (C-SPY system macro) . . . . . . . . . . . . . . . . . . 271tools icon, in this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25__toString (C-SPY system macro) . . . . . . . . . . . . . . . . . . 271__toUpper (C-SPY system macro) . . . . . . . . . . . . . . . . . . 272Trace capacity (Trace Settings option) . . . . . . . . . . . . . . . 164trace data, searching in . . . . . . . . . . . . . . . . . . . . . . . . . . . 162Trace Expressions window . . . . . . . . . . . . . . . . . . . . . . . . 176Trace mode (Trace Settings option) . . . . . . . . . . . . . . . . . 164Trace output (Trace Settings option) . . . . . . . . . . . . . . . . . 164

UCSRX-3

C-SPY® Debugging Guidefor RX

Page 319: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

Trace Settings dialog box . . . . . . . . . . . . . . . . . . . . . . . . . 163Trace Settings (E1/E20 Emulator menu). . . . . . . . . . . . . . 303Trace Settings (J-Link menu) . . . . . . . . . . . . . . . . . . . . . . 305trace start and stop breakpoints, overview. . . . . . . . . . . . . 105Trace Start breakpoints dialog box . . . . . . . . . . . . . . . . . . 174Trace Stop breakpoints dialog box . . . . . . . . . . . . . . . . . . 175Trace window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165trace (calls), profiling source. . . . . . . . . . . . . . . . . . . 180, 186Trace (emulator mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Trace (E1/E20 Emulator menu) . . . . . . . . . . . . . . . . . . . . 303trace (flat), profiling source. . . . . . . . . . . . . . . . . . . . 180, 186Trace (J-Link menu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305Trace (Simulator menu) . . . . . . . . . . . . . . . . . . . . . . . . . . 302trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306typographic conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

UUnavailable, C-SPY message . . . . . . . . . . . . . . . . . . . . . . . 90__unloadImage(C-SPY system macro) . . . . . . . . . . . . . . . 272Use command line options (debugger option). . . . . . . . . . 295Use devices with deviant instruction register lengths (J-Link debugger option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300Use manual ranges (Memory Access Setup option) . . . . . 156Use ranges based on (Memory Access Setup option) . . . . 156Use 64-bit counter (Performance Analysis option) . . . . . . 193user application, definition of . . . . . . . . . . . . . . . . . . . . . . . 31

VValue (Fill option). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142variables

effects of optimizations . . . . . . . . . . . . . . . . . . . . . . . . . 90information, limitation on . . . . . . . . . . . . . . . . . . . . . . . 90using in C-SPY expressions . . . . . . . . . . . . . . . . . . . . . . 88

variance (interrupt property), definition of . . . . . . . . . . . . 217Variance % (Edit Interrupt option) . . . . . . . . . . . . . . . . . . 226Verify download (debugger option). . . . . . . . . . . . . . . . . . 299

--verify_download (C-SPY command line option) . . . . . . 289version number, of this guide . . . . . . . . . . . . . . . . . . . . . . . . 2Viewing Range dialog box . . . . . . . . . . . . . . . . . . . . . . . . 173Viewing Range (Timeline window context menu) . . . . . . 172visualSTATE, C-SPY plugin module for. . . . . . . . . . . . . . . 32

Wwaiting for device, power consumption during . . . . . . . . . 199warnings icon, in this guide . . . . . . . . . . . . . . . . . . . . . . . . 25Watch window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87web sites, recommended . . . . . . . . . . . . . . . . . . . . . . . . . . . 24while (macro statement) . . . . . . . . . . . . . . . . . . . . . . . . . . 243windows, specific to C-SPY . . . . . . . . . . . . . . . . . . . . . . . . 52Work RAM start address (E1/E20 Hardware Setup) . . . . . . 58Work RAM start address (J-Link Hardware Setup). . . . . . . 62write failure during load . . . . . . . . . . . . . . . . . . . . . . . . . . 306__writeFile (C-SPY system macro) . . . . . . . . . . . . . . . . . 273__writeFileByte (C-SPY system macro) . . . . . . . . . . . . . . 273__writeMemoryByte (C-SPY system macro) . . . . . . . . . . 273__writeMemory8 (C-SPY system macro) . . . . . . . . . . . . . 273__writeMemory16 (C-SPY system macro) . . . . . . . . . . . . 274__writeMemory32 (C-SPY system macro) . . . . . . . . . . . . 274

Zzone

defined in device description file . . . . . . . . . . . . . . . . . 133in C-SPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Zone (Edit Memory Access option) . . . . . . . . . . . . . . . . . 158Zone (Edit SFR option). . . . . . . . . . . . . . . . . . . . . . . . . . . 155Zone (Fill option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Zone (Memory Restore option). . . . . . . . . . . . . . . . . . . . . 141Zone (Memory Save option) . . . . . . . . . . . . . . . . . . . . . . . 140Zone (Memory window context menu) . . . . . . . . . . . . . . . 138Zoom (Timeline window context menu) . . . . . . . . . . . . . . 171

UCSRX-3

319

Page 320: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

Symbols__cancelAllInterrupts (C-SPY system macro) . . . . . . . . . 249__cancelInterrupt (C-SPY system macro). . . . . . . . . . . . . 249__clearBreak (C-SPY system macro) . . . . . . . . . . . . . . . . 249__closeFile (C-SPY system macro) . . . . . . . . . . . . . . . . . 250__delay (C-SPY system macro) . . . . . . . . . . . . . . . . . . . . 250__disableInterrupts (C-SPY system macro) . . . . . . . . . . . 250__driverType (C-SPY system macro) . . . . . . . . . . . . . . . . 251__enableInterrupts (C-SPY system macro) . . . . . . . . . . . . 251__evaluate (C-SPY system macro) . . . . . . . . . . . . . . . . . . 252__fmessage (C-SPY macro statement) . . . . . . . . . . . . . . . 244__isBatchMode (C-SPY system macro) . . . . . . . . . . . . . . 252__loadImage (C-SPY system macro) . . . . . . . . . . . . . . . . 253__memoryRestore (C-SPY system macro) . . . . . . . . . . . . 254__memorySave (C-SPY system macro) . . . . . . . . . . . . . . 254__message (C-SPY macro statement) . . . . . . . . . . . . . . . . 244__openFile (C-SPY system macro). . . . . . . . . . . . . . . . . . 255__orderInterrupt (C-SPY system macro). . . . . . . . . . . . . . 257__popSimulatorInterruptExecutingStack (C-SPYsystem macro). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257__readFile (C-SPY system macro) . . . . . . . . . . . . . . . . . . 258__readFileByte (C-SPY system macro) . . . . . . . . . . . . . . 259__readMemoryByte (C-SPY system macro) . . . . . . . . . . . 259__readMemory8 (C-SPY system macro) . . . . . . . . . . . . . 259__readMemory16 (C-SPY system macro) . . . . . . . . . . . . 259__readMemory32 (C-SPY system macro) . . . . . . . . . . . . 260__registerMacroFile (C-SPY system macro). . . . . . . . . . . 260__resetFile (C-SPY system macro) . . . . . . . . . . . . . . . . . . 261__setCodeBreak (C-SPY system macro). . . . . . . . . . . . . . 261__setDataBreak (C-SPY system macro) . . . . . . . . . . . . . . 263__setLogBreak (C-SPY system macro) . . . . . . . . . . . . . . 264__setSimBreak (C-SPY system macro) . . . . . . . . . . . . . . 266__setTraceStartBreak (C-SPY system macro). . . . . . . . . . 267__setTraceStopBreak (C-SPY system macro). . . . . . . . . . 268__smessage (C-SPY macro statement) . . . . . . . . . . . . . . . 244__sourcePosition (C-SPY system macro) . . . . . . . . . . . . . 269__strFind (C-SPY system macro) . . . . . . . . . . . . . . . . . . . 269__subString (C-SPY system macro) . . . . . . . . . . . . . . . . . 270

__targetDebuggerVersion (C-SPY system macro) . . . . . . 270__toLower (C-SPY system macro) . . . . . . . . . . . . . . . . . . 271__toString (C-SPY system macro) . . . . . . . . . . . . . . . . . . 271__toUpper (C-SPY system macro) . . . . . . . . . . . . . . . . . . 272__unloadImage (C-SPY system macro) . . . . . . . . . . . . . . 272__writeFile (C-SPY system macro) . . . . . . . . . . . . . . . . . 273__writeFileByte (C-SPY system macro) . . . . . . . . . . . . . . 273__writeMemoryByte (C-SPY system macro) . . . . . . . . . . 273__writeMemory8 (C-SPY system macro) . . . . . . . . . . . . . 273__writeMemory16 (C-SPY system macro) . . . . . . . . . . . . 274__writeMemory32 (C-SPY system macro) . . . . . . . . . . . . 274-B (C-SPY command line option). . . . . . . . . . . . . . . . . . . 280-d (C-SPY command line option) . . . . . . . . . . . . . . . . . . . 282-p (C-SPY command line option) . . . . . . . . . . . . . . . . . . . 287--backend (C-SPY command line option) . . . . . . . . . . . . . 281--code_coverage_file (C-SPY command line option) . . . . 281--core (C-SPY command line option) . . . . . . . . . . . . . . . . 281--cycles (C-SPY command line option) . . . . . . . . . . . . . . 282--device_select (C-SPY command line option) . . . . . . . . . 283--disable_interrupts (C-SPY command line option) . . . . . 283--double (C-SPY command line option) . . . . . . . . . . . . . . 283--download_only (C-SPY command line option) . . . . . . . 284--drv_communication (C-SPY command line option). . . . 284--drv_mode (C-SPY command line option) . . . . . . . . . . . 284--endian (C-SPY command line option) . . . . . . . . . . . . . . 285--int (C-SPY command line option) . . . . . . . . . . . . . . . . . 285--ir_length (C-SPY command line option) . . . . . . . . . . . . 286--macro (C-SPY command line option) . . . . . . . . . . . . . . 286--mapu (C-SPY command line option) . . . . . . . . . . . . . . . 287--plugin (C-SPY command line option) . . . . . . . . . . . . . . 287--silent (C-SPY command line option) . . . . . . . . . . . . . . . 288--suppress_download (C-SPY command line option) . . . . 288--timeout (C-SPY command line option) . . . . . . . . . . . . . 289--verify_download (C-SPY command line option) . . . . . . 289

Numerics1x Units (Memory window context menu) . . . . . . . . . . . . 1381x Units (Stack window context menu) . . . . . . . . . . . . . . 149

UCSRX-3

320

Page 321: IAR Embedded Workbenchnetstorage.iar.com/SuppDB/Public/UPDINFO/007248/ew/doc/... · 2013-04-19 · IAR Systems, IAR Embedded Wo rkbench, C-SPY, visualSTATE, The Code to Success, IAR

Index

1x Units (Symbolic Memory window context menu) . . . . 1462x Units (Memory window context menu) . . . . . . . . . . . . 1382x Units (Stack window context menu) . . . . . . . . . . . . . . 1492x Units (Symbolic Memory window context menu) . . . . 1464x Units (Memory window context menu) . . . . . . . . . . . . 1384x Units (Stack window context menu) . . . . . . . . . . . . . . 1494x Units (Symbolic Memory window context menu) . . . . 147

UCSRX-3

321