This application note describes how to use Eclipse for building and debugging applications for Emcraft Cortex‑M BSPs.
You will need a Linux version of Eclipse IDE installed on you Linux development host. Go to https://www.eclipse.org/downloads/eclipse-packages/ and select the latest version of Eclipse IDE for C/C++ Developers. At the moment of writing, current version is the "Mars" release. Download and install Eclipse to your host.
Adding a Project to Eclipse
Here is how to create a single file project in Eclipse.
- Start Eclipse and select a workspace directory. The workspace directory is an arbitrary directory, different from the directory where your source file is located.
- Create an empty project, open File -> New -> C Project:
- Enter the name of the project, for example, c-example and click Next.
- On the next screen you will be prompted to choose build configurations. Leave all defaults and click Next to proceed.
- On the next screen, enter arm-uclinuxeabi- as a Cross compiler prefix:
- Click Finish.
- Add your source file to the project, open File -> Import, select File System:
- Click Next, and, using Browse, navigate to the directory with your source file. Select the directory in the left window, this will add its content to the project:
Click Finish.
Creating Build Configuration and Building the Project
Now, we need to instruct Eclipse on how to build the project for the Cortex‑M3/M4 target.
Debugging the Project on the Target
On the host filesystem, the executable binaries are located in the Debug subfolder of the Eclipse workspace directory you selected on start of Eclipse:
[psl@skywanderer myproject]$ ls -l /work/psl/eclipse-workspace2/c-example/Debug
total 144
-rw-rw-r--. 1 psl psl 3426 Apr 21 19:32 app.d
-rw-rw-r--. 1 psl psl 30968 Apr 21 19:32 app.o
-rwxr--r--. 1 psl psl 19096 Apr 21 19:32 c-example
-rwxrwxr-x. 1 psl psl 102107 Apr 21 19:32 c-example.gdb
-rw-rw-r--. 1 psl psl 1063 Apr 21 19:32 makefile
-rw-rw-r--. 1 psl psl 231 Apr 21 19:32 objects.mk
-rw-rw-r--. 1 psl psl 390 Apr 21 19:32 sources.mk
-rw-rw-r--. 1 psl psl 735 Apr 21 19:32 subdir.mk
[psl@skywanderer myproject]$
In the directory above, c-example is the binary for Cortex-M3 target. Make note of the c-example.gdb binary, we will need it for remote debugging.
For remote debugging, you need to deploy the c-example binary to the target. This can be done in several ways:
- Using scp or sftp to copy the binary to the target;
- Using NFS share configured on the host and mounting this share from the target.
We will demonstrate the second method. Suppose we have the Eclipse workspace directory (for example, /work/psl/eclipse-workspace2) exported as NFS share. Let's modify the Linux project to auto-mount this directory via NFS. Add the following lines to etc/rc and rebuild the project:
bash$ cd projects/rootfs
bash$ vi etc/rc
...
sleep 2
mount -o nolock 172.17.0.155:/work/psl/eclipse-workspace2 /mnt
...
After loading the project to the target, you should have your Eclipse workspace directory mounted as /mnt:
/ # df
Filesystem 1K-blocks Used Available Use% Mounted on
172.17.0.155:/work/psl/eclipse-workspace2 2403434912 1829438976 472513056 79% /mnt
/ #
/ # ls -l /mnt/c-example/Debug/
-rw-rw-r-- 1 1001 1001 3426 Apr 21 2017 app.d
-rw-rw-r-- 1 1001 1001 30968 Apr 21 2017 app.o
-rwxr--r-- 1 1001 1001 19096 Apr 21 2017 c-example
-rwxrwxr-x 1 1001 1001 102107 Apr 21 2017 c-example.gdb
-rw-rw-r-- 1 1001 1001 1063 Apr 21 2017 makefile
-rw-rw-r-- 1 1001 1001 231 Apr 21 2017 objects.mk
-rw-rw-r-- 1 1001 1001 390 Apr 21 2017 sources.mk
-rw-rw-r-- 1 1001 1001 735 Apr 21 2017 subdir.mk
/ #
Now, we need to add Debug Configuration to the Eclipse project:
- Open Run -> Debug Configurations:
- Create a new configuration in C/C++ Remote Application by clicking + in the upper left part of the dialogue:
- In the Main tab, change the Using GDB(DSF) Autimatic Remote Debugging Launcher: click to Select other... and choose Manual Remote Debugging Launcher:
- Now, switch to the Debugger tab and change gdb to arm-uclinuxeabi-gdb:
- Select the Connection tab and enter an IP address of you target, and gdbserver connection port:
- Click Apply (don't click on Debug yet!).
Now, we are ready to debug on the target. In the target console window, start gdbserver with you application using the port number your specified above:
/ # gdbserver :1234 /mnt/c-example/Debug/c-example
Process /mnt/linux-dp/Debug/c-example created; pid = 60
Listening on port 1234
Back to the Eclipse, click Debug. You will be asked to switch to the Debug Perspective window, accept it:
Click to enlarge
When started under remote debugger, the program automatically stops at the main() function.
Now you can execute you program with steps, put breakpoints, and examine variables:
Click to enlarge