The IAP of embedded technology, since I have it, the boss no longer worries about my code! (superior)

1. A bitter lesson

It was a severe winter day, and the customer was using our company's newly developed equipment on site . The equipment was originally designed to allow a maximum of 20 temperature and humidity sensors to be connected, but due to the large space on site, the customer requested to connect 30 temperature and humidity sensors. This requirement modification is very simple, only need to modify a macro definition in the program. Because it involves the need to modify the program and update the program firmware, we require the customer to send the device back to our company to upgrade the firmware of the device, and then send the device to the customer to the test site. However, due to the urgent project schedule, the client thought that this solution would take a long time, and did not agree with this solution! In the end, our company's R&D and production worked overtime for 6 hours, and it was not until 12 o'clock in the evening that a set of equipment was rebuilt, and then the sales staff drove the new equipment to the customer overnight. Because of a small modification requirement, a lot of manpower and material resources were wasted, which is really a heavy lesson!
insert image description here
With this heavy lesson, I added the IAP function to the device program without hesitation. Since the device has the IAP function, we can update the firmware program of the field device at any time according to the needs , and we can realize ourselves from now on!
insert image description here

2. What is IAP

IAP (In-Application Programming) refers to in-application programming, which means that the MCU program firmware can obtain new code data and program some areas of Flash during operation, and overwrite the old program firmware with the new firmware program to realize program firmware upgrade . The purpose of IAP is to update and upgrade .

Why use the IAP function?
What benefits will the IAP function bring us?

insert image description here
IAP can bring us the following two benefits.
1. IAP can upgrade the product program firmware without dismantling the case.
Usually, the program download needs to use a dedicated download port (such as JTAG port). However, this interface is usually not reserved outside the device. If you need to update the program firmware of the device, you need to disassemble the device shell and use the downloader to connect Go to the device download port and download the program to the device.
insert image description here
For example, there are 100 devices on site. Due to new requirements from customers, it is necessary to upgrade the program firmware of the devices on site. When engineers come to the site, they first need to open the shells of 100 devices, then use the downloader to connect to the download port to upgrade the program firmware, and then install the shells of 100 devices.
Removing and installing the device case is a very tedious process, and sometimes it can even damage the device due to accidental operation (such as screw slippage or circuit board short circuit) ! If the device has IAP function, we can use the reserved serial port, USB port or network port of the device to upgrade the device program firmware. The program firmware update can be realized without dismantling the device shell, which saves time and effort, and also reduces the probability of problems.
insert image description here
2. IAP can remotely upgrade the device through the network.
If the device has 3G/4G, WIFI, NB and other network functions, IAP can use these network functions to realize remote device upgrades. For example, if the device has the IOT-NB function, we can use the server in the cloud to send the data to the device through the NB network to realize the remote firmware upgrade function of the device, without sending engineers to the site, saving time, effort and efficiency!
insert image description here

3. Working principle of IAP

The core function of IAP is: update program. So how does IAP implement the update program function, and what is the working principle of IAP?
insert image description here
Let's talk about an example in life first: the manufacturing process of diamond cutter heads. A high-strength, wear-resistant diamond head is usually welded to the head of the saw blade. This head is made of diamond powder through high temperature and high pressure in a hot press.
insert image description here
The process of temperature and pressure in the manufacturing process of hot press equipment determines the performance and quality of diamonds. For example, a simple process is: the temperature and pressure increase slowly when starting up, and reach a high temperature and high pressure state after a certain period of time, then maintain high temperature and high pressure for a period of time, and finally Slowly reduce temperature and pressure, this production process is called process curve control.
insert image description here
Assume that the customer needs a saw blade for sawing marble, and needs a high-strength saw blade, so it is necessary to modify the process curve of the diamond cutter head. First, the production director brings the curve process list, and the operator receives the curve process list, resets the process curve, and then restarts the equipment, thus completing the update of the process curve . There are three important parts in the process of updating the entire process curve:
1. The process curve parameters currently running by the equipment.
2. New process curve parameters provided by the production director.
3. Operators.

insert image description here
There are three important actions in the process of updating the process curve:
1. Distribution, the production director will pass the new process to the operators.
2. Replacement, production workers delete old process curves and input new process curves.
3. Restart, restart the machine after completing the input of new process parameters, and run the new process curve.

insert image description here
Back to the topic, when implementing the IAP function, it is usually necessary to write two project codes when designing the firmware program
:
1. The first project code does not perform user function operations(product function), but receive data through USB, USART or network port (APP code is the data), and update the second part of the code, we call this part of the code bootloader .
2. The second project code is the real function code (to realize the product function), we call this part of the code app (application program).

Both the bootloader and app codes are burned in Flash at the same time (different areas). When the chip is powered on, the bootloader code starts to run first, and then jumps and executes the app code . The general process is as follows:
1. Check whether the app needs to be updated. The code is updated, and if necessary, an app code update is performed.
2. Jump to the app code.
3. Run the app code.
insert image description here
Combined with the example of diamond cutter head , the IAP workflow can be compared as follows:
1. The bootloader is equivalent to the operator. The operator can receive new process parameters and update the process parameters; the bootloader can receive new program firmware and update the device program firmware.
2. The temperature is equivalent to the process parameters running in the equipment.
3. The new equipment is equivalent to the new process parameters.
4. Sending, corresponding to the external device, sending the new app program data to the bootloader.
5. For replacement, the corresponding bootloader writes the received app program data into the FLASH area corresponding to the app program.
6. Restart, after the corresponding bootloader completes the app update, jump and execute the app code.

insert image description here
According to the IAP workflow, the IAP function can be decomposed into the following three functions:
1. Data interaction, receiving data sent by external devices.
2. Data storage, write the received data into the memory.
3. Program jump, jump and execute APP.

The functions of the above three parts of IAP are called IAP three axes . Next, let’s see what details these three axes accomplish and how we realize them.
insert image description here

Creation is not easy, I hope friends will like, forward, comment, and follow!
Your likes, forwards, comments, and attention will be the driving force for my continuous updates!
CSDN: https://blog.csdn.net/li_man_man_man
Today's headlines: https: //www.toutiao.com/article/7149576260891443724

Guess you like

Origin blog.csdn.net/li_man_man_man/article/details/128260193
Recommended