WSL2(Ubuntu 24.04)上开发RT-Thread操作系统
安装环境
RT-Thread源码
1
2
3git clone https://github.com/RT-Thread/rt-thread.git
# 国内镜像
git clone https://gitee.com/RT-Thread/rt-thread.git安装QEMU,这是一个仿真器,用来模拟RT-Thread在ARM架构上运行
1
sudo apt-get install qemu-system-arm
安装python和scons环境(RT-Thread的qemu配置脚本是使用scons写的,需要在python环境中安装scons和kconfiglib)
1
2
3
4
5
6
7
8
9sudo apt install python3.12
# 切换到源码根目录
cd rt-thread/
# 创建python虚拟环境
python3 -m venv .rt_thread_env
# 激活虚拟环境
source .rt_thread_env/bin/activate
# 安装scons和kconfiglib(前置环境)
pip3 install scons kconfiglib安装交叉编译器(因为编译RT-Thread要运行在ARM芯片上,所以需要使用gcc-arm的交叉编译环境),版本号要高于:6.2.1
1
2
3sudo apt install -y gcc-arm-none-eabi
# 查看版本号
arm-none-eabi-gcc --version版本号: arm-none-eabi-gcc (15:13.2.rel1-2) 13.2.1 20231009
安装ncuses库
1
sudo apt-get install libncurses5-dev
RT-Thread下的qemu环境配置
进入RT-Thread的根目录,之后执行以下指令:1
2
3
4
5
6
7
8
9
10# 进入模拟器环境
cd /bsp/qemu-vexpress-a9
# 进入配置环境,选择需要的配置
scons --menuconfig
# 编译源码
scons
# 授予运行权限
chmod +x ./qemu.sh
# 运行模拟器
sudo ./qemu.sh
项目代码编写
进入/applications/main.c文件,编写项目代码,实现需要实现的功能,比如:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020/12/31 Bernard Add license info
*/
void thread_entry(void *parameter){
while(true){
rt_kprintf("Thread is running.\n");
rt_thread_delay(1000);
}
}
int main(void)
{
rt_kprintf("Hello, This is Javen.\n");
//创建线程
rt_thread_t thread = rt_thread_create("my_thread", thread_entry, RT_NULL, 1024, 10, 20);
if(thread != RT_NULL){
rt_thread_startup(thread);
}
return 0;
}
修改结束之后需要重新编译