Follow+Star Public Number, don’t miss out on exciting content
Arrangement | strongerHuang
WeChat Public Account | Embedded Column
The first “project” for embedded beginners is LED control. In this article, we’ll explore the differences between 51, STM32, and Linux LED control.
51 LED control is a popular choice for many microcontroller beginners, as it is relatively easy.
51 microcontroller development usually involves directly manipulating registers, such as P1_0 corresponding to the LED IO port.
Compared to 51 LED control, STM32 LED control is slightly more difficult due to the greater number of peripherals and the complexity of the startup files. Many beginners give up when they see it.
However, it is quite simple. Below, we will explore LED control through registers and the standard peripheral library, and you’ll understand.
Directly manipulating registers requires a deep understanding of the meaning of each bit in each register (not recommended for beginners to learn registers initially), and the source code can look quite extensive:
2. Standard Peripheral Library Version
The standard peripheral library is one where ST has encapsulated the registers, allowing you to directly call function interfaces.
Linux LED control is relatively more complex. Of course, if some pre-configured environments are available, it becomes simpler and easier. However, if you have to port the system step by step and write drivers, it can get quite complicated.
Here, we will take the wiringPi open-source library as an example:
-
Download U-boot source code, configure, and compile;
-
Download Linux kernel, configure, and compile (generally, development boards will have ready-made configuration files);
-
Create the root file system; (if you lack a certain Linux foundation, you can use one-click burning for the above three steps)
-
Port the open-source library WiringPi;
-
Check the circuit diagram to find the pin corresponding to the LED; the program needs to use the pin number;
-
Code, cross-compile;
-
Download and run.
Once the preparations are done, the source code for LED control is relatively simple:
2. Linux Driver LED Control
This method has the highest difficulty level among all LED control methods, covering embedded development from upper-level applications to lower-level drivers. The steps involve driver code writing, Linux kernel module addition, operating system porting, and Linux application programming.
Here, I will share the classic LED driver source code for mini2440:
After writing the driver, the application layer code is as follows:
LED control is fundamental. If you are engaged in embedded development, I believe these LED controls are the most basic first step.
The first step may be challenging, but once you take it, the next step will become easier.
Reply in the background 『Embedded Software Design and Development』『Microcontroller』『Linux』 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 the Original” to see more shares, feel free to share, bookmark, like, and view.