Location>code7788 >text

Can you tell me in detail about how to learn stm32?

Popularity:511 ℃/2025-04-11 20:11:51

As a veteran who has been working in the embedded field for several years, I would like to share my mental journey and methodology of learning STM32. To be honest, when I first started to contact STM32, I was also confused. I graduated from the mechanical major and switched to embedded. My first job was transferred to the electronics department, but in fact I was doing microcontroller development. Those days were really painful and happy.

Recently, I have compiled the STM32 learning experience accumulated over the years into one"STM32 Practical Practical Quick Start" (click to go directly)The course includes a complete set of content from basic to practical, and 15 practical projects are taught step by step. But don’t rush to see the course first. I want to systematically talk about how to learn STM32.

1. Correct understanding of STM32

Many people are anxious to write code as soon as they come up, which is the biggest misunderstanding. STM32 is not simply programming, but a product of the combination of hardware and software.

When I first entered the industry, my leader threw me a STM32F103 development board and said, "Give me a demo that can run marbles in a week." I thought to myself, isn't it just to make a few LED lights flash? As a result, I didn't run after three days, so I was so angry that I almost dropped the board. Later I discovered that there was something wrong with my understanding of STM32.

The STM32 is a series of 32-bit ARM Cortex-M core microcontrollers launched by ST (ST). It is not a single model, but a huge family. They have their own characteristics in terms of performance, peripheral resources, storage capacity, etc. The most common entry-level is the STM32F1 series, among which F103 is the "star" model.

2. Essential knowledge reserves

Before learning STM32, you should at least have the following knowledge:

1. Basics of C language

This is essential, and STM32 is mainly developed in C language. If you can't even figure out the pointer and structure, don't rush to learn STM32, and make up for C language first.

I changed from mechanical to embedded, but my C language foundation was weak, and as a result, I often had inexplicable bugs when writing code. Once, it took me two days to find out that it was the wild pointer problem caused by the pointer not initializing. That feeling of frustration is painful to think about now.

2. Knowledge of digital circuits and analog circuits

You don't need to be proficient, but at least you need to understand the basic electronic components and circuit principles. For example, what are resistors, capacitors, diodes, transistors, what are pull-up resistors and pull-down resistors, what are filter circuits, etc.

I remember when I first started studying, I saw a bunch of symbols on the circuit diagram and it was a big head. Later I was"STM32 Practical Quick Start"The course specially added basic hardware knowledge modules, including how to view schematics, how to draw schematics, how to make boards, basic digital, analog and electrical, etc., in order to help novices like me avoid detours.

3. Computer composition principle

Understand the basic concepts and working principles of CPU, memory, input and output devices. STM32 is essentially a small computer system, and understanding the principles of computer composition helps to understand the architecture and how STM32 works.

4. Embedded System Basics

Basic knowledge such as the difference between an embedded system and a PC, the concept of a real-time operating system, the difference between interrupts and polling.

These basic concepts have helped me a lot in the process of my transformation from microcontroller to embedded Linux application development. They are like a map that prevents me from getting lost in the embedded ocean.

3. Learning route planning

Stage 1: Understand the STM32 architecture and development environment

First, we need to understand the internal architecture of STM32. What is the ARM Cortex-M kernel? What is the bus structure of STM32? How is its storage map organized? These issues need to be understood in a general way.

Next, get familiar with the development environment. There are many IDE options for developing STM32, such as Keil MDK, IAR, STM32CubeIDE, etc. Newbie recommends to use Keil MDK, which is the most widely used in the country and has the most abundant information.

However, in my course, I insisted not to use code generation tools like CubeMX, but instead handwritten code line by line. Why? Because only in this way can you truly understand the register configuration and working principle of STM32, rather than relying on the black box code generated by the tool. The students generally reported after class that although it was painful at the beginning, the efficiency of later development and depth of understanding were greatly improved.

Stage 2: Master the basic peripherals

The power of STM32 is its rich on-chip peripheral resources. In the introductory stage, you need to focus on mastering the following peripherals:

1. GPIO (General input and output port)

This is the most basic peripheral, used to control simple devices such as LEDs and buttons. I recommend implementing at least the following functions:

  • LED blinking (output mode)
  • Key detection (input mode)
  • External interrupt (interrupt trigger mode)

I remember when I first learned GPIO, I couldn’t tell the difference between push-pull output and open-drain output. It was not until I needed to use the IIC bus in a project that I suddenly realized: Only by opening the drain output can the function of line and between!

2. Timer

The STM32's timer function is extremely powerful and can be used for timing, PWM output, input capture, etc.

Mastering the timer is a hurdle, and many people are stuck here. I was just like that, looking at the densely packed registers and bit definitions on the data sheet, my head was too big. Later I summarized a method: first understand the basic working principle of the timer, then look at the specific register configuration, and achieve twice the result with half the effort.

3. USART (Universal Synchronous Asynchronous Transceiver)

This is the basic way for STM32 to communicate with a PC or other device. Learning to configure USART to realize serial port data transmission and reception is a necessary skill.

Our company has a project that uses STM32 for data collection and then sends it to the host computer via USART. It seems simple, but there are many pitfalls in the middle, such as incomplete serial port reception and data loss. These practical experiences,

4. ADC (Analog-to-digital converter)

Used to collect analog signals, such as temperature, light, voltage, etc.

The difficulty of learning ADCs lies in how to improve sampling accuracy and reduce noise impact. In a medical equipment project, the data fluctuations are large, which affects the diagnostic results. Later, this problem was solved through technologies such as oversampling and filtering. These experiences are also shared in my courses.

5. I2C and SPI

These two are commonly used communication buses for STM32 to communicate with various sensors, memory and other peripherals.

The difficulties in I2C bus learning are timing and troubleshooting. I remember one time, the I2C bus communication failed successfully. I searched for two days and found that it was caused by the improper selection of the pull-up resistor value. SPI is relatively simple, but there are also many pitfalls in multi-device management and high-speed transmission.

Stage 3: System advancement

After mastering the basic peripherals, you can enter the system-level learning:

1. DMA (Direct Memory Access)

DMA can realize data transmission between memory and peripherals without occupying the CPU, greatly improving system efficiency.

In a data acquisition project, I initially collected ADC data using interrupts, and the CPU occupancy rate was as high as 70%. After switching to DMA, the CPU usage rate dropped to 15%, making the system more sensitive.

2. Low power mode

STM32 provides a variety of low-power modes, such as sleep, stop, standby, etc. In battery-powered applications, the rational use of low-power mode can greatly extend battery life.

I've made a wearable device that uses the STM32F103 as the master. Initially, the battery could only be used for 2 days, but later, after optimizing the low-power consumption strategy, it was extended to 7 days, and the user experience was greatly improved.

3. RTOS (real-time operating system)

For complex embedded applications, the introduction of RTOS can simplify task management and improve code maintainability. Commonly used RTOS are FreeRTOS, RT-Thread, uC/OS, etc.

After I joined a foreign company at the age of 27, I have been exposed to more complex embedded systems, almost all of which are developed based on RTOS. Learning to use RTOS on STM32 is a key step towards advanced embedded development.

Although mine"STM32 Practical Practical Quick Start" (click to go directly)The course mainly focuses on bare metal programming, but also includes some introductory knowledge of RTOS, laying the foundation for students' subsequent in-depth learning.

Stage 4: Project Practical Battle

The knowledge you get from paper is always shallow, and you must practice it yourself to know it. No matter how much theoretical study is, it is not as good as the practical experience of a complete project.

I designed 15 practical projects, from simple LED flashing and key control to complex WIFI control, sensor data acquisition and processing, etc., to consolidate the knowledge learned in actual combat. I demonstrated the code line by line in each project, and did not use code generation tools such as CubeMX. The purpose is to let students truly understand the working principle of STM32.

I especially recommend the following categories:

1. Smart home category

Such as temperature and humidity monitoring, intelligent lighting control, door and window status monitoring, etc. In my course, there is a smart home control system based on STM32 and ESP8266, which can remotely control home appliances through mobile APP.

2. Data collection category

Such as industrial parameter monitoring, environmental data recording, etc. This type of project usually involves data acquisition and processing of multiple sensors, and can comprehensively use peripheral knowledge such as ADC, I2C, SPI, etc.

3. Control class

Such as simple robots, drone control systems, etc. This type of project has high real-time requirements and can exercise interrupt processing and task scheduling capabilities.

4. Communication category

Such as wireless data transmission, network connection, etc. In the course, I specifically explained how to use STM32 to control the ESP8266 module to connect to the WIFI network and realize Internet of Things applications.

During the completion of these projects, you will encounter various problems, which is the most valuable learning opportunity. I remember when I was working on a smart home project, I encountered the problem of unstable communication of ESP8266. After a week of investigation, I found that it was caused by excessive power ripple. These practical experiences are beyond the reach of any book.

4. Recommended learning resources

1. Official information

The reference manual and data sheet of ST official website are essential materials. Although it is in English, the register definition and function description are the most accurate.

When I first came into contact with STM32, I was stunned by the thick reference manual. Later I developed a habit: every time I learn a new peripheral, I first read the relevant chapters in the official manual, and then read the tutorials and routines, so that my learning efficiency will be greatly improved.

2. Development board and supporting information

It is crucial to choose a good STM32 development board. There are many options on the market, such as Zhengdian Atom, Wildfire, STM32F103 Minimum System Board, etc.

3. Network resources

There are many high-quality STM32 teaching videos on Bilibili, and there are also various open source projects to refer to on GitHub. However, the quality is uneven, so it is recommended to choose a series of tutorials with good reputation and systematic learning.

I also share a lot of STM32 learning materials and project cases in my official account. If you are interested, you can check it out.

4. Book recommendation

  • "STM32F10xxx Cortex-M3 Programming Manual": This is the official Chinese programming manual, which is relatively detailed.
  • "ARM Cortex-M3 Authoritative Guide": A good book for gaining insight into the Cortex-M3 kernel.
  • "Embedded Real-time Operating System μC/OS-III": A classic textbook for learning RTOS.

5. Common learning misunderstandings

1. Over-dependence on code generation tools

Tools such as STM32CubeMX can quickly generate initialization code. Many beginners use these tools from the beginning, resulting in poor understanding of the underlying registers and working principles.

2. Just watch but not practice

Embedded development is a highly practical field, and just reading books and watching videos is far from enough. You must practice hands-on, debug the code, and solve problems before you can truly master it.

My course emphasizes hands-on practice, and each of the 15 practical projects needs to be completed by the students themselves. I also provide learning exchange groups and personal Q&A to ensure that the problems encountered by students during the practice can be solved in a timely manner.

3. Lack of systematic learning

Many people learn STM32 to solve a specific problem. They let go after learning, resulting in scattered knowledge points. It is recommended to formulate a systematic study plan and proceed step by step.

4. Ignore the hardware foundation

Many learners with software background often ignore hardware knowledge, which leads to helplessness when encountering hardware problems during debugging.

I remember a colleague who has strong software capabilities but knows nothing about hardware. Once, the STM32 was not working normally in the project. He checked the software for a day but couldn't find the reason. Finally, I took a look and found that the crystal oscillator was not soldered properly, which is a typical hardware problem.

In my course, I specially added the basic hardware knowledge module, including how to view schematic diagrams, draw schematic diagrams, how to make boards, basic digital, analog and electrical, etc., to make up for this common shortcomings.

6. The road to advancement

After learning STM32, in which directions can you develop?

1. Deep into the ARM architecture

You can learn more advanced ARM Cortex-A series processors and enter Linux embedded development. After I joined a foreign company at the age of 27, I switched from microcontroller development to embedded Linux application development, and my salary and technical level have been qualitatively improved.

2. Focus on a certain application field

Such as automotive electronics, medical equipment, industrial control, etc. My job in a foreign company is to focus on embedded development in the field of automotive electronics, and this professional direction is easier to become an industry expert.

3. Full stack IoT development

Combining cloud services and mobile APP development, we will create a complete IoT solution. One of my current company businesses is to provide overall solutions to the Internet of Things, and this direction has broad prospects.

4. Embedded system optimization

Such as power consumption optimization, performance optimization, safety reinforcement, etc., we have become an expert in embedded system optimization.

7. Personal experience and suggestions

Learning STM32 is not easy, but it is definitely worth it. Looking back on my career development over the years, from a mechanical graduate to an embedded development engineer, to starting my own company, STM32 is the cornerstone of my entry into the industry.

If you decide to learn STM32, I have the following suggestions:

1. Persevere

Embedded development has a long learning cycle and requires continuous investment of time and energy. I started to come into contact with microcontrollers at the age of 24, and after years of accumulation, I have achieved today's achievements. Don’t expect to become an expert in the short term, but have a long-term mentality.

2. Practice more hands-on

It is the most taboo to just watch but not practice. It is recommended to prepare a development board and follow the tutorial or course to practice step by step. Don’t be afraid when encountering problems. The process of solving problems is the best learning process.

The 15 practical projects in my course cover various application scenarios from basic to advanced. Each project is carefully designed by me to allow students to grow in actual combat.

3. Develop debugging capabilities

In embedded development, debugging is a very important link. Learn to use oscilloscopes, logic analyzers and other tools, learn to analyze serial logs and debug information, these are all essential skills.

4. Focus on the community and cutting-edge technologies

The technology in the embedded field is updated quickly. We must maintain our enthusiasm for learning and pay attention to industry trends and new technologies. I started writing official accounts at the age of 28. On the one hand, I shared knowledge, and on the other hand, I forced myself to continue to learn.

5. Find like-minded partners

On the road to learning, having friends to move forward together will make you more motivated. My courses are equipped with a learning exchange group, where students can discuss and answer questions, and I will also regularly share industry trends and advanced knowledge in the group.

Conclusion

STM32 learning is a challenging but also a sense of accomplishment. It not only allows you to master a practical skill, but also cultivates your logical thinking and problem-solving skills.

If you are a newbie in embedded development, I hope my experience sharing can give you some inspiration and help. If you want to learn STM32 systematically, you can consider mine"STM32 Practical Practical Quick Start" (click to go directly)Courses, 15 practical projects are taught step by step, including a complete set of content from GPIO to WIFI, and also provide development boards and my personal Q&A services.

There is no shortcut to the learning path, only down-to-earth and perseverance. I hope everyone can find their own wonderful things on the road of embedded development!