Filter results by

Using Eclipse with ARTIK SDK

Once you've installed Eclipse on your Windows® or Linux® development system, you're ready to install and use the ARTIK SDK and other libraries.

This article describes how to cross-compile an application using the Eclipse IDE. You will link your application against the sysroot of the ARTIK target system that includes the ARTIK SDK and other open-source libraries.

The article will guide you through:

  1. Installing the ARTIK SDK package on your ARTIK target system

  2. Creating a sysroot on your development machine that captures the includes and libraries on your ARTIK target sysroot

  3. Using the Eclipse IDE to build a sample ARTIK SDK application, and then to debug and run the application on the ARTIK target.

The locally copied sysroot will be used for cross-compiling your applications in the Eclipse IDE. The mechanism for initially building this sysroot will also be used to keep it in-sync with changes and updates to the ARTIK module distribution on your board.

Managing sysroot

You'll be using the ARTIK SDK and other libraries on your ARTIK board, so we'll need a way to duplicate the sysroot of your ARTIK board on your development system. In this article we'll use rsync, for which you'll find a helpful primer here.

On your target ARTIK board, you will be installing:

  • ARTIK SDK
  • rsync program package

On your development PC, you will be

  • creating sysroot directories to hold copies of the libraries on your ARTIK board
  • writing script files that trigger transfer and update of the remote target files
  • configuring your Eclipse project to indicate to it the location of the sysroot.

Once everything is in place, and you have set up your PC and ARTIK board to share the same Wi-Fi network, you will use rsync with the board IP address to automatically obtain a file list and transfer all files.

In the future you will use the same scripts to perform an update, automatically collecting only those files that have changed.

Install SDK on the ARTIK target

The SDK needs to be installed on the ARTIK target board, along with its development packages containing the headers. The development machine then needs a way to stay in sync with the target board sysroot.

These steps take place on the terminal console of the ARTIK board that will be the target of your development.

  1. Execute
    ifconfig wlan0
    and write down the IP address. It will be called for later as <ARTIK_IP_address>.

  2. Set up access to the SDK repository as described here.

  3. Enter the following command on the ARTIK board to install the needed packages.

    dnf install libartik-sdk-*-devel gdb-gdbserver rsync

Set up synchronization framework

To access the SDK libraries and headers, you first need to extract the root file system (rootfs) of the target and expose it on the development machine. To do so we'll set up a framework for using rsync on both sides.

All of the instructions below take place on your development PC, which is assumed to have rsync installed and available. If in Windows, start by opening an msys bash window.

1. Create a directory and cd into it.
    – Windows: C:\sysroots
    – Linux or Mac: /opt/sysroots

2. Use your text editor to create a sync-sysroot.sh script with the following content. (Under Windows, msys vim sometimes mis-formats; use a Windows editor if needed.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /bin/sh
IP=$1
OUTDIR=$2

if [ -z "$1" ] || [ -z "$2" ]; then
   echo 'Wrong parameters'
   echo 'Usage: sync-sysroot.sh <target IP address> <output directory>'
   exit 1
fi

if [ ! -d "$OUTDIR/usr/include" ]; then
    mkdir -p $OUTDIR/usr/include
fi

if [ ! -d "$OUTDIR/usr/lib" ]; then
    mkdir -p $OUTDIR/usr/lib
fi

if [ ! -L "$OUTDIR/lib" ]; then
   WINOUTDIR=`cygpath -w $OUTDIR`
   cmd //c "mklink /J $WINOUTDIR\lib $WINOUTDIR\usr\lib"
fi

rsync -avu --delete-after --exclude 'lib/firmware' --exclude 'lib/modules' --exclude 'lib/jvm-exports' --exclude 'lib/jvm' --exclude 'lib/node_modules' root@$IP:/usr/lib $OUTDIR/usr/
rsync -avu --delete-after root@$IP:/usr/include $OUTDIR/usr/

For Linux environments only, you'll need to add this additional case before rsync.

1
2
3
if [ ! -L "$OUTDIR/lib" ]; then
    ln -sf usr/lib $OUTDIR/lib
fi

3. Make the script executable.

      chmod +x sync-sysroot.sh

4. Add the development machine as an authorized SSH client to avoid asking for a password during SSH sessions.

     a. First check whether you have an RSA key generated.

	ls ~/.ssh  

	id_rsa id_rsa.pub known_hosts

     b. If don't see id_rsa and id_rsa.pub as shown, you need to generate a key.

	ssh-keygen 

        Don't enter any passphrase when asked. You'll see something like this.


Generating public/private rsa key pair.                               
Enter file in which to save the key (/home/user/.ssh/id_rsa):        
Enter passphrase (empty for no passphrase):                           
Enter same passphrase again:                                          
Your identification has been saved in /home/user/.ssh/id_rsa.        
Your public key has been saved in /home/user/.ssh/id_rsa.pub.        
The key fingerprint is:                                               
SHA256:Lm6q0CFw5Ds6MenB2zKvzNN7tHTdB3aeObBU/zymD2E user@966bb16e176e  
The key's randomart image is:                                         
+---[RSA 2048]----+
|  .              |
| o           .   |
|. o         . .  |
|oo .       = . . |
|=o+     S + *Eo..|
|.*+o o o . o.*.oo|
|+=o.o + .   ..+ .|
|o++. +..     ..  |
| ++++o.       .. |
+----[SHA256]-----+

5. Add the development machine public key to the authorized keys of the target:

ssh-copy-id -i ~/.ssh/id_rsa.pub root@<ARTIK_IP_address>

Note that you'll need to redo this part whenever your ARTIK board IP address changes.

You'll see output similar to that below.


/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/user/.ssh/id_rsa.pub"                           
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed    
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys  
root@<IP address>'s password:                                                                                   

Number of key(s) added: 1                                                                                             

Now try logging into the machine, with: "ssh 'root@xxx.xxx.xxx.xxx'"  
and check to make sure that only the key(s) you wanted were added.

6. Create a sysroot output directory on the development machine. Omit sudo if not needed.

Windows:
sudo mkdir -p /c/sysroots/artik-sysroot
sudo chmod 0777 /c/sysroots/artik-sysroot

Linux or Mac:
sudo mkdir -p /opt/sysroots/artik-sysroot
sudo chmod 0777 /opt/sysroots/artik-sysroot

Synchronize sysroot from the target

With the rsync framework in place, you can now run the synchronization of the development machine sysroot to the files on the ARTIK target.

Windows:
./sync-sysroot.sh <ARTIK_IP_address> /c/sysroots/artik-sysroot

Linux or Mac:
./sync-sysroot.sh <ARTIK_IP_address> /opt/sysroots/artik-sysroot

Repeat the command a few times – the first try will take a while, while subsequent runs will be quicker. You should not see any changes among the subsequent runs.

When to synchronize. The sysroot should be synchronized regularly to make sure the sysroot on the development machine matches exactly with the content of the root file system on the target. In particular, re-run the script after:

  • Installing a new package

  • Running a dnf update command

  • Modifying, adding, or deleting any file under /usr/lib or /usr/include

When to start over. If you get Eclipse build failures due to missing files, first try to resync. If all else fails, remove the sysroot as follows so that you can start fresh.

Windows:
rm -rf /c/sysroots/artik-sysroot/*

Linux or Mac:
rm -rf /opt/sysroots/artik-sysroot/*

When to use another name. If you need to target another board, you should create a new sysroot directory under another name and do a fresh synchronization from the start. It is generally good practice to keep separate sysroots for each board, and change the build parameters to target the one you want to build against.

Creating SDK Project – Windows

We'll start a project using ARTIK SDK example code we already have available. Open a bash window, then type the following commands. Use the workspace directory you chose earlier.

cd /c/Users/user/workspace git clone https://github.com/SamsungARTIK/artik-sdk-examples.git

  1. Create a new Makefile Project with Existing Code.

  2. Select the GPIO example program from the ARTIK SDK samples. Choose a name and Cross GCC as the toolchain.

  3. Right-click on the project to get the contextual menu then click Properties.

  4. Check the Generate Makefiles automatically under the C/C++ Build tab and change the default build command to mingw32-make.exe

  5. In the C/C++ Build => Build Variables menu, select Add to add a SYSROOT variable pointing to C:\sysroots\artik-sysroot and make sure you check Apply to all configurations.

  6. Under C/C++ Build => Environment, edit the PATH to prepend C:\msys64\mingw64\bin; C:\Program Files (x86)\Linaro\gcc-linaro-arm-linux-gnueabihf-4.8-2013.10\bin; to the existing path.

  7. Configure the toolchain as below under the C/C++ build => Settings => Cross Settings menu to add the arm-linux-gnueabihf- prefix.

  8. Add the include paths pointing to the SDK location in the sysroot by clicking on the circled "add" icon:
    ${SYSROOT}\usr\include\artik\systemio
    ${SYSROOT}\usr\include\artik\base

    The GPIO example only requires the base and systemio SDK libraries. For your own projects, add an entry for each SDK library the program needs to be linked against.

  9. Link the artik-sdk-base library to your project by adding the following entries under C/C++ Build => Settings => Cross G++ linker => Librairies.
    artik-sdk-base
    ${SYSROOT}\usr\lib

  10. Add --sysroot=${SYSROOT} to the Linker flags parameter under C/C++ Build => Settings => Cross G++ Linker => Miscellaneous.

  11. Click OK to close the Properties window.

  12. Launch the build by right-clicking on the project then clicking Build project.

The result of the build appears in the console window.

Troubleshooting Tip. If you get build messages saying "cannot find" file xxx, it may be due to rsync issues. Run another sync; it may take several tries to get all file updates. If needed, remove sysroot and start fresh.

Deploy to Target

Here we'll deploy the program to the target and execute it.

  1. Click Run, then Run Configurations.

  2. Add a C/C++ Remote Application and configure it as follows.
    1. Click New button (upper left corner) to create a new remote connection; enter information like that shown.

    2. Select SSH as the connection type. Configure the connection as follows, by changing the IP address to match the IP of the target. If you have not changed the password on the target, the login/password should be root/root.

    3. Apply the new settings. Make sure the newly created connection (e.g. ARTIK 710) is selected under the Connection dropdown list.

  3. Finally click Run. If prompted, accept RSA key exchange and enter the credentials to allow the connection.

If everything goes well, you should see the output of the program running remotely in the Console window.

Debug

You can debug the program as follows.

  1. Create a new build configuration.

  2. Click New.

  3. Enter Debug as the name of the configuration, copy settings from the Default configuration, then click OK.

  4. Set the Debug configuration as active, then click OK.

  5. Edit the project configuration.

  6. Make sure the Debug configuration is selected, then change the optimization level to None (-O0) under C/C++ Build => Settings => Tool Settings => Optimization. Click OK.

  7. Build the project.

  8. Launch the Debug Configurations menu.

  9. Add a new C/C++ Remote Application and configure the parameters as shown below. Make sure you select the Debug output and build.

  10. Under the Debugger tab, add the arm-linux-gnueabihf- prefix to the GDB debugger field. Click Apply then Close to validate the configuration.

  11. Edit the artik_gpio_test.c file and add a breakpoint in the main function by double clicking in the left column in front of the line you want to break at. You should see a blue bubble if the breakpoint was set.

  12. Click the debug icon then gpio-test to launch the debug session.

The debug session should launch and stop in the main function. You can now use the debug commands to run, go step by step, watch variables, etc.

Happy debugging!

Creating SDK Project – Linux

We'll start a project using ARTIK SDK example code we already have available. Type the following commands. Use the workspace directory you chose earlier.

cd /home/user-name/workspace
git clone https://github.com/SamsungARTIK/artik-sdk-examples.git

  1. Create a new Makefile Project with Existing Code.

  2. Select the GPIO example program from the ARTIK SDK samples. Choose a name and Cross GCC as the toolchain.

  3. Right-click on the project to get the contextual menu then click Properties.

  4. Check the Generate Makefiles automatically under the C/C++ Build tab.

  5. Add a SYSROOT variable pointing to /opt/sysroots/artik-sysroot in the C/C++ Build => Build Variables menu. Make sure you check Apply to all configurations.

  6. Configure the toolchain as below under the C/C++ build => Settings => Cross Settings menu. The Path entry should point to the toolchain directory at /opt/toolchains/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabihf/bin/

  7. Add the include paths pointing to the SDK location in the sysroot as follows:

  8. Add an entry for each SDK library the program needs to be linked against. The GPIO example only requires the base and systemio SDK libraries. Link the artik-sdk-base library to your project by adding the entries as shown under C/C++ Build => Settings => Cross G++ linker => Libraries.

  9. Finally add –sysroot=${SYSROOT} to the Linker flags parameter under C/C++ Build => Settings => Cross G++ Linker => Miscellaneous.

  10. When the configuration is done, click OK. Then launch the build by clicking Project => Build All.

The program should build successfully as shown in the console window.

Deploy to Target

Here we'll deploy the program to the target and execute it.

  1. Click Run, then Run Configurations.

  2. Add a C/C++ Remote Application and configure it as follows.
    1. Click New to create a new remote connection

    2. Select SSH as the connection type. Configure the connection by changing the IP address to match the IP of the target as shown. Unless you changed the board login, User and Password should both be root.

    3. Click Finish.

  3. Make sure the newly created connection (e.g. ARTIK 710) is selected under the Connection dropdown list.

  4. Finally, click Run. If prompted, accept RSA key exchange and enter the credentials to allow the connection.

If everything goes well, you should see the output of the program running remotely in the console window.

Debug

You can debug the program as follows.

  1. Create a new build configuration.

  2. Click New.

  3. Enter Debug as the name of the configuration, copy settings from the Default configuration, then click OK.

  4. Set the Debug configuration as active, then click OK.

  5. Edit the project configuration by selecting Properties.

  6. Make sure the Debug configuration is selected, then change the optimization level to None (-O0) under C/C++ Build => Settings => Tool Settings => Optimization. Click OK.

  7. Build the project.

  8. Launch the Debug Configurations menu.

  9. Add a new C/C++ Remote Application.

  10. Configure the parameters as shown below.

  11. Under the Debugger tab, add the arm-linux-gnueabihf- prefix to the GDB debugger field. Click Apply then Close to validate the configuration.

  12. Edit the artik_gpio_test.c file and add a breakpoint in the main function by double clicking in the left column in front of the line you want to break at. You should see a blue bubble if the breakpoint was set.

  13. Click the debug icon then gpio-test Debug to launch the debug session.

The debug session should launch and stop in the main function. You can now use the debug commands to run, go step by step, watch variables, etc.

Happy debugging !

Last updated on: