Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to transplant rt-thread operating system on raspberry pie 2

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to port the rt-thread operating system to Raspberry Pie 2. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Preparatory work

Hardware

1. Raspberry pie 2 development board (if not, you can directly replace it with qemu).

Software

The env tool provided by rt-thread can be used on 1.window.

Scons is required on 2.Ubuntu because the rt-thread operating system is organized through scons.

3.git tools for code management

4.qemu, analog development board

5.arm gcc version gcc-arm-none-eabi-5_4-2016q3

The experiments in the following articles are all carried out under Ubuntu16.04, using qemu to simulate raspberry pie 2. The actual hardware has also been tested and the effect is the same.

two。 Transplant idea

The power-up process of raspberry pie 2 is to start gpu and read the kernel firmware from the SD card. So if you want to implement kernel yourself, you need to do similar processing, compile a firmware of kernel7.img and put it in the SD card. If you operate directly with qemu, you don't need so many complex operations, just local simulation.

What is the point if you want to migrate the rt-thread operating system to the raspberry pie?

2.1. Startup code

When raspberry pie gpu loads kernel7.img into sdram to start execution, you first need to do the necessary initialization work. So the link address 0x00008000 needs to be given correctly. Initialize the necessary equipment, since there is no previous allocation stack, you can only use assembly for initialization. In short, do what is necessary. So what are these necessary operations? Because the chip of Raspberry Pie 2 uses bcm2835, there are four cores working in it, so only one core can work and the other three cores sleep. Then close mmu, allocate stack space, and clear the bss segment. At this point, you can jump to C language to perform the relevant logic operations. After all, the operation of C language looks clearer than assembly.

2.2. Interrupt vector initialization

Here you need to specify the interrupt vector table and specify the handler of the interrupt function. Organize the offset of the interrupt to the scale according to the architecture of armv7. Then initialize the initialization of the rt-thread interrupt vector table. Of course, this has been done in the operating system.

2.3.tick

The rt-thread operating system needs to have a clock tick, that is, timing interrupts. For this part, you need to implement a timer interrupt yourself. In terms of physical hardware, we can use the interrupt generated by a clock module called SP802 in the raspberry pie, but qemu does not implement it, only gtimer. So in order to ensure that both the hardware and qemu can run, gtimer is used in the experiment.

2.4. Context switching

If you want to achieve the return of the interrupt site and the thread switch site, there is no lack of context switching logic, that is, context. The main task of this part is to save the state register before switching the context and restore the contents of the register after the switching is completed. So we can restore the last scene.

2.5.uart

If you want to debug rt-thread programs, of course, serial port printing is a major feature of the rt-thread operating system is to support shell. You can use commands to operate the operating system and view information. Raspberry pie has two serial ports, one is directly driven by the internal clock mini uart. The other is the pl011 serial port module, which operates at different register addresses.

The above 5 points are also the key to the migration of the entire minimum system. Now the author has transplanted this raspberry pie rt-thread minimum system. If you are interested, you can play by yourself.

Https://github.com/bigmagic123/raspi-littlevgl .

The purpose of this project is to transplant littlevgl on raspberry pie. The original version is the smallest system.

3. Operation steps

First, you need to clone the code down.

Git@github.com:bigmagic123/raspi-littlevgl.git

Then go to the project directory / bsp/raspi2. What needs to be modified here is the GCC path in the rtconfig.py file.

You need to change it to your own gcc path.

Then open Terminal-> new Terminal on vscode to see the console window appear.

Type scons to compile. The following phenomena indicate success.

QEMU operation

If qemu is already installed on your computer at this time, you can start the script directly.

This indicates that the system is running successfully.

Raspberry pie 2 hardware operation

Connect raspberry pie with USB to TTL module. Then put the file you just compiled into the SD card directory.

The SD card file can only leave these three files, and kernel7.img is the rtthread firmware we just compiled with scons.

4. Code analysis

The relevant kernel code can be downloaded from the official website of rt-thread. The author just changed some bsp files.

CPU correlation

Related to cpu is in the bsp/raspi2/cpu directory.

Startup starts with start_gcc.S. The context is switched in the context_gcc.S file.

Peripheral correlation

Peripherals related to the code in the driver directory. Currently, only uart and tick are implemented.

User operation code

The user operation code is in the applications file, where the first thread started is in the main function.

Int main (int argc, char** argv)

{

Rt_kprintf ("Hello RT-Thread!\ n")

While (1)

{

Rt_kprintf ("cur tick is% d\ n", rt_tick_get ())

Rt_thread_delay (1000)

}

Return 0

}

Thank you for reading! This is the end of the article on "how to transplant rt-thread operating system on raspberry pie 2". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report