Home › Service › R8C | Debugger KD30

R8C | Debugger KD30

R8C13 introduction - Where to Buy ? - Your own projects - An initial Report - Debugger KD30 - The R8C service page

 

Using the KD30 debugger

You can compile programs for the R8C/13 as release versions, download them to the microcontroller and run them. However, it’s helpful to use a debugger when you’re developing a program, especially one that’s relatively complex. That allows you to interrupt the program at any desired location, view memory contents, execute instructions one step at a time, and much more.

The microcontroller must always be in debug mode when you use the debugger, which means the ‘Mode’ jumper must be fitted. The Reset button is unnecessary because you use software commands issued by the debugger to start and stop your program.

In the first steps of the following description, we assume you have installed the complete software package as described in the February 2006 issue of Elektor Electronics. Start the KD30 program from the Renesas Tools program group. A start window will appear. The most important settings here are the COM interface and the microcontroller type (R521134.MCU). Select the microcontroller type under ‘Refer…’. You will find the appropriate file for the R8C/13 in the ‘R8C-Tiny Series’ group. If you want to debug via the USB port, select ‘Serial’ (not ‘USB’) and enter the name of the virtual COM port (e.g., ‘COM2’).
 

Connecting to the hardware
 
After you click on ‘OK’, the debugger first downloads some firmware to the microcontroller. That firmware gives KD30 full control over the microcontroller and enables it to download the programs you are working on. You can download a program by selecting a file under File / Download / Load Module. To try this out for yourself, select a file such as timer_interrupt.x30, which is located on the R8C/13 software CD-ROM in the Debug directory of the project with the same name.
 

Source code in the debugger window
 
After you have downloaded your program, you can start it with ‘Go’, stop it with ‘Stop’, or reset it with ‘Reset’. When you run the program, it causes the four LEDs to blink. In a manner of speaking, you are operating the microcontroller under remote control – you don’t have to do anything on the actual board.

Select the ‘BasicWindows / Program Window’ view. There you can select either pure C source code or the mixed display mode, which also shows the assembly language code generated by compiling the C source code.

Generally speaking, your program will run at normal speed when you use the debugger. However, you will see a difference if you use the debugger with a program that uses the internal ring oscillator. The debugger always enables the 20-MHz crystal oscillator, so your program will run a lot faster than expected in that case.

Running KD30 from HEW
 
There’s another treat in store for you. If you run the debugger directly from HEW, KD30 will even notice whether you have modified the project or compiled a new debug version.

To see this for yourself, start HEW using a project such as timer_interrupt from the February issue. Open the Debugger tab under Setup / Customize. Select ‘Other external debugger’ and enter the path to KD30 and the path to the project ‘-load $(CONFIGDIR) $(PROJECTNAME).x30’.
 

KD30 configuration settings
 
If you look in the ‘Tools’ menu, you will see the command ‘Launch External Debugger...’. Select it to start KD30 after first pressing the Reset button on the circuit board. A reset is necessary each time KD30 is launched, because the debugger has to load new firmware.
 

Starting KD30
 
After you start KD30, it will automatically load the current x30 file and the associated source code. You can start, stop and reset your program using the corresponding commands. If the project has been modified, KD30 will ask whether you want to download the modified project.

To try this for yourself, start the timer_interrupt project with the debugger. Then stop it and display the C source code. The current location will be somewhere in the endless loop. Select a line in the interrupt function and click on ‘Break’. You have just set a ‘breakpoint’ where the program is supposed to stop.
 

A breakpoint in the source code
 
Next you can use ‘Step’ to execute the instructions one at a time. In this case you will see how the individual LEDs change states step by step, while at full speed they appear to be switched simultaneously.

Integrating KD30 into HEW

An even more luxurious option is to integrate the debugger into the development environment. However, there’s also a small drawback to this: if you manage to crash the debugger, the development environment will freeze. One way to crash the debugger is to remove the supply voltage from the target system during debugging.

Start a completely new project and name it ‘Debug1’. In Step 5 of the project setup, specify KD30 as the external debugger and ‘M16C R6C FoUSB/UART’ as the target.
 

Debugger configuration
 
Enter a single instruction in the new project (such as ‘while(1)’), compile it in the Debug_ M16C_R6C_FoUSB/UART configuration, and select the session M16C_R6C_FoUSB/UART. KD30 will then start up with a different appearance, because it is now integrated into the HEW user interface. Just as before, you have to specify the microcontroller type and interface. After that, KD30 will download new firmware as before, and it will automatically download the current version of the project after each new compilation. Now you can code and debug to your heart’s content!
 

Development environment user interface with internal debugger

Spotlight

Computer Vision

Learn more about Computer vision, probably the most exciting branch of image processing. With this book the first step is easy!