当前位置:网站首页>RT thread [II] system initialization process
RT thread [II] system initialization process
2022-04-22 07:53:00 【Ke Yuqian】
Rt-thread [ Two ] System initialization process
Preface
Open a special topic , Record your own learning Rt-thread The process of . A lot of information comes from previous notes and excerpts , I don't remember the specific source of some documents and knowledge points . If there is your hard work and the source is not indicated , Please contact me .
mailbox :[email protected]
WeChat :18852982072
Learn by myself Rt-thread In terms of my experience , This is not a very difficult IOT-OS. As long as you have enough patience , It's easy to get started . And for a domestic RTOS for . Finding information is relatively easy .
Here is the flow chart given on the official website
MDK Provides extended functionality S u b Sub Sub$ and S u p e r Super Super$( Other platforms have similar extensions , Here is the most commonly used MDK For example, ), You can give main add to S u b Sub Sub$ Prefix symbol as a new function S u b Sub Sub$main, This S u b Sub Sub$main You can call some to be added in main Previous function ( Add here RT-Thread System initialization function ), Call again S u p e r Super Super$main go to main() Function execution , This allows users to ignore main() Previous system initialization ( See ARM Compiler v5.06 for µVision armlink User Guide). Let's see RT-Thread The startup process is shown in the figure below :
But here's what's given MDK Process in environment I'm using RT-STUDIO IDE Use it directly GCC Compiled, so the starting process here is a little different .
We directly open the project startup_stm32f407xx.S file Go and see where our main function entry is .

Startup file startup_stm32f407xx.S
startup_stm32f407xx.S as follows


Intercept startup_stm32f407xx.S The first half This is assembly language I have studied the principle of microcomputer Or if you are interested You can study it . But some of the notes here have been written clearly .
First of all, we Set the stack pointer sp Then we put flash Medium data Paragraph and bss Transport section to sram in Pay attention to this bss The value of the segment All are assigned to 0 了 . Then Start Jump to SystemInit initialization Then jump to entry ( This is the entry function of our application ).
Let's take a look at this SystemInit initialization 
The most important sentence here is Configure the position of vector table and add offset address The specific meaning can be checked SCB register .
entry: Program entry function
Next is our most relevant program entry function

The next process is the same as that on the official website Play it again here

What we are most concerned about These are the two functions here One is related to the underlying hardware rt_hw_board_init, This is also the function we should focus on when porting ; The other is application related rt_application_init.
rt_hw_board_init: Underlying hardware related

hw_board_init(BSP_CLOCK_SOURCE, BSP_CLOCK_SOURCE_FREQ_MHZ, BSP_CLOCK_SYSTEM_FREQ_MHZ);
This sentence is the initialization of the clock . F427XX yes 180MHz Set it yourself .
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
Set up the console device This is shell Runtime console .
rt_components_board_init();
RT-Thread Automatic initialization mechanism

If you have such needs, you can understand what actions have been done here .
As you can see from the code above rt_components_init Functions are called and executed in turn RT-Thread Customize RTI Symbol segment SECTION(".rti_fn."level) Internal subordinate __rt_init_desc_rti_board_start To __rt_init_desc_rti_board_end Command or function of , The user can define... By calling the macro INIT_EXPORT(fn, level) Put the function pointer that needs to be initialized at startup into the RTI In the symbol segment , Form an initialization function table ( By analogy STM32 Interrupt vector table of ).
rt_application_init: Application related

Whether it's on or off heap Support The application entry is a thread
void main_thread_entry(void *parameter)

rt_application_init Created a main thread main_thread_entry, The component initialization function is called inside the thread rt_components_init, Then enter main function , Start executing user code , Users can go to main Add your own application to the function .

As you can see from the code above rt_components_init Functions are called and executed in turn RT-Thread Customize RTI Symbol segment SECTION(".rti_fn."level) Internal subordinate __rt_init_desc_rti_board_end To __rt_init_desc_rti_end Command or function of , The user can define... By calling the macro INIT_EXPORT(fn, level) Put the function pointer that needs to be initialized at startup into the RTI In the symbol segment , Form an initialization function table ( By analogy STM32 Interrupt vector table of ).
RT-Thread And for different level The corresponding macro definition is given , The code is as follows :

main()

Information
版权声明
本文为[Ke Yuqian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220622549037.html
边栏推荐
猜你喜欢
随机推荐
Unity遮罩 反向遮罩实现
C-10 年龄问题
【TCP/IP 四 IP 网际协议】
QT学习汇总
redis监听key过期事件
C#抽象类
继续树莓派4B+OLED:开机自动显示IP地址
Unity gets the network and converts it to a timestamp
QT advertising screen (multi display split screen + full screen display picture)
Vmware 设置固定ip地址--桥接模式
QT广告屏(多显示器分屏+全屏显示图片)
C-9 structure: the calculation input date is the day of the year
JWT实现登录认证,密码加密及Token校验全过程(附源码)
树莓派4B:使用raspi-config实现USB BOOT
Problem D: 孪生素数
Binary conversion -- learning summary
Opportunity interview questions
Oracle sequence usage collation
Multithreading (threaded Communication [producer and consumer])
MySQL Chinese field sorting problem (sorting according to Chinese Pinyin)

![Stm32外设篇 [一]IO](/img/75/61ea3ed2936eea9b55d59e96253995.png)







