[JP] Quick Start Guide on Open-Source Tools
This quick-start guide is intended to guide new users of open-source tools to start using the open-source tools for Renesas micros.
Windows Users
1)Compile
The steps given below assume that you are using the rx-elf tool chain. According to the tool-chain you are using , use the appropriate commands.
S.No | Toolchain | |
1 | RX | rx-elf-xxx |
2 | RL78 | rl78-elf-xxx |
3 | H8 | h8300-elf-xxx |
4 | SH | sh-elf-xxx |
5 | M16CM32C | m32c-elf-xxx |
- Run the tool chain short cut from Windows Start menu.
- Create a folder “test” and go to that folder.
- Write a “Hello World!” program in file hello.c.
#include <stdio.h>
int main(void)
{
int ret;
ret = printf(“Hello World!\r\n”);
return ret;
}
- Compile the program using the following command line:
$ rx-elf-gcc hello.c -o hello.out -g
- For “m16c” use -mcpu=m16c option , where “m16c” is the target for which the code is compiled. If you want to compile the code for some other target, then please specify the target name for “-mcpu” option.
For e.g. to compile code for r8c target, give the following command:
$ m32c-elf-gcc -msim -mcpu=r8c hello.c -o hello.out -g - –msim option is valid only for RX and M16C
- The above command will generate an executable file called hello.out.
- Run the program using rx-elf / sh-elf/m32c-elf /h8300-elf simulator as follows:
$ rx-elf-run hello.out
- Execution of the program will print “Hello World!” string on the console.
- Type following command line (Loading will take couple of seconds)
$ rx-elf-gdb hello.out
2) Debug
- After loading, the program cursor will be positioned at line printf. At this point, the GDB would have opened file hello.c in its main window.
- From the file menu, select the option “target settings”. A target selection dialog will appear.
- From the Target drop down list, select “simulator”. Keep the checkbox, break point at main, checked.
- From the Run menu, select “Connect to Target”. A dialog box saying, “Successfully Connected” will appear.
- From the View menu select “Console”. This will open the console window, which displays the messages printed by the program.
- From the Run Menu, select “Run”. The program will start running and will stop at main, since the breakpoint is set at main.
- Now the flow of program is in your control. Press ‘N’ to go to next executable line.
- Position the cursor on the variable ret. This should display “ret=14” as a tool tip.
- You can then try various menu options such as “Watch Variables”, “Set breakpoint”, etc.
- This is how a simple program can be debugged using Insight GDB.
- If you are running the GDB on command line, follow the steps mentioned under the Linux section.
Please refer to the GDB manual for details on various GDB commands and the Insight manual for operational commands.
Linux Users
The steps given below are for rx-elf / Sh-elf / Rx -elf /M16cM32C tool chains. If you are using different tool chain then use appropriate commands.
- Add the tool chain path into current path using following command:
$ export PATH=$PATH:/usr/share/gnuh8_v11.01_elf-1/bin/
- Create a folder “test” and go to the folder.
- Write a “Hello World!” program in file hello.c.
#include <stdio.h>
int main(void)
{
int ret;
ret = printf(“Hello World!\r\n”);
return ret;
}
- Compile the program using the following command line:
- $ rx-elf-gcc hello.c -o hello.out -g
- Where “m16c” is the target for which the code is compiled. If you want to compile the code for some other target, then please specify target name for “-mcpu” option
For e.g. to compile code for r8c target, give the following command:
$ m32c-elf-gcc -msim -mcpu=r8c hello.c -o hello.out -g -msim option is valid only for RX and M16C - Above command will generate an executable file called hello.out.
- Run the program using rx-elf simulator as follows:
$ rx-elf-run hello.out
- Execution of the program will print “Hello World!” string on the console.
- To use GDB, follow the steps given below.
- Type the following command line:
$rx-elf-gdb hello.out
The GDB prompt (gdb) will appear on the console.
- Type the command “target sim” on the prompt. This will connect the gdb to target simulator and “Connected to target simulator” message will appear on the console window.
- Type “load” on the command prompt to load the program in the memory. A message indicating that the program is loaded will appear on the console.
- Type command “b main” on the command prompt to insert a breakpoint at function main. A message “Breakpoint 1 at 0x10fc: file hello.c, line 6 will appear on the console window.
- Type “run” to run the program. The program will stop at line 6 of the hello.c. Following messages will appear on the console.
———————————————————-
Starting program: /home/user/test/hello.out
Breakpoint 1, main () at hello.c:6
6 ret = printf(“Hello World!\r\n”);
———————————————————-
- Press ‘N’ to go to next line. Pressing ‘N’ will print “Hello World!” on console and program will stop at line 7.
- Type “disp ret” to view the value of “ret”.
- This shows how a simple program can be debugged using the GDB. Please refer to the GDB manual for details on various GDB commands.
Below is a summary of the GDB commands and console view:
- Set target as a simulator (no hardware available)
(gdb) target sim
- Load the hello.out file into the simulator
(gdb) load
- Set a break point at main()
(gdb) break main
- Run the code
(gdb) run
You should see the following output on your command line console.
These are for RX target. Other targets have same commands.
D:\>rx-elf-gdb hello.out
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “–host=i386-pc-mingw32msvc –target=rx-elf”.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/
Reading symbols from D:\hello.out…done.
(gdb) target sim
Connected to the simulator.
(gdb) load
(gdb) break main
Breakpoint 1 at 0x100010a: file hello.c, line 6.
(gdb) run
Starting program: D:\hello.out
Breakpoint 1, main () at hello.c:6
6 ret = printf(“Hello World!\r\n”);
(gdb)
Now you can single step through your code
(gdb) step
Run through rest of your code using continue command
(gdb) continue