Hello World
This guide will walkthrough the creation and compilation of a Hello World executable intended to run directly on the phyCORE-AM62x Development Kit running Linux.
Native Compilation (On the Target)
Target Image Setup
By default, the BSP-Yocto-Ampliphy-AM62x-PD24.1.0 phytec-qt6demo-image doesn’t include build tools such as gcc, make, git, etc. In order to build your applications on the target natively, these packages will have to be added to your target image first.
First, complete the setup steps outlined in the Build the BSP guide.
Once setup, modify your $BUILDDIR/conf/local.conf:
vi $BUILDDIR/conf/local.conf
Add the following line to the end of the file:
$BUILDDIR/conf/local.conf
IMAGE_INSTALL:append = " packagegroup-core-buildessential"
Now rebuild your target image and then use it to boot your phyCORE-AM62x Development Kit into Linux.
host:~$ bitbake phytec-qt6demo-image
Write your HelloWorld Code
Let’s make a project directory to contain the Hello World source code:
phyboard-lyra-am62xx-3:~# mkdir ~/helloworld-project
phyboard-lyra-am62xx-3:~# cd ~/helloworld-project
Create the main Hello World application source code file using your favorite text editor, this guide will leverage ‘vi’ but ‘nano’ is a more beginner friendly option:
phyboard-lyra-am62xx-3:~# vi helloworld.c
Note
The vi text editor begins in “Command Mode” and you must first hit the ‘i’ key in order to enter “Insert Mode”. Using the arrow keys to navigate, make the necessary changes and then hit ESC to go back to “Command mode”. Now enter “:wq” to write the file and quit.
Pro Tip: Use the right click on your mouse to paste! This will only work if you are in “Insert Mode” first.
Edit the contents of the file to reflect the following and remember to save your changes when you are done!
#include <stdio.h>
int main()
{
printf("Hello World!\n");
}
Compile the project.
phyboard-lyra-am62xx-3:~# gcc -O helloworld.c -o helloworld
Run the binary:
phyboard-lyra-am62xx-3:~# ./helloworld
You should see the following output:
phyboard-lyra-am62xx-3:~# ./helloworld
Hello World!
Cross-Compilation (On a Linux Host Machine)
Once you follow the Build the BSP guide to help you build a SDK installer (or install a pre-built one), and then run through the Install The SDK guide to install it and then source it, you can leverage the computing resources and development tools available to your Linux Host Machine to compile applications intended to run on the phyCORE-AM62x Development Kit.
Basically, you can create the helloworld.c file using the same steps above using your Linux Host Machine’s Terminal and then use the cross-compilation toolchain to compile your application to run on a different architecture (in this case it would be the ARM architecture):
$CC -O helloworld.c -o helloworld
Once built, you can confirm the target architecture the binary is intended for using the ‘file’ utility:
host:~$ file helloworld
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=71f34ddf90d981cb429087646d6b39c629dec800, for GNU/Linux 3.7.0, with debug_info, not stripped
You’ll notice errors if you try to run this binary on the Host Machine. Check out the Copying Files to the Device Guide to help you transfer it to the phyCORE-AM62x Development Kit such that you can execute it.