Difference between revisions of "DESK-XZ7-L/Development/Hello World example"

From DAVE Developer's Wiki
Jump to: navigation, search
(Created page with "<section begin="History" /> {| style="border-collapse:collapse; " ! colspan="4" style="width:100%; text-align:left" ; border-bottom:solid 2px #ededed" |History |- ! style="bo...")
 
 
Line 6: Line 6:
 
! 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:#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:#ededed; padding:5px; color:#000000" |2023/01/25
+
| 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" |2024/01/29
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |DESK-XZ7-L-1.0.1 release
+
| 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" |DESK-XZ7-L-1.0.1 release
 
|-
 
|-
 
|}
 
|}
Line 16: Line 16:
 
==Hello World example==
 
==Hello World 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.  
+
Here below is an example of 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
 
This example shows how to use the arm cross-compiler using the environment configured for this purpose
Line 23: Line 23:
  
 
* start the Linux development VM and login into the system
 
* start the Linux development VM and login into the system
* install the toolchain, for example for Bora
+
* install the toolchain, for example for [[BORA SOM | BORA]] SOM
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
Line 77: Line 77:
 
</pre>
 
</pre>
  
* invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 64-bit for the target microprocessor
+
* 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">
 
<pre class="workstation-terminal">
 
dvdk@vagrant:~/myproject$ $CC -O hello.c -o hello
 
dvdk@vagrant:~/myproject$ $CC -O hello.c -o hello
Line 86: Line 86:
 
=== Running the example on the target ===
 
=== Running the example on the target ===
  
Now it is enough to copy the object file on target and perform the following command:
+
Now it is enough to copy the object file on target and execute it:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
Line 97: Line 97:
  
 
<section end="Body" />
 
<section end="Body" />
[[Category:BORA]]  
+
 
[[Category:BORA Xpress]]  
+
[[Category:BORA]] [[Category:BORA Xpress]] [[Category:BORA Lite]]
[[Category:BORA Lite]]
 

Latest revision as of 15:24, 29 January 2024

History
Issue Date Notes
2024/01/29 DESK-XZ7-L-1.0.1 release



Hello World example[edit | edit source]

Here below is an example of C code displaying the classic 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[edit | edit source]

  • start the Linux development VM and login into the system
  • install the toolchain, for example for BORA SOM
dvdk@vagrant:~$ wget https://mirror.dave.eu/desk-xz-l/desk-xz7-l-1.0.1/desk-xz7-l-1.0.1_bora_sdk.sh
--2024-01-26 11:57:04--  https://mirror.dave.eu/desk-xz-l/desk-xz7-l-1.0.1/desk-xz7-l-1.0.1_bora_sdk.sh
Resolving mirror.dave.eu (mirror.dave.eu)... 84.46.251.143
Connecting to mirror.dave.eu (mirror.dave.eu)|84.46.251.143|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 998591008 (952M) [text/x-sh]
Saving to: ‘desk-xz7-l-1.0.1_bora_sdk.sh’

desk-xz7-l-1.0.1_bora_sdk.sh                    100%[====================================================================================================>] 952.33M  10.8MB/s    in 1m 40s  

2024-01-26 11:58:43 (9.57 MB/s) - ‘desk-xz7-l-1.0.1_bora_sdk.sh’ saved [998591008/998591008]

dvdk@vagrant:~$ chmod 755 desk-xz7-l-1.0.1_bora_sdk.sh 
dvdk@vagrant:~$ ./desk-xz7-l-1.0.1_bora_sdk.sh 
PetaLinux SDK installer version 2021.2
======================================
Enter target directory for SDK (default: /opt/petalinux/2021.2): 
You are about to install the SDK to "/opt/petalinux/2021.2". Proceed [Y/n]? y
Extracting SDK.......................................................................................................................................................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /opt/petalinux/2021.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi
  • open a terminal window and cd into your source code directory
dvdk@vagrant:~$ mkdir -p ~/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;
}
  • configure the build environment
dvdk@vagrant:~/myproject$ source /opt/petalinux/2021.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi 
  • as you can see here below, the $CC environment variable has been properly configured for using the SDK sysroot parameter:
dvdk@vagrant:~/myproject$ echo $CC                                                                                                                                                                     
arm-xilinx-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/petalinux/2021.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
  • invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 32-bit for the target microprocessor
dvdk@vagrant:~/myproject$ $CC -O hello.c -o hello
dvdk@vagrant:~/myproject$ file hello
hello: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=cd0630d98370eb6b80423fb1b4b1e3411f2f4576, for GNU/Linux 3.2.0, with debug_info, not stripped

Running the example on the target[edit | edit source]

Now it is enough to copy the object file on target and execute it:

...
...
root@bora:~# ./hello
Hello, World!
root@bora:~#