My STM32 development environment bloody history: From entry to proficiency, avoiding detours is the bottom line
Speaking of the choice of STM32 development environment, I really have too much to say. As a veteran who has been working in the embedded field for nearly ten years, I have gone through many detours and accumulated a lot of experience from being ignorant when I first entered the industry to being able to calmly deal with various project needs now. Today I will talk about this seemingly simple but often troublesome problem for novices: How to choose the development environment for STM32?
Before officially starting, I want to share a short story first. I just finished recording some time ago"STM32 Practical Practical Quick Start" (click to go directly)In the course, a friend who had just entered the industry sent me a private message: "Teacher, I bought a STM32 development board, but I didn't succeed in installing the environment for three days. Is it not suitable for me to learn embedded?" I felt a sigh in my heart when I heard this. In fact, this situation is too common among newbies, and it can even be said to be the "introduction tax" of embedded development. But in fact, as long as you choose the right tools and master the correct methods, the construction of the STM32 development environment is not that complicated.
1. Why choose STM32? Let's talk about its advantages first
Before we discuss the development environment in depth, let’s talk about why STM32 is so popular. STM32 is a 32-bit microcontroller series based on the ARM Cortex-M core launched by ST. It has several outstanding advantages:
First of all, it is extremely cost-effective. Compared with similar products, the STM32 does a great job of balancing performance and price. A high-performance STM32F103C8T6 development board is less than 20 yuan on Taobao, which was simply unimaginable ten years ago.
The second is the improvement of the ecosystem. ST Company provides STM32 with rich library functions and development tools, allowing developers to focus more on application-level development without paying too much attention to the underlying details. Especially after the launch of STM32CubeMX, the graphical configuration greatly lowered the development threshold.
Also, it has a wide range of applications. From simple LED controls to complex industrial control systems, from smart homes to medical devices, the STM32 is almost everywhere. Because of this, mastering the development skills of STM32 is a must-have skill for embedded engineers.
I remember when I first started learning STM32, I was attracted by its "low cost and high performance" characteristics. At that time, in order to get started quickly, I bought a lot of books and video tutorials and took a lot of detours. Now I think about it, if there were any recordings I had now"STM32 Practical Quick Start"I can save at least half a year of exploration in the course. This is also my original intention of recording this course - I hope it can help more novices avoid detours and quickly master the essence of STM32 development.
2. STM32 mainstream development environment
Let’s talk about the topic, the STM32 development environment mainly has the following options:
1. Keil MDK-ARM: The old strong man is as stable as Mount Tai
Keil MDK-ARM is undoubtedly the first choice for STM32 development, especially in the country. It provides a complete development tool chain, including editors, compilers, debuggers, etc., with a friendly interface and quick access.
Advantages:
- Ecosystem perfection: Almost all STM32 tutorials and books are written based on the Keil environment and have rich learning resources.
- Powerful debugging function: The built-in debugger supports breakpoints, single-step execution, variable monitoring and other functions, making it very convenient to troubleshoot problems.
- Good compatibility: Support for various ARM chips is very comprehensive, not limited to STM32.
- Automatic code completion and syntax checking: This is very helpful to improving development efficiency.
- Built-in peripheral register view: You can intuitively view and modify register values, which is very helpful for understanding the working principle of hardware.
Disadvantages:
- Commercial software, expensive: The full version authorization is close to 20,000 yuan, which is a great burden for individual developers and small teams. Of course, there is a free version but limited code size (32KB).
- Only support Windows platforms: Not very friendly to developers using Mac or Linux.
- The IDE itself is bloated: The startup speed is slow and the interface design is a bit outdated.
- Weak project management function: Not very friendly to large projects.
I remember one time participating in an embedded system design competition, and Keil suddenly crashed while debugging code all night, causing me to lose several hours of work. At that moment, I really had the urge to smash the computer. Later, I developed the habit of saving and backing up code frequently, and began to explore the possibilities of other development environments.
However, it has to be admitted that for beginners, Keil is still the easiest choice to get started. If you are just starting to learn STM32, I suggest starting with Keil first and consider other options when you have a certain foundation.
2. STM32CubeIDE: Officially produced, with a bright future
STM32CubeIDE is an integrated development environment officially launched by ST. It integrates STM32CubeMX and Eclipse IDE to become a one-stop development solution.
Advantages:
- Free and complete functionality: No code size limit, suitable for projects of all sizes.
- Integrated STM32CubeMX: You can directly configure graphically in the IDE and generate initialization code with one click.
- Based on Eclipse: Inherited the powerful functions of Eclipse, such as version control, code reconstruction, etc.
- Official support: ST company is continuously updated and maintained, and the support for the new series of chips is the most timely.
- Cross-platform: Supports Windows, Linux and MacOS.
- Powerful debugging functions built-in: Including real-time variable viewing, breakpoint setting, memory viewing, etc.
Disadvantages:
- High resource occupancy: Higher configuration is required to run smoothly.
- Slow startup speed: Especially when it is first started.
- Steep learning curve: For developers who are not familiar with Eclipse, it may take some time to get started.
- Occasionally there are stability issues: There may be lag or crash under certain operations.
Last year I took over a smart home project and the customer asked to use the latest STM32H7 series chips. I tried to use Keil at the time, but found that the support for the new series of chips was not very perfect. After switching to STM32CubeIDE, the problem was solved. In particular, its graphical configuration function makes complex clock and peripheral initialization extremely simple, greatly improving development efficiency.
Although I was a little uncomfortable when I first started using CubeIDE, especially the project structure and build system were quite different from Keil, I fell in love with its powerful features after adapting. Now it has become my main tool for daily development.
3. IAR Embedded Workbench: Excellent performance, professional choice
IAR is another professional-grade embedded development environment that is very popular in the industry, especially in areas where code quality and execution efficiency are strictly required.
Advantages:
- Strong compilation and optimization capabilities: The generated code is small in size and high in operation efficiency, and has obvious advantages in embedded systems with limited resources.
- Comprehensive and powerful debugging functions: Supports advanced functions such as complex conditional breakpoints and data breakpoints.
- Rich code analysis tools: Including static analysis, complexity analysis, etc., which helps improve code quality.
- Good MISRA-C support: It is very important for projects that need to meet functional safety standards.
- Professional technical support: Paid users can receive timely technical support.
Disadvantages:
- Expensive: The full version is more expensive than Keil.
- Only support Windows platforms: Linux and MacOS are not supported.
- It's more difficult to get started: The interface is not as intuitive as Keil, and there are many configuration items.
- Integration with STM32CubeMX is not as perfect as CubeIDE: Additional configuration is required.
I have worked for a company that does medical equipment, where almost all projects are developed using IAR. The reason is simple: medical devices have extremely high requirements for code reliability and performance, and IAR does excel in this regard. In particular, its code optimization capabilities are often about 10% smaller than the code generated by Keil. This difference is very significant in resource-constrained microcontrollers.
However, for the average developer, the high price of IAR and the steep learning curve can be prohibitive. Unless your work environment requires IAR, other options may be more appropriate as individual learning and small project development.
4. PlatformIO + VSCode: Open Source Rookie with Unlimited Potential
In recent years, with the rise of the open source movement, PlatformIO based on VSCode has gradually become a new choice for embedded development, especially favored by young developers.
Advantages:
- Completely free and open source: No functional limitations.
- Lightweight: Fast startup speed and less resource usage.
- Cross-platform: Perfectly support Windows, Linux and MacOS.
- Integrated Package Management: Automatically handle dependencies and simplify environment configuration.
- Supports multiple development boards and frameworks: Not only limited to STM32, it also supports various platforms such as Arduino and ESP32.
- A powerful plug-in ecosystem: Thanks to VSCode's plug-in system, the development environment can be highly customized.
- Modern interface and user experience: In line with the habits of contemporary software development.
Disadvantages:
- Relatively few learning resources: Especially Chinese materials.
- The debugging function is not as perfect as that of professional IDE: Some advanced debugging features may be missing or require additional configuration.
- Not friendly enough to novices: A certain command line and development toolchain knowledge is required.
- Integration with STM32CubeMX is not seamless enough: It takes some extra work.
At the end of last year, I started trying to develop STM32 projects using PlatformIO. The initial motivation was simple - I changed into a Mac notebook, and neither Keil nor IAR supported MacOS. Unexpectedly, this "forced" attempt completely changed my development habits. The combination of PlatformIO+VSCode not only meets basic development needs, but its modern experience and powerful expansion capabilities even allow me to choose to continue using it after returning to the Windows environment.
Especially for those who are involved in multiple platforms development at the same time, the unified experience of PlatformIO is irreplaceable. I can develop STM32, ESP32 and Arduino projects simultaneously with the same set of toolchains without switching between multiple IDEs.
In my recently recorded "STM32 Quick Start" course, I also added a chapter specifically to introduce how to use PlatformIO for STM32 development, because I believe this will be a future trend, especially for cross-platform developers.
5. Other options: AC6 System Workbench, EmBitz, etc.
In addition to the mainstream development environment mentioned above, there are some other options worth mentioning:
AC6 System Workbench (SW4STM32):
- Free and complete functionality
- Based on Eclipse
- Official support (ST recommended)
- But the update is not as timely as CubeIDE, and it is now basically replaced by CubeIDE
EmBitz:
- Lightweight IDE
- free
- Interface similar to Keil
- But the community is small and resources are limited
Bare Metal Development + Makefile + GCC:
- Complete control over the build process
- Maximum flexibility
- Suitable for advanced users and specific needs
- The learning curve is extremely steep
I once tried bare metal development + Makefile in a project that requires extreme optimization. Although a lot of effort was put into building and understanding the construction system in the early stage, the final reward was also significant: not only did I have a deeper understanding of the ARM architecture and STM32, the generated code was also nearly 20% smaller than using the default settings of the IDE. Of course, this method is only recommended to developers who have an in-depth understanding of embedded systems, which is too complicated for beginners.
3. How to choose the STM32 development environment that suits you the most?
After saying so much, the most critical question is: How should we make decisions in the face of so many choices? Here are some suggestions from several different angles:
1. Choose according to the developer's experience level
beginner: There is no doubt that Keil MDK is the best choice. Rich Chinese tutorial resources, intuitive interface and complete debugging functions can allow you to focus on learning STM32 itself, rather than be bothered by problems in the development environment. Even the course "STM32 Practical Quick Start" that I have recorded now mainly uses the Keil environment, which takes into account the needs of most beginners.
Intermediate Developer: You can try STM32CubeIDE. It integrates the graphical configuration function of STM32CubeMX, which can greatly accelerate the development process. At the same time, an Eclipse-based environment can also help you become familiar with more professional development toolchains.
Senior Developer: Choose according to project requirements. If you pursue code efficiency and quality, IAR is the best choice; if you need to develop cross-platform or integrate with modern development processes (such as CI/CD), PlatformIO is a better choice; if the project is complex and has special needs for the toolchain, you can even consider the bare metal development + Makefile method.
2. Select according to the project type
Personal study or small project: Free version of Keil (limited code size 32KB) or completely free STM32CubeIDE/PlatformIO are all good choices.
Commercial Product Development: Select according to product characteristics. Products with high performance and code quality requirements can be considered; general commercial product development uses the full version of Keil or STM32CubeIDE to meet the needs.
Teamwork project: It is recommended to use STM32CubeIDE or PlatformIO, which has better support for version control and cross-platform features can ensure that team members can maintain a consistent development experience when using different operating systems.
Teaching scenarios: Usually Keil is the best choice because the learning resources are the most abundant. But if you are teaching in colleges and universities and have a limited budget, STM32CubeIDE is a good alternative.
I remember that when I was in college, the school’s laboratory purchased several Keil sets, but the number was limited, and there were often cases of "grabbing computers". If you could use free tools like STM32CubeIDE or PlatformIO at that time, there would be no such problem. This is why in my "STM32 Quick Start" course, in addition to the main Keil environment, I also introduced how to use other free alternatives.
3. Select according to the operating system
Windows Users: All options can be considered, Keil, IAR, STM32CubeIDE and PlatformIO can all work perfectly.
MacOS or Linux users: The selection range is narrowed to STM32CubeIDE and PlatformIO, the former is more comprehensive but has a higher resource occupancy, while the latter is lighter but some advanced features may require additional configuration.
4. Choose according to your budget
Zero budget:STM32CubeIDE or PlatformIO are the best choices, and the free features they provide are enough to cope with most development scenarios.
Limited budget: You can consider the entry-level version of Keil or a specific kernel version, and the price is relatively acceptable.
Adequate budget: Full version of IAR or Keil, get the most comprehensive functional support and professional technical services.
4. Frequently Asked Questions and Solutions for Building STM32 Development Environment
No matter which development environment you choose, you may encounter some problems during the construction process. Here are some common problems and solutions:
1. Driver issues
Problem description: The STM32 development board or ST-Link debugger cannot be recognized.
Solution:
- Make sure the latest ST-Link driver is installed
- Try different USB ports (especially USB3.0 ports sometimes have compatibility issues)
- Check whether the USB cable supports data transmission (some charging cables do not support data transmission)
- Check whether there are unrecognized devices in Device Manager and right-click to update the driver
I once had a strange problem: the same development board and debugger runs fine on my desktop, but it just doesn't recognize it on my laptop. After struggling for a long time, I finally found that it was a problem with the USB interface - the front USB interface of the laptop was insufficient, so it was solved by replacing it with the rear interface. This seemingly simple question sometimes wastes a lot of time, so I hope it can help more people avoid pitfalls.
2. Compilation issues
Problem description: The project cannot be compiled, and various errors have occurred.
Solution:
- Check whether the toolchain is installed correctly
- Confirm that the chip model in the project settings matches the actual development board used
- Check if the compiler version is compatible with the project
- Recompile after cleaning the project
- Check if there are syntax errors in the code or references to non-existent files
Once, a student was studying my "STM32 Practical Quick Start" course, and he encountered the problem that he still failed to compile even though he followed the video step by step. After remote diagnosis, it was found that it was because he chose a different version of the compiler when installing Keil, which resulted in some syntax incompatible. This also reminds us that in embedded development, the version consistency of the toolchain is very important.
3. Debugging issues
Problem description: Cannot enter debug mode or interrupt the debugging process.
Solution:
- Check if the debugger connection is correct (SWD or JTAG interface)
- Confirm whether the power supply of the development board is stable
- Reduce the debug clock frequency
- Update the debugger firmware
- Check if there is any code that has disabled debugging (such as misconfiguring the clock or disabling the relevant pins)
Once when I was debugging a low-power application, the part of the code that was running into sleep mode would be disconnected. Later I found out that it was because the sleep mode disabled the debugging interface. The solution was to temporarily comment out the code entering sleep mode during debugging.
4. File path issues
Problem description: The header or source file cannot be found in the IDE.
Solution:
- Avoid using Chinese or special characters in project paths
- The project path should not be too long or too many levels
- Check if the included path in the project settings is correct
- Reference files using relative paths instead of absolute paths
This problem is especially common in Windows environments. My advice is to develop good habits, use pure English in project paths, avoid spaces, and reduce nesting depth.
5. Performance issues
Problem description: The IDE runs slowly, affecting development efficiency.
Solution:
- Turn off unnecessary plugins and features
- Increase virtual memory
- Regularly clean up projects and workspaces
- For older computers, consider using lighter options like PlatformIO instead of CubeIDE
I used to run Keil and STM32CubeIDE on a laptop with 8GB memory, and the computer got stuck like a PPT. The problem was only alleviated after upgrading to 16GB of memory. Therefore, if you are a heavy user of embedded development, you must pay attention to computer configuration.
5. Future trends of STM32 development environment
With the continuous development of embedded development, the STM32 development environment is also evolving. Here are some trends worth watching:
1. Cloud development and online IDE
With the popularity of cloud computing, online IDE is emerging. For example, Mbed Studio, Arduino Web Editor, etc. have already supported the development of some STM32 chips. The advantage of this method is that it does not require local installation of complex environments, but only needs a browser to develop. In the future, with the maturity of technologies such as WebUSB, it is possible to even realize fully online programming and debugging.
2. Container development environment
Container technologies such as Docker are changing the way software development is developed, and embedded development is no exception. Through a containerized development environment, we can ensure that team members use completely consistent toolchains and libraries to avoid the problem of "running on my computer".
3. AI-assisted development
With the development of artificial intelligence technology, AI-assisted programming is becoming a reality. The future STM32 development environment may integrate functions such as automatic code generation, intelligent error detection and optimization suggestions to significantly improve development efficiency.
4. Cross-platform unified experience
Developers are increasingly inclined to use a set of tools to complete development tasks on multiple platforms. The rise of PlatformIO is a reflection of this trend. In the future, we may see more unified development environments that support multi-platform and multi-chip.
5. Low-code/no-code development
For some common application scenarios, low-code or no-code development tools may emerge, allowing people with no programming background to quickly implement simple embedded applications. In fact, STM32CubeMX is already an early attempt at this concept.
6. My personal choices and suggestions
After years of embedded development experience, I have formed my own workflow:
- Prototyping and learning: Use STM32CubeIDE, which integrates the graphical configuration function of CubeMX, and can quickly build a prototype system.
- Complex projects and product development: Use IAR to pursue ultimate performance, or use PlatformIO to pursue development experience and cross-platform capabilities.
- Teaching and sharing: Use Keil as the main tool because it has the highest popularity and the richest learning resources. My "STM32 Practical Quick Start" course mainly uses Keil for this reason.
For developers at different stages, my advice is:
beginner: Starting with Keil, this is the least likely choice to have problems. Most of the tutorials and books on the market are based on Keil, and you can find the most reference materials.
Advanced: Try STM32CubeIDE and be familiar with the features of graphical configuration and modern IDE, which will greatly improve your development efficiency.
Professionals: Flexible choices according to project needs, and try to master a variety of development environments to enhance your adaptability.
Educator: Taking into account both mainstreamness and accessibility, mainly using Keil for teaching, but also introducing other options to let students understand the overall picture of the industry.
7. Summary: There is no best, only the most suitable
Looking back at the entire article, we discuss the various options for the STM32 development environment, their respective pros and cons, selection criteria, FAQs, and future trends. The most important conclusion is: there is no absolutely the best STM32 development environment, only the choice that is best for your current needs.
- Keil MDK: The most traditional, most popular, and rich in learning resources, suitable for beginners and teaching scenarios.
- STM32CubeIDE: Free, comprehensive features, official support, suitable for most intermediate developers and formal project development.
- IAR Embedded Workbench: The best performance, the strongest professionalism, suitable for high-demand commercial product development.
- PlatformIO + VSCode: The most modern, most flexible, with the best cross-platform support, suitable for teams and individuals who pursue development experience.
No matter which development environment you choose, the ultimate goal is to achieve your creativity and solve practical problems. Tools are always just means, don’t fall into the misunderstanding of “tool worship”. As I'm in"STM32 Practical Practical Quick Start" (click to go directly)As emphasized in the course, mastering core concepts and principles is more important than being familiar with specific tools, because tools may change, but the principles are consistent.
I hope this article can help you avoid detours in choosing STM32 development environment. Embedded development is a journey that is both challenging and fulfilling. Choosing the right tool is only the first step, and more importantly, continuous learning and practice. If you are learning STM32 development, please share your experiences and confusions.
Finally, no matter which development environment you choose, I hope you can go further and further on the road of embedded development and create more valuable works!