Steps to Use .NET on the Forlinx OKMX6UL Series Development Board (Linux4.1.15)

In this era of everything interconnected, embedded development is becoming increasingly popular. .NET, a powerful and cross-platform development framework introduced by Microsoft, is gradually making its mark in the embedded field as well.

So how to use.NET on Forlinx OKMX6UL series development board to make your embedded development journey more colorful!

1. Scope and Preparation

This article primarily targets the Folinx OKMX6UL series development boards, with Linux4.1.15. Other platforms can also refer to this it, but may need to make appropriate adjustments according to the actual circumstances.

2. .NET Installation

(1) Download the .NET compressed package from the official website.

https://dotnet.microsoft.com/en-us/download/dotnet/6.0

For 32-bit processors, please download the arm32 compressed package;

For 64-bit processors, please download the arm64 compressed package;

Note: The following instructions are based on .NET V6.0.415 as an example.

(2) Extract the Compressed Package

Extract the compressed package to the root user directory

mkdir /home/root/.dotnet
tar -xvf dotnet-sdk-6.0.415-linux-arm.tar.gz -C /home/root/.dotnet

After decompression, the following file is obtained.

root@fl-imx6ull:~# ls .dotnet/
LICENSE.txt            dotnet                 packs                  sdk-manifests          templates
ThirdPartyNotices.txt  host                   sdk                    shared

(3) Configure Environment Variables

To make the system recognize the .NET commands,please configure the environment variables.

vi /etc/profile

Add:

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools

Re-run/etc/profile to validate the environment variable

root@fl-imx6ull:~# source /etc/profile

Check environment variables

root@fl-imx6ull:~# export
export DOTNET_ROOT="/home/root/.dotnet"
......
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/root/.dotnet:/home/root/.dotnet/tools"
......

3. .NET Usage in Practice

Check the Version

First, you can view the version of .NET and related information by using the command dotnet --info.

root@fl-imx6ull:~# dotnet --info 
.NET SDK (reflecting any global.json):
 Version:   6.0.415
 Commit:    6963d2d1e0
Runtime Environment:
 OS Name:     Linux
 OS Version:  
 OS Platform: Linux
 RID:         linux-arm
 Base Path:   /home/root/.dotnet/sdk/6.0.415/
global.json file:
  Not found
Host:
  Version:      6.0.23
  Architecture: arm
  Commit:       e0f0de876a
.NET SDKs installed:
  6.0.415 [/home/root/.dotnet/sdk]
.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.23 [/home/root/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.23 [/home/root/.dotnet/shared/Microsoft.NETCore.App]
Download .NET:
  https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

First Test Application

Create a.NET project

root@fl-imx6ull:~# dotnet new console -o sample1
The template "Console App" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on /home/root/sample1/sample1.csproj...
  Determining projects to restore...
  Restored /home/root/sample1/sample1.csproj (in 1.81 sec).
Restore succeeded.

You can see the following files under the sample 1 path.

root@fl-imx6ull:~# ls sample1/
Program.cs      obj             sample1.csproj

Among them, the source code is stored in the Program. CS.

root@fl-imx6ull:~/sample1# cat Program.cs 
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

This part is written in C.

Running

root@fl-imx6ull:~# cd sample1/
root@fl-imx6ull:~/sample1# dotnet run
Hello, World!

Compile the Application

Create a project

root@fl-imx6ull:~# dotnet new console -o sample1

Compilation

root@fl-imx6ull:~/sample1# dotnet build
MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  sample1 -> /home/root/sample1/bin/Debug/net6.0/sample1.dll
Build succeeded.
    0 Warning(s)
    0 Error(s)
Time Elapsed 00:00:27.31

Generate after compilation

bin/Debug/net6.0/sample1

Execute the file

root@fl-imx6ull:~/sample1# ./bin/Debug/net6.0/sample1 
Hello, World!

Note: .NET uses libgpiod for GPIO operations, so if want to manipulate the GPIO on the board using .NET, ensure that the kernel version supports gpiod.

4. Considerations and Limitations

While .NET can run on the OKMX6UL series development boards, there are some limitations to be aware of:

Performance Issues: Due to the lower CPU frequency (528MHz) on the OKMX6UL-C, .NET cannot run smoothly. OKMX6ULL-S and OKMX6ULL-C, with slightly higher frequencies (792MHz), can only barely run .NET. If high performance is required, consider using a more powerful development board.

Kernel Version Issues: OKMX6ULL series uses Linux 4.1.15, which may prevent the use of some high-version kernel interfaces in .NET, such as libgpiod. If need to use these interfaces, consider upgrading the kernel or finding alternative solutions.

Combining OKMX6UL series development boards with .NET provides embedded developers with a new exploration platform. It can make full use of the cross-platform advantages and powerful functions of.NET to develop unique embedded applications.