Follow+Star Public Account, don’t miss out on exciting content
Author | strongerHuang
WeChat Official Account | Embedded Column
In embedded development, aside from mastering basic programming syntax, the programming concepts are also critical. Here are two programming concepts.
The layered thinking in embedded systems might be unfamiliar to you, but you have definitely seen many software architecture diagrams similar to the ones below.
For example, the RT-Thread Nano kernel structure:
STM32Cube software structure:

These software architecture diagrams may contain a lot of information, and you might not fully understand them.
However, if you take a closer look at the division of each area, you will find that they divide the software into multiple regions, which actually reflects a kind of layered thinking.
For example:A remote control operates a small car, which includes the remote control buttons (for example: forward, backward, left, right), wireless communication (for example: 433), the car’s wireless receiver, motor drive, motor control algorithms, etc.
When faced with such embedded software development, how would you program?
For the car part: encapsulate motor drive (such as IO clock, PWM configuration) into a function, and encapsulate the 433 driver into another function. Then organize these two functions into a Driver function.
The remote control part is similar: encapsulate button driving (such as IO clock, configuration) into a function, and encapsulate the 433 driver into another function.
Here, for example, if your motor uses acceleration and deceleration, as well as left and right turning algorithms, encapsulate them into corresponding Middleware module functions (to be called by the application layer).
The application layer tests your business logic and integrates software resources. If you divide your code into layers, the business logic code becomes straightforward.
Conversely, if your code is messy, implementing a business logic may require working overtime for several days, and the final code will be filled with bugs.
Modularization in embedded programming is quite important; it can affect your code quality, the amount of overtime, and even promotions and salary increases.
Using the previous example:
A remote control operates a small car, which includes the remote control buttons (for example: forward, backward, left, right), wireless communication (for example: 433), the car’s wireless receiver, motor drive, motor control algorithms, etc.
If you write all the code in the main function, can it be implemented? Of course, it can be implemented.
However, if you write it this way, is your business logic code very cumbersome and time-consuming?
Moreover, if you later need to modify the button methods or add features, what will you do?
Thus, you need to program modularly, encapsulating some small modules into functions for the corresponding application layer to call.
As mentioned earlier: Motor drive (for example IO clock, PWM configuration) encapsulated into a function is actually a small module.
Of course, the driver function here is just a small module; it needs to be further encapsulated into a “large module”.
For instance: if I introduce an encoder here, to detect motor speed in a closed-loop manner, I can integrate the bottom motor drive, acceleration and deceleration algorithms, and encoder into a motor movement function (module): MOTOR_Ctrl(speed, direction). This is a large module (and can be further encapsulated based on requirements).
Finally, there are many important programming concepts that developers need to understand and master. To some extent, your programming concepts determine whether you are a novice or a master.
Reply ‘ Embedded Software Design and Development ‘ to read more related articles.
Welcome to follow my public account, reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.
Welcome to follow my video account:

Click “Read Original” to see more shares, welcome to share, collect, like, and view.