51 MCU engineers share their own arm development experience

I've seen a lot of friends discussing in the forums about electrical engineering design, specifically asking: "How do I learn to learn?" In this article, Xiaobian introduces an engineer who has experience in "Single-chip and Embedded System Applications" and shares his practical insights.

2.png

Initially, I worked with 51 microcontrollers using C51. I had over ten years of experience with the C language but used it very little. Later, I transitioned to ARM due to project requirements. At first, I knew nothing about ARM. I read "ARM Architecture and Programming," but it was quite confusing. However, perhaps because I was fearless, I just created a project in MDK, added the built-in startup file, and wrote a main function that ran in an infinite loop without interacting with any hardware. To my surprise, it actually worked. Then, based on that foundation, I gradually started controlling GPIO and serial communication. I realized that I wasn't really doing anything complicated—what were those other operating modes, link registers, or PC registers? I didn't care. As long as I could control the peripherals, I was satisfied. How it was implemented was up to the compiler and linker.

Looking back now, developing for ARM seems much simpler than I once thought. Especially with MDK, you can do basic development easily. Don't get confused by all the strange details. Learn while you develop, and as your projects become more complex, everything will start to make sense naturally. Our company has a new colleague, and I usually ask him to do simple tasks like buttons or serial ports. He almost always manages to complete them.

Luo Wei shared several suggestions after talking for so long:

  1. There's no need to be proficient in ARM assembly. You just need to understand it enough to read it when debugging. If performance is critical and you need to use assembly, what you should focus on is changing your mindset and optimizing algorithms—for example, using lookup tables instead of calculations. I’ve been working with ARM for five years and completed many projects, and I haven’t written a single line of assembly yet.
  2. Because of real-time and cost constraints in industrial control, I usually don’t use an operating system. Instead, I implement memory management, event management, mailboxes, etc. These things take time to accumulate. I usually write code with generalization in mind and build my own libraries, which makes things much easier later. I’ve used some OS before, but I found it didn’t speed up my development—it only caused bugs that were hard to track down.
  3. If your project requires an OS, network, GUI, or file system, it’s better to buy a ready-made board. Everything is already done, and there are fewer bugs. If you're doing a large volume, you can customize it and calculate the development cost—it might even be cheaper. If you're personally interested, then that's another story.
  4. Now there are pre-built libraries for peripherals. I suggest not using them—or at least not relying on them too much. To use them well, you must understand the peripheral registers. At that point, writing your own code is often simpler. A basic register assignment is usually sufficient, and many function libraries require calling multiple functions, which can be overkill. However, for computational libraries like DSP, it's still better to use them since they are optimized for performance.
  5. Use interrupts wherever possible. This applies to both 51 and ARM. There's absolutely no need to poll for events that can be handled via interrupts. Interrupts are the soul of a microcontroller, and your entire program should revolve around them.
  6. Learn C well, and develop your own programming style from the beginning. Start with function names and variable names, and write comments. Don't be afraid of being thorough—these are crucial. I believe the best code style is one where you can understand the program immediately without reading the comments—the code itself is the comment. Sometimes I write things like `a = b - 2 - 1` instead of `a = b - 3`. It may seem silly, but 2 and 1 represent specific values, and writing 3 directly would make it harder to understand. The compiler will optimize it anyway.
  7. If you're working with C, master pointers. If interrupts are the soul of a microcontroller, then pointers are the soul of C.

In short, working with ARM is almost the same as working with 51. The key lies in understanding and manipulating peripheral registers.

Aivono AIM MAGIC 20000

YIWU JUHE TRADING COMPANY , https://www.nx-vapes.com