RZ-G/RZG2 Eclipse develop and debug: Difference between revisions

From Renesas.info
Line 183: Line 183:


== Secondary cores cross developing and debugging ==
== Secondary cores cross developing and debugging ==
The RZ/G2 family includes a secondary, real-time core. The RZ/G2L include a Cortex-M33 whereas RZ/G2E-N-M-H include a Cortex-R7. You can use Eclipse to develop and debug also for these cores. However debugging is a little tricky because the secondary core cannot boot independently rather it relies on the main core to load the firmware and boot. However the idea behind does not change much, you need to setup a development environment for the Cortex-M/R (e.g. arm-none-eabi-gcc ) and use the corresponding GDB to debug (arm-none-eabi-gdb) to connect to OpenOCD port dedicated to the secondary core. You can also develop and debug both main cores and secondary cores, using two Eclipse instances.
The RZ/G2 family includes a secondary, real-time core. The RZ/G2L include a Cortex-M33 whereas RZ/G2E-N-M-H include a Cortex-R7. You can use Eclipse to develop and debug also for these cores. However debugging is a little tricky because the secondary core cannot boot independently, rather it relies on the main core to load the firmware and boot. However the idea behind does not change much, you need to setup a development environment for the Cortex-M/R (e.g. arm-none-eabi-gcc ) and use the corresponding GDB to debug (arm-none-eabi-gdb) to connect to OpenOCD port dedicated to the secondary core. You can also develop and debug both main cores and secondary cores, using two Eclipse instances.


=== Cortex-M33 developing and debugging ===
=== Cortex-M33 developing and debugging ===

Revision as of 08:00, 2 June 2021

Introduction

In this page you'll find instructions on how to use Eclipse to develop, cross-build and debug for RZ/G2. Eclipse is a very well known IDE (Integrated Development Environment) that can be used to develop for different targets, supporting many programming languages.

Installation

There are many guides available online that describe how to install Eclipse on your host Linux machine, normally an x86 PC. For example, if you are using Ubuntu 20.04, you can follow the instructions included on this web page. Do not launch Eclipse after the installation.

Setting up the cross-build environment

Since the goal is to develop for RZ/G2 that are SoCs based on 64-bit Arm Cortex-A cores, you need to install the SDK. For more information on how to build and install the SDK for RZ/G2 you can normally refer to the Release Note of the BSP, the links can be found here. Once the SDK is installed, you have to setup the environment by launching the related script. The default installation path is: /opt/poky/[version] so, for example, in order to setup the environment to cross-build for RZ/G2L:

source /opt/poky/3.1.5/environment-setup-aarch64-poky-linux  

If successful, you should be able to invoke the cross-compiler:

$ $CC --version
aarch64-poky-linux-gcc (GCC) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

and also other tools like GDB. These system environment variables will be used by Eclipse.

Launching Eclipse

We are now ready to launch Eclipse, from the same terminal where you sourced the environment variable script just type:

eclipse &

When you launch Eclipse for the first time, it asks to set-up a workspace, after that you should see a Welcome screen:

Eclipse Welcome page

First Linux cross application: Hello World

In order to create your first Hello World program, click File -> New -> C/C++ Project. Then select "C Managed Build", next, select "Hello World ANSI C Project", give it a name (e.g. Hello World) and select Cross GCC, next, next until the Cross configuration window appears. Then for "Cross compiler prefix" type aarch64-poky-linux- and "Cross compiler path" type /usr/bin.

Eclipse cross.png

If you click finish a new project with the name give will be created. Now in order to get it correctly built, you need to adjust some build settings. Right click on the project, then Properties. When the setting windows pop-up, expand C/C++ Build and select Settings. Then select Miscellaneous under Cross GCC Compiler and add the flag: --sysroot=${SDKTARGETSYSROOT}. Similarly, for Cross GCC Linker: --sysroot=${SDKTARGETSYSROOT}

Eclipse build settings.png

If you now click on the hammer icon on the top left, you should be able to build the project. If successful on the console you will get:

12:04:50 **** Build of configuration Debug for project Hello World ****
make all 
Building file: ../src/Hello World.c
Invoking: Cross GCC Compiler
aarch64-poky-linux-gcc -O0 -g3 -Wall -c -fmessage-length=0 --sysroot=/opt/poky/3.1.5/sysroots/aarch64-poky-linux -MMD -MP -MF"src/Hello World.d" -MT"src/Hello\ World.d" -o "src/Hello World.o" 
"../src/Hello World.c"
Finished building: ../src/Hello World.c

Building target: Hello World
Invoking: Cross GCC Linker
aarch64-poky-linux-gcc --sysroot=/opt/poky/3.1.5/sysroots/aarch64-poky-linux -o "Hello World"  ./src/Hello\ World.o   
Finished building target: Hello World

12:04:50 Build Finished. 0 errors, 0 warnings. (took 168ms)

Cross debugging a Linux application over the network using GDB

Now we are ready to debug. Click Run -> Run Configurations, then select (double click) on C/C++ Remote Application, you can leave the default name or choose what you want.

Eclipse debug hello world.png

Then click "New" button (corresponding to Connection), choose "SSH", then "OK":

Eclipse debug hello world connection.png

Give the connection a name and specify the target IP address. User should be root. There's only one last field to configure in the "Run Configurations": Remove Absolute File Patch for C/C++ Application", click on Browse and leave the default path, then click OK. Please notice that in order to connect and debug openssh and gdbserver must be installed on the target. If you click "Run", the application will be deployed and run on the target board. In the console you should see:

/home/root/Hello\ World;exit

Last login: Tue Jun  1 11:36:17 2021 from 192.168.10.118

root@smarc-rzg2l:~# /home/root/Hello\ World;exit
!!!Hello World!!!
logout

To debug, instead, you have to adjust one more parameter. Select "Debug" from the drop down list (instead on "Run"). Then click on the gear corresponding to "Hello World Debug" (or the name you gave):

Eclipse debug hello world debug.png

Switch to the Debugger Tab and select the cross GDB included in the SDK, aarch64-poky-linux-gdb:

Eclipse debug hello world debug debugger.png

Note: If an error pops up when trying to modify the debug configuration, then you need to add a new "Launch Target". Normally it should not be strictly needed but without at least a target it may not work. At this point you should be able to debug by simply clicking on the "bug" icon, the binary will be downloaded into the target and run under GDB control":

Eclipse debug hello world debug ongoing.png

Cross debugging bare metal programs using GDB and OpenOCD

Eclipse is useful also to debug bare metal programs in combination with OpenOCD. In this section the RZ/G2 Flash Writer is taken as an example.

Cloning a repository using Eclipse

Eclipse includes a plugin for a seamless integration with Git. You can clone and import at the same time. Click File -> Import -> Git -> Projects from Git (with smart import). Then Clone URI, then paste the RZ/G2 Flash Writer GitHub link:

https://github.com/renesas-rz/rzg2_flash_writer

into Location (URI). Then by clicking next, the Branch Selection window appears, select both "master" and "rz_g2l" (default). Then you are prompted to choose a destination folder, choose where the repository will be cloned and click Next. Now we want to import the project using another wizard, so we have to click on "Show other specialized import wizards".

Eclipse import git.png

When the other import wizard window appears, select from the C/C++ category, "Existing Code as Makefile Project" and click Next. Browse to the code location where you cloned the repository, select the folder (Open) and finally select "Cross GCC" before clicking Finish:

Eclipse import git makefile.png

You should now have the project cloned from the repository, on the master branch and imported as a Makefile project.

Building RZ/G2E-N-M-H Flash Writer

The master branch is the branch you want to use to build the Flash Writer for RZ/G2E-N-M-H. Of course you would need to setup the build environment for your target in a similar way as explained above for the RZ/G2L. Assuming you did so, we just have to make sure the correct board is selected during the build. To do so, right click on the project name -> Properties and then select C/C++ Build. Uncheck "Use default build command" and add:

  • BOARD=EK874 for RZ/G2E
  • BOARD=HIHOPE for RZ/G2N-M-H

Eclipse flashwriter board.png

You can now build, you should see the message:

========== !!! Compile Complete !!! ==========

in the Console output.

Building RZ/G2L Flash Writer

To build the RZ/G2L Flash Writer we need to checkout the corresponding branch. Right click on the project -> Team -> Switch To -> Other. Then from the "Remote Tracking" choose the rz_g2l branch, click "Check Out...":

Eclipse flashwriter branch.png


And finally "Check out Commit". A warning about the "Detached HEAD" will appear, you can ignore and click close. Alternatively, and recommended if you want to make changes, you can "Create Branch" window appears, leave it as is and click on "Finish". We need to select the right make command, so right click on the project name -> Properties and then select C/C++ Build. Uncheck "Use default build command" and add/modify BOARD=RZG2L_SMARC. The message

========== !!! Compile Complete !!! ==========

should appear if the build is successful. Do not forget to source the right environment variable setup script according to the board used. Please note that you would need to launch Eclipse from the terminal where the environment variables have been set.

Debugging using OpenOCD - No specific plugin

Please follow the instructions given in this page on how to set-up, build and launch OpenOCD for the RZ/G2 targets. You have to make sure that OpenOCD is running in another terminal window and awaiting for a GDB connection. In the rest of the section the RZ/G2L is taken as an example, however the process is very similar also for the other members of the RZ/G2 family.

You need to create a debug config file specific to the Flash Writer. Right click on the project -> Debug As -> Debug Configurations. Then select GDB Hardware Debugging and create a new launch configuration. The "Main" tab will be automatically populated with the current project and related binary. Switch to the "Debugger" tab and configure it as per below:

Eclipse flashwriter debugging.png

Switch to the "Startup " tab and uncheck "Load image" and "Load symbols" and just add "source gdb_smarc_g2l_flash_writer" as the only initialization command:

Eclipse flashwriter debugging startup.png

The template for this GDB script can be found here, you will have to adjust the paths to your current ones. This is needed because for whatever reason the settings shown in this pane are not actually effective, so the only possibility is to have a separate file that includes all the preliminary GDB startup commands. Please also make sure that the SW1 of the SMARC board is configured as shown in the GDB script.

If everything goes fine you should be able to debug the Flash Writer code in the Eclipse debug perspective:

Eclipse flashwriter debugging connected.png

Debugging using OpenOCD - Dedicated plugin

The procedure explained above is working but it may result a bit tedious. There is a specific OpenOCD plugin but it is not installed by default with Eclipse. In order to install it, go to Help -> Install New Software. Then select "All Available Sites" and in the filter type "openocd" and hit enter.

Eclipse install openocd plugin.png

Select the plugin and install, at the end of the installation process an Eclipse restart is required.

Right click on the project -> Debug As -> Debug Configurations, a new option should be available: "GDB OpenOCD Debugging". Create a new configuration, leave the "Main" tab with the default values and switch to the "Debugger" tab. Here is where you have to configure the link to the OpenOCD executable and the config options, as well as the right GDB executable:

Eclipse openocd plugin debugger.png

Adapt to your own paths. The OpenOCD config options for RZ/G2L are:

-f /home/micbis/repos/openocd/installdir/bin/../share/openocd/scripts/interface/jlink.cfg -c "set SOC G2L" -f /home/micbis/repos/openocd/installdir/bin/../share/openocd/scripts/target/renesas_rz_g2.cfg

Again, the paths have to be adjusted. Do not forget to modify the GDB executable name with the environment variable ${CROSS_COMPILE}. Then switch to the "Startup" tab and configure as per below:

Eclipse openocd plugin startup.png

If everything is set properly by clicking on the "bug" icon, OpenOCD is started automatically, code and symbols loaded automatically and therefore you should end up in being able to debug, similarly to what was shown in the previous section.

Secondary cores cross developing and debugging

The RZ/G2 family includes a secondary, real-time core. The RZ/G2L include a Cortex-M33 whereas RZ/G2E-N-M-H include a Cortex-R7. You can use Eclipse to develop and debug also for these cores. However debugging is a little tricky because the secondary core cannot boot independently, rather it relies on the main core to load the firmware and boot. However the idea behind does not change much, you need to setup a development environment for the Cortex-M/R (e.g. arm-none-eabi-gcc ) and use the corresponding GDB to debug (arm-none-eabi-gdb) to connect to OpenOCD port dedicated to the secondary core. You can also develop and debug both main cores and secondary cores, using two Eclipse instances.

Cortex-M33 developing and debugging

To do.

Cortex-R7 developing and debugging

To do.