Changes

Jump to: navigation, search

DESK-MX6UL-L/Development/Hello word example

5,310 bytes added, 15:13, 2 July 2021
Created page with "{{subst:HelloWorld | nome-som=AXEL ULite | kit-code=MX6UL}}"
<section begin=History/>
{| style="border-collapse:collapse; "
!colspan="4" style="width:100%; text-align:left"; border-bottom:solid 2px #ededed"|History
|-
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Version
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Issue Date
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
|-
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|X.Y.Z
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Month Year
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|TBD
|-
|-
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|[TBD_link X.Y.Z]
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Month Year
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|TBD
|-
|}
<section end=History/>
__FORCETOC__
<section begin=Body/>

==Hello word example==

Here below an example on C code displaying the classic [https://en.wikipedia.org/wiki/%22Hello,_World!%22_program Hello World!] message on the target serial console.

This example shows how to use the arm cross-compiler using the environment configured for this purpose

=== Setting the cross-compiler ===
It is assumed that the development environment has been set up properly as described [[DESK-MX6-L#Quick_start_guide|here]].
* start the Linux development VM and login into the system
* open a terminal window and ''cd'' into your source code directory

<pre class="workstation-terminal">
dvdk@vagrant:~$ mkdir myproject
dvdk@vagrant:~$ cd myproject/
dvdk@vagrant:~/myproject$ vi hello.c
dvdk@vagrant:~/myproject$ cat hello.c
#include <stdio.h>

int main(){
printf("Hello, World!\n");
return 0;
}
</pre>

* configure the build environment
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ source /home/dvdk/desk-mx-l/desk-mx6-l-1.0.0_env.sh
</pre>

* as you can see here below, the <code>$CC</code> environment variable has been properly configured for using the SDK <code>sysroot</code> parameter:
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ echo $CC
arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/home/dvdk/desk-mx-l/sdk/desk-mx6-l-1.0.0-toolchain/sysroots/cortexa9hf-neon-poky-linux-gnueabi
dvdk@vagrant:~/myproject$
</pre>

* invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 32-bit for the target microprocessor
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ $CC hello.c -o hello
dvdk@vagrant:~/myproject$ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=212bc8245d6274bb4ed675b71128b0e835870fab, not stripped
dvdk@vagrant:~/myproject$
</pre>

=== Running the example on the target ===

Now it is enough to copy the object file in the <code>/home/root</code> rfs directory and [[AXEL ULite/MX6UL/General/Booting_from_NFS | boot from nfs...]]

<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ sudo cp hello /home/dvdk/desk-mx-l/rfs/desk-mx6-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx6-l/home/root/
total 32
drwx------ 2 root root 4096 Jun 8 12:36 .
drwxr-xr-x 3 root root 4096 Jan 28 23:54 ..
-rwxr-xr-x 1 root root 16432 Jun 8 12:36 hello
-rw-r--r-- 1 root root 1011 Nov 25 2020 .profile
dvdk@vagrant:~/myproject$
</pre>

on the target:

<pre>
...
...
...
[ OK ] Started Terminate Psplash Boot Screen.
[ OK ] Started /etc/rc.local Compatibility.
Starting Hostname Service...
Starting WPA supplicant...
[ OK ] Started Serial Getty on ttymxc2.
[ OK ] Started Getty on tty1.
[ OK ] Started WPA supplicant.
[ OK ] Started Hostname Service.

NXP i.MX Release Distro 4.14-sumo desk-mx6 ttymxc2

desk-mx6 login: root
root@desk-mx6:~# ls -la
total 32
drwx------ 2 root root 4096 Jun 8 2021 .
drwxr-xr-x 3 root root 4096 Jan 28 2021 ..
-rw-r--r-- 1 root root 1011 Nov 25 2020 .profile
-rwxr-xr-x 1 root root 16432 Jun 8 2021 hello
root@desk-mx6:~# ./hello
Hello, World!
root@desk-mx6:~#
</pre>


----

[[Category:AXEL ULite]]
8,226
edits

Navigation menu