Personal tools

How to write your first C program for Vision-SOM6ULL on the target board, Linux host and Windows host

From SomLabs Wiki

Revision as of 22:11, 6 November 2017 by Admin (talk | contribs) (Created page with "{{PageHeader|How to write your first C program for Vision-SOM6ULL on the target board, Linux host and Windows host}} == Writing program on target system == One of few ways to...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to write your first C program for Vision-SOM6ULL on the target board, Linux host and Windows host


Writing program on target system

One of few ways to create applications is to connect to target board via UART-USB converter or SSH client, use a text editor (for example nano) to write code and compile them with gcc. To do that install compiler and some additional software:

root@somlabs:~# apt install build-essential

Now create your program file with nano editor:

root@somlabs:~# nano HelloWorld.c

Enter the code below to the file:

#include <stdio.h>

int main() {
        printf("Hello world!\n");
        return 0;
}

Save the file (Ctrl+O) and exit (Ctrl+X). Now you can compile and run your program:

root@somlabs:~# gcc -o HelloWorld HelloWorld.c
root@somlabs:~# ./HelloWorld
Hello world!
root@somlabs:~#

Writing program on Linux host

Other method is to write your application on host system. In this case Ubuntu 16.04 will be used. You need to install qemu-arm-static package on your host:

jz@ubuntu:~$ sudo apt install qemu-user-static

Download rootfs image to your host and extract it:

jz@ubuntu:~$ wget http://somlabs.com/os_images/somlabs-visionsom-6ull-debian-rootfs-qemu.tar.xz
jz@ubuntu:~$ sudo tar xf somlabs-visionsom-6ull-debian-rootfs-qemu.tar.xz

Enter into chrooted ARM debian envionment using command:

jz@ubuntu:~$ sudo ./somlabs-debian/chtoolchain

Now you are ready to create basic application on your host, first steps are just like in case of development on target, but you need to perform them on your host: Create your program file with nano editor:

jz@ubuntu:~$ nano HelloWorld.c

Enter the code below to the file:

#include <stdio.h>

int main() {
        printf("Hello world!\n");
        return 0;
}

Save the file (Ctrl+O) and exit (Ctrl+X). Now you can compile and run your program:

jz@ubuntu:~$ gcc -o HelloWorld HelloWorld.c

Now it is time to upload executable file to the target (you need to find it's IP before, for example by running ip a command on target):

jz@ubuntu:~$ scp HelloWorld2 root@192.168.0.53:/root

Now your executable should be in /root directory of the target system, you can run it (enter the command below on target):

root@somlabs:~# ./HelloWorld
Hello world!
root@somlabs:~#

Writing program on Windows host

Writing program on Windows host using virtual machine

To develop application on Linux virtual machine hosted by Windows system you can use for example VirtualBox or VMWare Workstation Player. There are many tutorials on installing Ubuntu on these virtual machines on the Internet. For next steps look at Writing program on Linux host section above.

Writing program on Windows host using Windows Subsystem for Linux

To develop application on Windows using Windows Subsystem for Linux check Microsoft installation tutorial. After installation you can run Ubuntu bash on Windows - press Win key to open Windows start menu and search for Bash on Ubuntu on Windows, once you run it you can refer to Writing program on Linux host section above.

NXP Partner ST Partner Renesas Partner