RT-Thread Smart Getting Started Guide~

RT-Thread Smart (referred to as rt-smart) is a new branch derived from the RT-Thread operating system. It is aimed at chips with MMU and high-end applications, such as ARM Cortex-A series chips, MIPS chips, and RISC-V chips with MMU Wait. rt-smart enables an independent and complete process based on the RT-Thread operating system, while executing in a hybrid microkernel mode.

The rt-smart.zip software package is a user experience software package for RT-Thread Smart, which can be executed on the VExpress-A9 machine emulated by QEMU or on the Raspberry Pi 4B development board. This document is for QEMU, Raspberry Pi 4B development board to quickly get started rt-smart getting started guide document.

Package description


Download the rt-smart software package

You can download the rt-smart software package at the following link, the file name is rt-smart-20201125.zip:

https://realthread.cowtransfer.com/s/1c2b64ba968748

Decompress it, assuming that the decompressed directory name is rt-smart, and rt-smart is used to represent this directory name in the following. The related main directories and descriptions are shown in the following figure:

Prepare the tool chain

For Linux and Windows environments, you need to download the corresponding arm-linux-musleabi tool chain. If it is the rt-smart software package, the tool chain in the Linux environment is included.

● Linux version tool chain: install_arm-linux-musleabi_for_x86_64-pc-linux-gnu.tar

● Windows version tool chain: install_arm-linux-musleabi_for_i686-w64-mingw32

Toolchain download link:

https://realthread.cowtransfer.com/s/1c2b64ba968748

Please download and use the right tool chain according to your own development environment.

After downloading, unzip and expand to the `rt-smart/tools/gnu_gcc` directory. The environment variables set by smart-env.bat/sh in the rt-smart directory, where the toolchain path points to this directory.

Compile under Linux and execute on QEMU simulation environment

Under Linux system, some basic environment needs to be installed before compiling rt-smart. This document is based on the Ubuntu16.04 system environment operation, other Linux versions are similar.

Install the compilation environment

First install other tools and software packages that are needed during compilation. You can install them through the following commands:

1sudo apt-get update
2sudo apt-get install vim scons git bzip2 net-tools
3sudo apt-get install python-all python-all-dev
4sudo apt-get install qemu-system-arm qemu-system-common qemu-utils

The above command will install some basic system tools, python environment, scons, qemu tools, etc.

Compile the application

 1# 进入到rt-smart目录
 2cd rt-smart
 3
 4# 设置对应的环境变量,和原RT-Thread相比,多了RTT_CC_PREFIX环境变量
 5source smart-env.sh
 6
 7# 编译用户态程序
 8cd userapps
 9scons
10
11scons: Reading SConscript files ...
12scons: done reading SConscript files.
13scons: Building targets ...
14CC build/hello/main.o
15CC build/ping/main.o
16CC build/pong/main.o
17CC build/vi/optparse-v1.0.0/optparse.o
18CC build/vi/vi.o
19CC build/vi/vi_utils.o
20CC build/webclient/main.o
21LINK root/bin/hello.elf
22LINK root/bin/ping.elf
23LINK root/bin/pong.elf
24LINK root/bin/vi.elf
25LINK root/bin/webclient.elf
26scons: done building targets.

After the compilation is successful, the applications under `userapps/apps` will be compiled into individual elf executable files and placed in the `userapps/root/bin` directory, which can be converted into romfs and C language arrays. The rt-smart kernel is used, so that it can be executed directly without relying on other file systems. To generate romfs and C language arrays, you can use the following command line:

1cd userapps
2python ../tools/mkromfs.py root ../kernel/bsp/qemu-vexpress-a9/applications/romfs.c

Compile rt-smart kernel

 1cd rt-smart/kernel/bsp/qemu-vexpress-a9
 2scons
 3... ...
 4CC build/kernel/src/thread.o
 5CC build/kernel/src/timer.o
 6LINK rtthread.elf
 7arm-linux-musleabi-objcopy -O binary rtthread.elf rtthread.bin
 8arm-linux-musleabi-size rtthread.elf
 9   text    data     bss     dec     hex filename
101219480   40652  122444 1382576  1518b0 rtthread.elf
11scons: done building targets.

If the compilation is correct, the rtthread.elf kernel file will be generated.

Simulation execution

Run directly through the vexpress-a9 development board simulated by qemu:

 1cd rt-smart/kernel/bsp/qemu-vexpress-a9
 2./qemu-nographic.sh
 3
 4 \ | /
 5- RT -     Thread Smart Operating System
 6 / | \     5.0.0 build Nov 15 2020
 7 2006 - 2020 Copyright by rt-thread team
 8lwIP-2.0.2 initialized!
 9try to allocate fb... | w - 640, h - 480 | done!
10fb => 0x61100000
11[I/sal.skt] Socket Abstraction Layer initialize success.
12[I/SDIO] SD card capacity 65536 KB.
13Dir /mnt mount failed!
14hello rt-thread
15msh />
16msh />/bin/hello.elf
17msh />hello world!

The way to exit qemu: "Ctrl+A, X". We also ran the compiled application `/bin/hello.elf` above, and saw it output `hello world!`.

When executed for the first time, it will output `Dir /mnt mount failed!`. This is because at the beginning of execution, the qemu script will generate an empty sd.bin file as an SD card for vexpress-a9. So in the first execution, sd0 needs to be formatted

 1 \ | /
 2- RT -     Thread Smart Operating System
 3 / | \     5.0.0 build Nov 24 2020
 4 2006 - 2020 Copyright by rt-thread team
 5lwIP-2.0.2 initialized!
 6try to allocate fb... | w - 640, h - 480 | done!
 7fb => 0x61100000
 8[I/sal.skt] Socket Abstraction Layer initialize success.
 9[I/SDIO] SD card capacity 65536 KB.
10[I/SDIO] switching card to high speed failed!
11Dir /mnt mount failed!
12hello rt-thread
13msh />mkfs sd0
14msh />
15
16# Ctrl + A, X退出
17QEMU: Terminated
18
19bernard@fuchsia-NUC8i7BEH:~/workspace/rt-smart/smart/kernel/bsp/qemu-vexpress-a9$ ./qemu-nographic.sh
20 \ | /
21- RT -     Thread Smart Operating System
22 / | \     5.0.0 build Nov 24 2020
23 2006 - 2020 Copyright by rt-thread team
24lwIP-2.0.2 initialized!
25try to allocate fb... | w - 640, h - 480 | done!
26fb => 0x61100000
27[I/sal.skt] Socket Abstraction Layer initialize success.
28[I/SDIO] SD card capacity 65536 KB.
29[I/SDIO] switching card to high speed failed!
30file system initialization done!
31hello rt-thread
32msh />

Compile under Windows and execute on Raspberry Pi 4B

It can also be compiled on Windows and executed on qemu or Raspberry Pi 4B development board. Here we mainly mention how to execute it on Raspberry Pi 4B.


Prepare the compilation environment

To compile rt-smart on Windows, you can use the env tool of RT-Thread. For download and installation of env tool, please refer to: https://www.rt-thread.org/page/download.html

Please make sure that env can be used normally. Because the rt-smart.zip package does not carry the toolchain in the Windows environment, please remember to install the toolchain preparation section described above to download the Windows toolchain and unzip it under `rt-smart\tools\gnu_gcc`. Open the terminal window of env, switch to the root directory of the rt-smart code package, run smart-env.bat, it will set certain environment variables, and then the overall smart development environment can be used.

1#进入rt-smart目录,设置环境变量
2cd rt-smart
3> smart-env.bat

Note: Run smart-env.bat here to set the environment, it includes the compiler settings, and it also sets the prefix of the toolchain. You can enter the following command in the env terminal to see if the returned result is valid:

1# 查看环境变量是否生效
2> set RTT_CC_PREFIX
3RTT_CC_PREFIX=arm-linux-musleabi-

Compile the application

When compiling an application, the usage is similar to that of Linux:

1#进入userapps目录进行编译
2cd rt-smart\userapps
3scons


Compile rt-smart kernel

 1#进入raspberry-pi\raspi4-32目录进行编译
 2cd rt-smart\kernel\bsp\raspberry-pi\raspi4-32
 3scons
 4... ...
 5CC build/kernel/src/signal.o
 6CC build/kernel/src/thread.o
 7CC build/kernel/src/timer.o
 8LINK rtthread.elf
 9arm-linux-musleabi-objcopy -O binary rtthread.elf kernel7.img
10arm-linux-musleabi-size rtthread.elf
11   text    data     bss     dec     hex filename
12 710780   40448   64730  815958   c7356 rtthread.elf
13scons: done building targets.

After the compilation is correct, the kernel7.img file will be generated in the current directory. This is the 32-bit version on the Raspberry Pi. Currently rt-smart only supports 32-bit systems, so it is executed in 32-bit mode on Raspberry Pi 4B.

Execute on Raspberry Pi

Prepare hardware connection

In order to execute on Raspberry Pi 4B, you need to prepare the following hardware list and connect the serial cable to the development board. The connection diagram is as follows:

1. Raspberry Pi 4B

2. SD card (32GB or less)

3.USB to TTL serial cable

4. Network cable

5. TYPE-C (for power supply)

6. Card reader (used to write compiled files to SD card)

Prepare the software on the SD card

To load the Raspberry Pi, some boot files need to be placed in the SD card. rpi4_rt-smart_boot.zip is to load some boot files for Raspberry Pi, which can be downloaded from the following address:

https://realthread.cowtransfer.com/s/1c2b64ba968748

Decompress the downloaded file and put it into the empty SD card root directory together with kernel7.img, as shown in the figure below, where the compiled executable elf file in the `userapps\root\bin` directory is stored in the bin folder.

Open the serial port debugging assistant, plug in the power, you can see that the program has been running normally, enter the bin directory to execute the sample program:

 1heap: 0xc00c9a0a - 0xc40c9a0a
 2\ | /
 3- RT -     Thread Smart Operating System
 4 / | \     5.0.0 build Nov 15 2020
 5 2006 - 2020 Copyright by rt-thread team
 6lwIP-2.0.2 initialized!
 7version is B1
 8bcmgenet: PHY startup ok!
 9[I/sal.skt] Socket Abstraction Layer initialize success.
10[I/SDIO] SD card capacity 31465472 KB.
11found part[0], begin: 4194304, size: 256.0MB
12found part[1], begin: 272629760, size: 29.772GB
13file system initialization done!
14hello rt-thread!
15msh />/bin/hello.elf
16msh />hello world!


1. Virtual Roundtable Part 1-Embedded System Information Security

2. The secret of Huawei's 5G was in the hands of a Turk? !

3. The latest semiconductor rankings are released, and Nvidia achieves 50% growth!

4. [MCU] A "flexible and resource-saving" IAP upgrade program

5.Why is RISC-V becoming a hot spot?

6. Introduction to Hongmeng OS suitable for developers~

Disclaimer: This article is reproduced online, and the copyright belongs to the original author. If you are involved in the copyright issues of the work, please contact us, we will confirm the copyright based on the copyright certification materials you provide and pay the author's remuneration or delete the content.

Guess you like

Origin blog.csdn.net/DP29syM41zyGndVF/article/details/110412136