News from our smart team...

Hello World program for the i.MX53 board

Mar 31, 2014

Assuming you’ve configured your environment correctly (you’ve installed eclipse, its plugins, the toolchain and the sysroot on the development machine; on the target machine booted the filesystem successfully), creating an application is as easy as the following steps:

  1. Open Eclipse, on the menubar, click on “File” -> “New” -> “Project…”;

  2. select “C Project”, click on “Next”;

New Project align-middle

  1. type a name for your new project;

  2. expand the “Yocto Project ADT Project” folder;

  3. here you could select “Empty Project” if you wish, but let’s select “Hello World ANSI C Autotools Project”, this way Eclipse creates an Autotools project and its files and folders preconfigured. Click on “Next”;

C Project align-middle

  1. here you can set more information about the project, like: “Author”, “Copyright notice”, “Hello world greeting”, the “Source” folder and the “License”;

  2. Fill them as you wish and click “Finish”.

Basic Settings align-middle

At this point your project was created. Let’s make sure that the Yocto configuration was set right:

  1. On the menubar, click on “Project”, “Change Yocto Project Settings”;

  2. here you can check the “Toolchain” and “Sysroot” locations and the “Target architecture” as well. Change them if needed or just close the window if everything is right.

Project Settings align-middle

Now that your project is set up, lets build it:

  1. On the menubar, click on “Project”, “Reconfigure Project”. You don’t have to do this every time you build it, but only when a project configuration is changed;

  2. on the menubar, click on “Project”, “Build Project”.

Build align-middle

Your application binary is already created!

Now it’s time to test it. For the following steps, you need to setup the target device. This includes: boot the corresponding filesystem on it, have a network connection between the target device and the development machine and have started the TCF agent on the target device.

If the description above sounds simplified, it’s because it’s simple! The filesystem to be booted on the device is provided along with the toolchain and the sysroot. For the i.MX53, on the development machine you just have to do a binary copy of the filesystem to a SD card, plug the SD card on the board and power it on. To setup a valid network configuration, you can do it with a simple command (ex.: ifconfig eth0 10.9.0.1) and to start the TCF agent a single command as well (/etc/init.d/tcf-agent start).

After the device have been set up, let’s test and debug your application:

  1. On the menubar, click on “Run”, “Debug configurations”;

  2. on the left area, expand “C/C++ Remote Application”;

  3. locate your project to bring the view of the Debug configurations on the right area;

  4. at the right side of the “Connection” field, click on “New” to create a new connection with the target device;

  5. select “TCF” which means Target Communication Framework, click on “Next”;

  6. fill the IP address of the target device, the name of the connection and a description if desired. Click on “Finish” to create the connection;

  7. at the “Connection” field, select the just created connection;

  8. fill in a remote absolute path for your application, click on “Apply”;

  9. click on “Debug”;

Debug Config align-middle

  1. a login screen will be shown, fill with the target device credentials, click “OK”;

Login align-middle

  1. accept the debug perspective when prompted;

  2. Your application is now running in Debug mode! Press F8 to resume it and complete the execution.

Debug Run align-middle

After the application finished its first run, lets add a segmentation fault on the code to see what happens:

  1. Add the following lines between the “includes” and the “main” function:
1
2
3
   struct segfault {
     int field;
   };
  1. add the following lines inside the “main” function:
1
2
  struct segfault *s = NULL;
  int dummy = s->field;
  1. on the menubar, click on “Project”, “Build Project”;

  2. on the menubar, click on “Run”, “Debug Configurations”

  3. click on “Debug”.

Segmentation Fault Run align-middle

Now you can use the Eclipse IDE with all of its features to debug your application. That’s it, these are the basics to start with the O.S. SDK. Happy coding!