Differences in Hardware Operations: MCU, Linux, and Android

I am Wei Dongshan, and I have been engaged in embedded Linux training for a long time. Recently, I plan to serialize a series of articles. I am recording a brand new embedded Linux video, using a new approach, starting no longer from bare metal/uboot, which is more efficient. The corresponding documentation will also be written into a book titled <> Second Edition.

Video documentation and draft of the book can be downloaded directly:

https://vdisk.weibo.com/s/t6HbuIpx6zoa1

1. Concept

As long as programming is involved and the hardware used is not a computer, it can be considered embedded software development. The so-called “embedded” means embedding the processor into a certain object, giving it computing capability.

For example, if a microcontroller is in a watch, then the watch is an embedded device, and the program developed for the microcontroller is embedded software; if a mobile phone has a powerful processor, it is also an embedded device. The mobile phone runs a Linux system, and Android runs on top of that Linux system. Both Linux and Android belong to embedded software.

The software or systems running on embedded devices can be divided into three categories: microcontrollers, large operating systems like Linux/WinCE, and GUI systems like Android/IOS/QT.

When developing products, we consider cost-effectiveness, using whatever is suitable, which requires us to have multifaceted development capabilities. This article will introduce the focuses of microcontrollers, Linux, and Android systems.

2. What Products Use These Three Technologies?

Differences in Hardware Operations: MCU, Linux, and Android

Differences in Hardware Operations: MCU, Linux, and Android

Differences in Hardware Operations: MCU, Linux, and Android

Differences in Hardware Operations: MCU, Linux, and Android

No single technology can be applied to all devices; often, they need to be combined. For example, drones require microcontrollers to handle various control events more quickly, Linux for better image processing and transmission, and an Android app for easier control on mobile devices.

3. Who Has More Job Opportunities?

We should let the data speak; see the chart below:

Differences in Hardware Operations: MCU, Linux, and Android

Surprisingly, there are actually the most jobs for Linux. This may be because internet products also use Linux, such as in virtualization, cloud computing, and cloud storage. These internet and cloud product companies have a huge demand for Linux developers, making it unfair to compare these positions with microcontroller positions.

So I further segment this data, extracting Linux positions related to hardware operations separately:

Differences in Hardware Operations: MCU, Linux, and Android

These statistics are somewhat rough, but they can illustrate some issues. I will create a bar chart:

Differences in Hardware Operations: MCU, Linux, and Android

Perhaps we can conclude that among hardware-related positions, microcontroller jobs are the most numerous, with embedded Linux positions being two-thirds of the microcontroller jobs. If we include Linux app positions, they would be the most numerous, which seems somewhat unfair, as Linux apps should be compared with Java and others. This demand for positions aligns with reality: a company typically has the least hardware positions, slightly more drivers, and the most apps. Often, several senior employees in app positions also handle driver tasks.

3.1 Microcontroller Job Opportunities Have the Lowest Threshold

The light switch, washing machine, refrigerator, microwave, and other small appliances around you all use microcontroller technology; your home wireless router and smart TV use Linux; and your mobile phone is either Android or Apple.

It can be roughly inferred that microcontroller job opportunities are more concentrated in the small appliance sector, with a relatively low threshold and limited technical advancement. Note that I said “technical advancement.” A few years ago, I made a statement that “learning microcontrollers has no future,” which was too extreme and received criticism from many. I have since revised it to “only learning microcontrollers has no future.”

Recently, a skilled individual taught me about CAN knowledge, which is primarily used in microcontroller programming, but Huawei could not lure him away with an annual salary of 800,000; he has just started learning Linux. He sent me two images:

Differences in Hardware Operations: MCU, Linux, and Android

Everyone, look at the images above. To earn a high salary, microcontroller engineers must delve into the industry and master core technologies. Otherwise, in terms of microcontroller technology alone, there is not much difference between 10 years of experience and 2 years of experience.

Working with microcontrollers allows one to master the entire program from top to bottom, knowing all the issues, which is comfortable but also means complacency and crisis.

With the advent of the 5G and IoT era, microcontrollers will have new developments, and I believe the focus will be on various RTOS and IoT standards.

3.2 Linux Positions Are Actually the Most Numerous

Before writing this article, I also tended to believe that microcontroller positions were the most numerous. However, after conducting a rough search on 51JOB, it turns out that Linux positions are indeed the most numerous, even when only counting “embedded Linux” positions, which have reached two-thirds of microcontroller positions. This may indicate an industrial upgrade in China, as everyone is no longer satisfied with using microcontrollers for simple functions but rather requires adding more and more dazzling features.

If you are an electronic engineer looking to engage in jobs closely related to “Linux drivers,” opportunities may be limited, as this requires experience. This is the awkward aspect of the industry: microcontroller engineers looking to switch jobs find that embedded Linux positions related to hardware programming are the most suitable, yet these positions place a high emphasis on experience; in reality, the easiest to find are Linux app development positions in electronic products.

There is a trend in small and medium-sized companies where a project is handed over to you, and your team is expected to complete everything from apps to drivers to hardware. Many people are multi-skilled.

Therefore, having multiple skills is advantageous; if you are an electronic engineer, mastering microcontrollers, Linux drivers, and Linux apps may significantly enhance your survival ability.

3.3 Android

The heat around Android has somewhat diminished; a small or medium-sized company without certain strength cannot really handle the Android system, as it is too large. Randomly configuring Bluetooth can take one or two months. Therefore, companies needing to use the Android system mostly purchase boards from solution companies, which help them modify the Android system. After purchasing the solution, these companies often focus on developing Android apps; those looking to study the Android system may find better opportunities at mobile manufacturers or solution companies. For instance, I know that a subsidiary of iFlytek uses the Rockchip series boards from Zhongshan Firefly.

4 How Do Microcontroller/Linux/Android Engineers Control Lights?

The schematic diagram for controlling an LED is shown below. By outputting a high or low level from a certain pin, the LED can be turned on or off.

Differences in Hardware Operations: MCU, Linux, and Android

4.1 How to Control Lights with Microcontrollers?

Differences in Hardware Operations: MCU, Linux, and Android

Simply put, the engineer needs to look at the schematic to determine which pin to use and what level to output to light the LED. Then they need to refer to the chip manual to determine how to operate the registers. Finally, they write the program.

As for the style of the program you write and how to name functions, it is entirely up to you. If other colleagues want to reuse your code later, they will have to look at your documentation or your code.

Currently, ARM is releasing some HAL standards, which specify some hardware operation function interfaces. If everyone adheres to these standards, apps on microcontrollers can be easily ported to other boards.

4.2 How to Control Lights with Linux?

Differences in Hardware Operations: MCU, Linux, and Android

In Linux, the driver is responsible for operating the hardware, and the app can call standard interfaces such as open and write to light the LED. When the app calls open, it triggers the led_open function in the driver; when the app calls write, it triggers the led_write function in the driver.

So, how is the driver written? The driver program must define functions like led_open and led_write. Before writing these functions, the driver engineer also needs to refer to the schematic and the chip manual, just like the microcontroller engineer.

Then, they provide these led_open and led_write functions according to Linux standards. Therefore, Linux driver = driver framework + hardware operation = driver framework + microcontroller knowledge. Why introduce the driver framework? Directly operating hardware is so straightforward and direct.

There are two reasons:

1. Specialization is key; do not let app developers look at schematics or chip manuals; they only need to call standard open, read, write, etc. interfaces to operate the hardware.

2. Software and hardware are isolated; no matter how the hardware changes, only the driver needs to be modified, and the app does not.

3.3 How to Control Lights with Android?

Differences in Hardware Operations: MCU, Linux, and Android

Android is a GUI system that runs on Linux, and hardware operations are completed by Linux. Thus, you can think of Android as a set of apps, which also access the driver through open and write interfaces to operate the hardware.

However, most programs in Android are written in Java, while these open and write are C language functions, so a layer needs to be introduced: JNI interface (Java Native Interface), which allows Java to call C functions.

5. How Do Microcontroller/Linux/Android Engineers Use LCDs?

Using light control as an example is too simple to highlight the differences between microcontrollers and Linux; however, the differences between Linux and Android seem minimal.

Next, we will explain using an LCD as an example.

5.1 LCD Operating Principles

Differences in Hardware Operations: MCU, Linux, and Android

Assuming the above image is an LCD screen, the densely packed black dots are called pixels. Each row has several dots. Imagine there is an electron gun located behind a pixel, firing red, green, and blue primary colors in various proportions to form any color. The electron gun moves while emitting various colors of light, moving from left to right. After reaching the right edge, it jumps to the start of the next line and continues moving from left to right, repeating this until it reaches the lower right pixel, and finally jumps back to the starting point.

Question 1: How does the electron gun move?

Answer: There is a pixel clock signal line (DCLK) connected to the screen. With each pixel clock signal (DCLK), the electron gun moves one pixel.

Question 2: How is the color emitted by the electron gun determined?

Answer: There are three sets of red, green, and blue signal lines (RGB) connected to the screen, which convey colors through these three sets of signal lines (RGB).

Question 3: When the electron gun reaches the right edge of the LCD screen, how does it know to jump to the start of the next line?

Answer: There is a horizontal sync signal line (HSYNC) connected to the screen. When it receives a horizontal sync signal (HSYNC), the electron gun jumps to the leftmost side of the next line.

Question 4: How does the electron gun know to jump back to the starting point?

Answer: There is a vertical sync signal line (VSYNC) connected to the screen. When it receives the vertical sync signal line (VSYNC), the electron gun jumps from the lower right corner of the screen to the upper left corner (starting point).

Question 5: How does the electron gun know that the color determined by the three signal lines (RGB) is what it needs?

Answer: There is an RGB data enable signal line (DE) connected to the screen. When it receives the data enable signal line (DE), the electron gun knows that the color determined by the three signal lines (RGB) is valid and can be emitted to that pixel.

The following image shows the block diagram of the development board, LCD controller, and LCD screen.

Differences in Hardware Operations: MCU, Linux, and Android

The previously mentioned pixel clock (DCLK), three sets of red, green, and blue signal lines (RGB), horizontal sync signal line (HSYNC), vertical sync signal line (VSYNC), and RGB data enable signal line (DE) are all emitted from the LCD controller. As long as the development board supports LCD display, it will certainly have an LCD controller.

Question 6: Where does the data on the three RGB signal lines come from?

Differences in Hardware Operations: MCU, Linux, and Android

The above image is the source block diagram of RGB data, where a portion of memory is allocated, referred to as the Framebuffer. In the Framebuffer, we will construct the color corresponding to each pixel. The values in the Framebuffer will be read by the LCD controller and sent to the electron gun through the three RGB lines. The electron gun then converts it into red, green, and blue colors to display on the screen. Each pixel on the screen has a corresponding storage space in the Framebuffer, which stores the color of the corresponding pixel on the screen.

The LCD controller will continuously read the color values of each pixel from the Framebuffer and send them to the electron gun while coordinating with DCLK, VSYNC, HSYNC, and DE signals.

In summary, the program needs to accomplish two things: set up the LCD controller and write data into the video memory.

5.2 How to Operate LCD with Microcontrollers?

Differences in Hardware Operations: MCU, Linux, and Android

Microcontroller programmers have very straightforward tasks:

1. Set up the LCD controller, which will automatically read each pixel’s data from the Framebuffer and send it to the LCD.

2. Place the text or images to be displayed into the Framebuffer.

5.3 How to Operate LCD with Linux?

Differences in Hardware Operations: MCU, Linux, and Android

In Linux, the driver is responsible for operating the hardware, and the app can call standard interfaces like open and ioctl to obtain LCD parameters and set the LCD. Then, using mmap, the app can get the address of the Framebuffer and fill it with data. As for the LCD controller’s setup, that is done by the driver.

So, how is the driver written? It initializes the LCD controller and provides functions like lcd_open, lcd_ioctl, and lcd_mmap, allowing the app to obtain LCD parameters, set parameters, and get the Framebuffer address. Thus, Linux driver = driver framework + hardware operation = driver framework + microcontroller knowledge. Why introduce the driver framework? Directly operating hardware is so straightforward and direct.

There are two reasons:

1. Specialization is key; do not let app developers look at schematics or chip manuals; they only need to call standard open, read, write, ioctl, mmap, etc. interfaces to operate the hardware.

2. Software and hardware are isolated; no matter how the hardware changes, only the driver needs to be modified, and the app does not.

5.4 How to Operate LCD with Android?

Differences in Hardware Operations: MCU, Linux, and Android

Android is a GUI system, similar to QT. In Android/QT and other GUI systems:

  1. LCD will be used by multiple apps. If not managed uniformly, it will definitely become chaotic;
  • 2. Therefore, there must be a management software, also known as service software:
    • 2.1 Apps construct their interfaces and submit them to the display service software.
    • 2.2 The display service software merges the final display image based on the layering of multiple apps.
    1. Finally, it calls the driver to display it.

    So, in the Android system, the focus is on display services, managing the layering, and destruction of multiple windows. Hardware operations are implemented by Linux.

    6 Conclusion

    I do not intend to spark a debate over the superiority of microcontrollers, Linux, or Android. I truly do not have high hopes for pure microcontroller software development, but I am optimistic about the application of RTOS and IoT in microcontrollers. Life is not easy, and neither is being a coder. Once you embark on the path of coding, continuous learning is the only way forward.

    ———————————-

    Having shared the insights, let’s move on to some benefits. June 18 is approaching, and the Baidu Q&A online learning platform is hosting a <> event. Groups of two or more can participate, and the discounts are quite significant. The original price of 800 for the Android video is now 699 for group purchases and 689 for group leaders. You understand, we rarely hold activities. This is a rare opportunity. Interested students should seize the time to purchase, as the event ends at 24:00 on June 19.

    Please scan the QR code below to participate in the group purchase and enjoy discounts:

    Differences in Hardware Operations: MCU, Linux, and Android

    Rules:

    Differences in Hardware Operations: MCU, Linux, and Android

    Welcome to add the group administrator’s WeChat to join the group and interact with Teacher Wei:

    Differences in Hardware Operations: MCU, Linux, and Android

    Our public account QR code:

    Differences in Hardware Operations: MCU, Linux, and Android

    Leave a Comment