My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
AIoT with RT-Thread RTOS — 1 Dev Env

AIoT with RT-Thread RTOS — 1 Dev Env

Abby's photo
Abby
·Apr 21, 2020

The combination of AI and IoT brings the AIoT, but how RTOS can connect with AIOT? A passage from RT-Thread community member PinXue, listening to his opinions of AIoT with RT-Thread on Dev Env.

RT-Thread is an open-source RTOS, powers millions of devices. It is way far simple and easy to hands-on than generic OS like Linux.

11.png

First, we need setup the environment for RT-Thread development. It is most simple way to use the development environment in docker.

TLDR version

  • macOS/Linux:
docker pull pinxue/rt-env:clang6_opt_gcc
docker run --name rtenv --rm -it --privileged -p 8181:8181 \
  -v `pwd`/../rt-thread:/home/rtt/rt-thread \
  pinxue/rtenv:clang6_opt_gcc \
  bash
  • Windows
docker pull pinxue/rt-env:clang6_opt_gcc
docker run --name rtenv --rm -it --privileged -p 8181:8181 -v %~dp0rt-thread:/home/rtt/rt-thread pinxue/rtenv:clang6_opt_gcc bash

Get the docker If you have not installed docker-ce, install it. Download the installer from (hub.docker.com/search?q=&type=edition&a..)

PS. You may change image dir of docker-ce if your system disk space is tight, check preference:

12.png

Get the image

There are three ways to get the image: pull or load or build

  • Pull:

It is preferred way, just one command: docker pull pinxue/rt-env:clang6_opt_gcc

Type the command in CMD window or Terminal.

  • Load: If some friends around you have already pulled or built the image, they can save the image as a tarball and share with you. It is handy if docker pull is slow or your team made some customizations.

The save script can be found here: github.com/pinxue/rtenv-in-docker/blob/mast.. Put rtenvd.tar.gz saved along with load.bat, run load.bat (sh load.bat for macOS/Linux)

The load script: github.com/pinxue/rtenv-in-docker/blob/mast..

Windows: well, I didn’t build in that OS, yet. The command docker build ... are just same, build.bat script to be created...

There is an optional ‘xgfw’ argument, it speeds up a lot if you have trouble with GFW (just ignore it if you don’t know what’s GFW)

Ready To Go

Now we have the image, next step is docker run to create a container. As an development environment in docker, it comes with tools like compiler, linker, debugger, emulator, analyzer, etc. And those tools need access the source code of our project to do their work, there are ways to bridge them together.

We will use docker volume to map local files into container, so that development tools can access those files as they are a part of the container, while we still may use any favorite editor/IDE/flashing tool on host system (your macOS/Windows/Linux running the docker engine) to modify source code or get binary built. Be aware there are other ways. We may run into a container and git clone the source code into that container, or we create another container to keep source project and link into this tool container. Both require a little more understanding on docker container and file system.

There are already a run_in.bat for Windows and a run_in.sh for macOS/Linux created for the convenience. It is highly suggested to clone or download github.com/pinxue/rtenv-in-docker even if you don’t plan to build the docker image, those companion scripts are helpful. These scripts have assumption about where is the source code files:

  • Windows: .\rt-thread

  • macOS: ../rt-thread

Fell free to edit the scripts if you don’t like the folder layout.

An example of running the run_in script in terminal :

10:docker pinxue$ ./run_in.sh
Using default toolchain in docker (/opt/gcc/gcc-arm-none-eabi-5_4)
To change toolchain in ./gcc/gcc-arm-none-eabi-6_2-2016q4 :
  ./run_in.sh -v `pwd`/../docker/gcc:/opt/gcc -e RTT_EXEC_PATH=/opt/gcc/gcc-arm-none-eabi-6_2-2016q4/bin
Now you are in docker.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
rtt@51e0a1bed219:~$

PS, double-clicking the run_in.bat in Windows Explorer works as well as call it in a cmd window.

PPS, type exit then press enter, in case you don’t know how to quit the docker container.

Get RT-Thread Source Code

The way recommended is to run_in docker, then git clone github.com/RT-Thread/rt-thread.git

In this way, we need not worry about installing git on the host system. As a developer, you must know it well to use git, for example --depth 1 to save time and disk space.

But feel free to download zip archive from Github or any way proper, just remember to decompress and put into the right place (mentioned above already).

In the docker container, there are a few scripts to save some keyboard typing. In container, cat README.md for details. Here is an example of building qemu-vexpress-a9 bsp:

rtt@5d77da97ae45:~$ source qemu_a9.sh
rtt@5d77da97ae45:~/rt-thread/bsp/qemu-vexpress-a9$ scons -j2
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
CC build/applications/lcd_init.o
CC build/applications/mnt.o
...
arm-none-eabi-objcopy -O binary rtthread.elf rtthread.bin
arm-none-eabi-size rtthread.elf
   text    data     bss     dec     hex filename
 595273    5284   85276  685833   a7709 rtthread.elf
scons: done building targets.
rtt@5d77da97ae45:~/rt-thread/bsp/qemu-vexpress-a9$ ./qemu.sh
WARNING: Image format was not specified for 'sd.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
VNC server running on 127.0.0.1:5900
\ | /
- RT -     Thread Operating System
 / | \     4.0.3 build Apr  1 2020
 2006 - 2020 Copyright by rt-thread team
lwIP-2.0.2 initialized!
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/utest] utest is initialize success.
[I/utest] total utest testcase num: (0)
[I/SDIO] SD card capacity 65536 KB.
[I/SDIO] switching card to high speed failed!
hello rt-thread
msh />

We just build and run RT-Thread in QEMU emulator!

(In case you don’t know how to quit the QEMU: Ctrl-C to quit QEMU or run exec_in .sh in new terminal to get into the container and killall qemu-system-arm)

Run with other toolchian

In fact run_in .sh already prompt you how to do!

Gcc for arm-none-eabi is built-in, but it will be too huge to download if we bundle all possible toolchain into the docker image. It is quite easy to re-use this rtenv in docker with different toolchian. Let’s take aarch64 toolchain as an example. Just download and expand into gcc dir (gcc is just a dir name, feel free to put anything into it.) There is a script in ./gcc for fetching arm and aarch64 toolchain, in case you don’t know where to download.

Now we are ready to run ./run_in .sh -v pwd/gcc:/opt/gcc -e RTT_EXEC_PATH=/opt/gcc/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-elf/bin

Which is exactly aa64_run_in .sh done for us.

Now we have the tool, ready for hacking!