Quick Start Guide on GNU Tools

This quick-start guide is intended to guide new users of GNU tools to start using the GNU 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

 

  1. Run the tool chain short cut from Windows Start menu.
  2. Create a folder “test” and go to that folder.
  3. 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;
}

  1. Compile the program using the following command line:

    $ rx-elf-gcc hello.c -o hello.out -g

  1. 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
  2. –msim option is valid only for RX and M16C
  3. The above command will generate an executable file called hello.out.
  4. Run the program using rx-elf / sh-elf/m32c-elf /h8300-elf simulator as follows:

    $ rx-elf-run hello.out

  1. Execution of the program will print “Hello World!” string on the console.
  2. Type following command line (Loading will take couple of seconds)

    $ rx-elf-gdb hello.out

 

2) Debug

  1. 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.
  2. From the file menu, select the option “target settings”. A target selection dialog will appear.
  3. From the Target drop down list, select “simulator”. Keep the checkbox, break point at main, checked.
  4. From the Run menu, select “Connect to Target”. A dialog box saying, “Successfully Connected” will appear.
  5. From the View menu select “Console”. This will open the console window, which displays the messages printed by the program.
  6. From the Run Menu, select “Run”. The program will start running and will stop at main, since the breakpoint is set at main.
  7. Now the flow of program is in your control. Press ‘N’ to go to next executable line.
  8. Position the cursor on the variable ret. This should display “ret=14” as a tool tip.
  9. You can then try various menu options such as “Watch Variables”, “Set breakpoint”, etc.
  10. This is how a simple program can be debugged using Insight GDB.
  11. 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.

  1. Add the tool chain path into current path using following command:

    $ export PATH=$PATH:/usr/share/gnuh8_v11.01_elf-1/bin/

  1. Create a folder “test” and go to the folder.
  2. 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;

}

  1. Compile the program using the following command line:
  2. $ rx-elf-gcc hello.c -o hello.out -g
  3. 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
  4. Above command will generate an executable file called hello.out.
  5. Run the program using rx-elf simulator as follows:

    $ rx-elf-run hello.out

  1. Execution of the program will print “Hello World!” string on the console.
  2. To use GDB, follow the steps given below.
  3. Type the following command line:

    $rx-elf-gdb hello.out

The GDB prompt (gdb) will appear on the console.

  1. 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.
  2. 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.
  3. 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.
  4. 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”);

———————————————————-

  1. Press ‘N’ to go to next line. Pressing ‘N’ will print “Hello World!” on console and program will stop at line 7.
  2. Type “disp ret” to view the value of “ret”.
  3. 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:

  1. Set target as a simulator (no hardware available)

(gdb) target sim

  1. Load the hello.out file into the simulator

(gdb) load

  1. Set a break point at main()

(gdb) break main

  1. 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

Support