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

Example Analysis of porting rt-thread to ls2k1000 Development Board

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Godson ls2k1000 development board transplant rt-thread example analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Transplanting rt-thread notes on ls2k1000 development board

1. Preface

two。 Basic introduction of Longxin School

The running process of 3.rt-thread on the Loongson faction

Startup Analysis of 4.rtt

4.1 start Code Boot

4.2 Startup process for rt-thread

5. Initialization of key part drivers

6.Stack Frame

7. Summary

1. Preface

Godson 2k1000 development board has a very rich peripheral resources, the board design is also very exquisite.

So I'm going to run rt-thread, and then do some related development operations.

This article mainly aims at the development board of Godson 2k1000 to transplant rt-thread. Through this article, we can basically grasp the process of transplanting rt-thread to a new architecture. At the same time, we can also have a good grasp of the relevant knowledge of mips64 architecture. At the same time, we are familiar with the use of Longxin 2k1000.

Because bare metal development has a certain relationship with rtos development, if you want to understand the lower level of rt-thread, you must understand the chip design and the design of various architectures.

two。 Basic introduction of Longxin School

Loongson pie is a development board facing ordinary development groups. Loongson pie is equipped with 2K1000 processor (main frequency 1GHz) and on-board DDR3 particles to realize the running and storage function of DDR3. The functions of input and output and interrupt of GPIO are realized. One network port, three USB interfaces, HDMI interface, LCD interface, audio input / output, SD card interface, two CAN interfaces and RTC timing function are integrated on the board. The WIFI module can be expanded. 2K Longxin School can be widely used in the fields of information security, electric power, rail transit, industrial control, signal processing, data communication, information education and so on.

Because of its strong performance and multi-interface, it also makes it possible to implement more schemes.

Godson has the SPI Flash of 8Mb, and the BIOS of Godson is stored in this SPI Flash. Godson is called pmon. It can be understood as uboot, due to the use of Godson pmon, in order to verify and experience the effect, and facilitate the development and testing, we can make use of the tftp download function of pmon, copy the firmware into memory, and then directly execute it. This method is conducive to program debugging and development.

When actually applied to the production environment, rt-thread can be solidified into spi flash, which can speed up the startup speed. Now we will only talk about the startup process of the development phase.

The running process of 3.rt-thread on the Loongson faction

Longxin Group burns the firmware through network download, so it starts pmon first, and then transfers the rt-thread firmware to ddr.

After powering up, the pmon of Godson starts to start. during the serial port printing process, we can enter the pmon console by entering the c character on the keyboard, so we can use the tftp of pmon to load the firmware into ddr, and then jump to ddr to execute.

Ifaddr syn0 192.168.12.100

Load t ftp://192.168.12.35/rtthread.elf;

G

Where ifaddr sets the ip address of the development board, syn0 represents the first network card, load loads the program into memory, and g starts execution.

Then, rt-thread starts the initialization process, initializes the serial port, initializes the interrupt, then turns on the interrupt, the thread starts scheduling, and rt-thread begins to schedule tasks.

This is a complete process implemented by the Longxin faction.

Startup Analysis of 4.rtt

For Longxin migration, or for a new architecture to migrate rt-thread, the basic process is divided into the following parts:

1. Bare metal code boot initializes stack space and bss segments to provide an environment for running c code

two。 Turn off interrupts until all processes are initialized and turn on interrupts when the first thread with the highest priority goes off the stack

3. Initialize uart

4. Initialize os tick interrupt

5. Console output logo

6. Initialize ipc, and components, initialize timer () and idle threads

4.1 start Code Boot

The main function of this section is to prepare for starting the C code.

This part of the code is usually written by the assembly, prepares the sp stack pointer, then clears the bss segment and jumps directly to the rtthread_startup function.

Then go to the rt-thread entry function.

4.2 Startup process for rt-thread

Briefly, the startup process of rt-thread is as follows:

1. Turn off global interrupts

two。 Board-level driver initialization (key initialization, timer, uart, etc., migration most of the work)

3. Initialize the selected rtt component

4. Print logo

5. Scheduler initialization

6. Initialize threads such as main, idle, etc.

7. Start scheduling (turn on global interrupt when leaving the stack)

8. Thread starts scheduling

5. Initialization of key part drivers

For Godson 2k1000, we need to pay attention to the initialization of key peripherals in rt_hw_board_init. Two are mainly involved here, one is uart driver initialization, the other is timer initialization.

For tick, we use the c0 register in mips to compare.

HPET controller

Through configuration, each timer can generate interrupts independently.

This set of timers consists of a master timer (up-counter) that accumulates upward and a set of comparators. This timer accumulates up at a fixed frequency (125MHz), so when the software reads the value of the timer twice, unless it encounters a timer overflow, the value read the second time is always larger than the value read the first time. Each timer contains a match register and a comparator. When the value of the match register is equal to that of the master timer, the timer generates an interrupt. Some timers can produce periodic interruptions. The HPET module includes a master counter (main count) and three comparators (comparator), all of which are 32 bits wide. Of the three comparators, one and only one comparator supports periodic interrupts (periodic-capable), and all three comparators support aperiodic interrupts.

In our rtt, aperiodic interrupts are normally used. The relevant registers are not expanded and can be configured in the process of use.

Uart controller

As the console of rtt, serial port is also indispensable. When using ls2k1000, we need to fully consider the use of uart resources.

2K1000 integrates 12 UART controllers and communicates with the bus bridge through the APB bus. Although there are so many serial port controllers, in fact, many of them are multiplexed serial port controllers, so in fact, only 4 uart interfaces can be used at the same time.

Its uart controller has the following parts:

1. The sending and receiving controller is responsible for distributing or receiving data in the fifo.

The 2.moden register controls the shape of the serial output signals DTR and RTS as well as the related check status.

3. Interrupt arbitration module: when any interrupt condition is satisfied and the corresponding position 1 is in the interrupt enable register (IER), then the interrupt request signal UAT_INT of the UART is set to a valid state.

4. Access register module: when the UART module is selected, the CPU can access the register selected by the address line through read or write operations.

Interrupt this part must be very careful, because the use of serial port, when it comes to fifo, you need to know the idle status and related half-full or full or 32-byte interrupt and other attributes. Otherwise, it will be extremely complicated to read the data.

6.Stack Frame

The stack frame is related to the compiler and architecture, so you need to know the activity trajectory of the stack when using it. The stack and unstack of the function and the call of the operating system are all related to this part.

The stack operation of rt-thread is in the stack.c file of the specific architecture of libcpu.

During initialization, each thread performs a stack-breaking operation. The unstack operation is in the context_gcc.S file.

In addition to pushing the stack into general registers, it also involves status registers, such as spsr or cpsr, and so on, which should also be taken into account if there is a FPU.

It should be noted that the order in which the stack is pressed must correspond to the order in which the stack is released. The debugging function of this part is tedious and needs to be tracked step by step.

After reading the above, have you mastered the method of example analysis of porting rt-thread to Godson ls2k1000 development board? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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