The road to FreeRTOS learning, using STM32F103C8T6 as the experimental MCU (prologue - talking about MCU and FreeRTOS)

The way of learning is mainly the application of FreeRTOS operating system on STM32F103 (STM32F103C8T6), using the standard library programming method, and the IDE used is KEIL5.

Notice! ! ! This learning path can be learned by purchasing the STM32 minimum system board and some accessories, or by Proteus simulation.

Subsequent articles will be published on personal blog (jason1016.club) and CSDN at the same time;

The video will be posted on bilibili(UID:399951374)

Author's words:

        I believe that after learning the bare metal development of STM32, when you write a huge project with confidence, you will always feel that the tasks of each module will always restrict and affect each other in the later stage. There is an absolute sequence relationship (also called polling method).

        Here is an example: I set the MCU

  • (1) A task that needs to upload the temperature and humidity data collected by the sensor to the server every three seconds through the MQTT protocol
  • (2) This is for me to also set the system to monitor the light intensity threshold to control the switch of the light through the photometric sensor
  • (3) Set the OLED screen to display the clock in real time.
  • (4) Control the LED breathing light and perform a flip operation every 5s

        Then I will encounter many problems when writing programs:

  • Should the above first and second tasks be written in the interrupt or suspend flag and then executed in the polling main function?
  • Assuming that it is in an interrupt, will the execution event of the interrupt be too complicated?
  • Assuming that in the task, when there are more tasks, the single-chip microcomputer needs to complete a polling cycle every time. If the polling cycle is too long, will it cause the real-time performance of data transmission to be lost or even cause data packet loss?
  • When we use delay to wait for the function, will it cause the system to "do nothing" and cause CPU resources to be wasted in vain?

        So we started to learn and try to understand the operating system to solve the above problems. So what operating system should we transplant? By understanding the mainstream systems adapted to STM32F103 are μC/OS-II, eCos, FreeRTOS, Dujiangyan operating system and other operating systems. Among them, FreeRTOS is famous for being open source and free, so we naturally choose FreeRTOS as the first choice when we are learning microcontrollers.

        Alright, I've been locked up with you for so long, and it's not good to hang on to you anymore, so I'm going to get straight to the point! ! !

What is an operating system?

        I believe that many tutorials have been talked about here, but here I want to talk to you about my views!

        First of all, we must first know who is the main body of the operating system, and who does the operating system serve? There is only one service audience of the operating system from beginning to end, and that is the single-chip microcomputer.

        Regarding what is a single-chip microcomputer, I would like to share an understanding model that I personally like very much. (Taking STM32F103 as an example) we compare the single-chip microcomputer to a person, then his core is his little brain;

        Now that he is compared to a person, we might as well transform the various operating modes of the single-chip microcomputer into an advanced thinking mode of a person. First of all, the bare-metal development mode is the stage of this child. At this time, the microcontroller does not know how to allocate its own time reasonably: I only know that in the morning, I should brush my teeth first, then wash my face, and finally have breakfast. The single-chip microcomputer will not handle it, so I just stand in front of the sink and wait to brush my teeth and wait for the toothpaste to come (polling mode);

Then there is the front-end and back-end system mode . When you get older and enter the childhood period, you can understand what your parents say. In the above-mentioned mode of handling things, you have learned to listen to your parents. In this way, if mom says she is going to go out soon and asks you to help get the car keys, and you foolishly brush your teeth, wash your face and eat breakfast before sending it to mom, you will probably die of anger.

Finally, it comes to the multitasking system . The single-chip microcomputer has passed through the immature childhood, and has its own way of life and code of conduct in the youth. Of course, youth is a rebellious period. The difference in the development of different single-chip microcomputers lies in what they have learned and what they have learned (and here I call this matter what system they have transplanted). Let’s take a single-chip microcomputer child who has learned FreeRTOS as an example. This child has learned:

  • Divide all the things to be done into tasks, and then do the important things first (the task scheduler schedules according to the task priority).
  • You can do other things while other tasks are waiting. For example, if you are boiling hot water, you can do other things when the water boils. (task scheduler task switching)
  • Use your own memory reasonably (heap_4 memory allocation)
  • ......

        Of course, the three stages mentioned above are all based on the fact that the single-chip microcomputer is the foundation of human beings, endowing him with the ability to think. I believe everyone knows that the reason why human beings are different from beasts is their ability to think, and the basis of thinking is our developed brain, which is determined by our genes. Just like why can a single-chip microcomputer be endowed with an operating system (thinking ability)? The decisive factor lies in its fundamental core—the ARM core. Taking STM32F103C8T6 as an example, its core is cortex-M3. His core is his inherited brain. In essence, his brain supports his thinking. Therefore, the birth of the operating system is not a development product of ARM, but a native product of ARM. In fact, in the cortex-M3 and M4 cores, a series of configurations have long been reserved for the receiving operating system, and different operating systems are just changes in the different events encountered in the development process of the single-chip microcomputer.

        It may be a bit convoluted, so I like to use a very in-depth analysis: two factors determine a person, one is his genes, and the other is his experience. The same is true for single-chip microcomputers. What determines its essence is its factory hardware (core and peripherals), and what determines its way of thinking is its operating system.

  • We cannot determine our genes, but in fact our genes endow us with the ability to think. We can use different ways of thinking to achieve higher achievements under the condition of fixed genes.
  • The single-chip microcomputer also cannot determine its core, peripherals and other hardware, but in fact the core of the single-chip microcomputer endows it with the ability to transplant the operating system. It can also achieve more functions and reduce more power consumption by transplanting different operating systems when the hardware is fixed.

 I believe that after talking here, everyone probably understands the relationship between the single-chip microcomputer and the operating system. The operating system is the way the single-chip microcomputer thinks and handles things. There may be many introductions to the Linux operating system and FreeRTOS operating system on the Internet, but I believe everyone reads so many introductions. In my opinion, the definition of the operating system should be broadly defined to a mode of execution events of the single-chip microcomputer. Whether it is bare metal or front-end and back-end, multitasking is a complete operating system (here is the author's personal conjecture, please correct me if I am wrong).

Study Path Arrangement

        This learning path will use STMF103C8T6 as the MCU, transplant the FreeRTOS operating system on it, and analyze the FreeRTOS real-time operating system layer by layer. In the end, I hope that everyone can master the FreeRTOS real-time operating system, and can make many practical projects based on this.

Hope and Encouragement

I really like that sentence, the best time to plant a tree is 10 years ago, followed by today! May who you are today be who you are tomorrow. Just like the sentence written on my personal blog homepage:

You will eventually become who you want to be May you not be alone
on the road to success

This article is written independently by the author. All original articles on this BLOG may not be used for commercial purposes or traditional media without my permission. Please indicate the source for reprinting by online media, otherwise it is an infringement.

Guess you like

Origin blog.csdn.net/weixin_61908666/article/details/130822189