Personal tools

Building simple C program for VisionSOM-STM32MP1

From SomLabs Wiki

Jump to: navigation, search

Building simple C program for VisionSOM-STM32MP1


This article describes how to build a simple Hello World C application fo the VisionSOM-STM32MP1 module. To do this we need to have the installed toolchain as described in the article OpenSTLinux for VisionSOM-STM32MP1. In this example the toolchain is installed in the /opt/st/stm32mp157a-visionsom-mx/2.6-snapshot directory.

Configuring the environment

The environment configuration script is installed with the toolchain. We need to call it in order to configure required environmental variables:

. /opt/st/stm32mp157a-visionsom-mx/2.6-snapshot/environment-setup-cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi

We can verify it by checking the value of the CC variable:

echo $CC

the example output looks like this:

arm-openstlinux_weston-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/st/stm32mp157a-visionsom-mx/2.6-snapshot/sysroots/cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnuea

This configuration step has to be repeated in each terminal separatelly every time after opening it.

Building the example code

Now we can create a simple program in the HelloWorld.c file:

#include <stdio.h>

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

and compile it using the previously prepared terminal:

$CC -o HelloWorld HelloWorld.c

The created executable can be run only on ARM architecture - it can be verified by calling the command:

file HelloWorld

The output contains the details about the binary:

HelloWorld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.2.0, BuildID[sha1]=0ba619f33a20c2521f445510df799064aa330e2f, with debug_info, not stripped

Now it is time to upload the executable file to the target using ssh or by copying it directly to the SD card and running it from the target terminal:

root@stm32mp157a-visionsom-mx:~# ./HelloWorld 
Hello world!
NXP Partner ST Partner Renesas Partner