IAP technology helps STM32 update programs

introduction

The development of embedded systems ultimately requires downloading the compiled code to a specific microcontroller chip, and different manufacturers' microcontroller chips have different download methods. With the development of technology and the updating of application requirements, user program loading tends to be online programming. More and more chip companies provide and open interfaces and methods for user update programs to improve the reliability and maintainability of the entire system. Sex. ST's STM32 series based on the CortexM3 core has been widely used, and in many developments based on the STM32 series, user programs are inevitably loaded. Based on the introduction of the principle of IAP technology, this paper discusses in detail how to implement the online update function of users on STM32F103ZE chip, and analyzes the reasons why abnormalities may occur.

1 Background review

1.1 Main program update method

At present, in addition to the program update method directly through the emulator or the burner, there are mainly three methods of updating the bootloader technology, the ISP technology, and the IAP technology.

(1) Bootloader technology

The boot loader refers to the process performed by the controller to load a piece of code stored in an external non-volatile memory into an internal high-speed memory unit (such as on-chip RAM) when the system is powered up.

(2) ISP (In System Programming) technology

The MCU has its own bootloader, which is activated by the specified method and downloads or erases the user code through the communication interface. External intervention is required, static, and downloads when the user code is not running.

(3) IAP (In ApplicaTIon Programing) technology

The microcontroller has some rewritable non-volatile memory inside, such as Flash. When the microcontroller is running independently, the user downloads or erases his own code by communication using his own programming program. Note that a microcontroller that does not have an IAP function cannot modify the data of the Flash. No external intervention is required, dynamic, and downloads while the user code is running.

1.2 Introduction to STM32 Series

The STM32 family of microcontrollers is based on the CortexM3 core and has several improvements in its architecture, including the Thumb2 instruction set that improves code density while improving performance, and tightly coupled nested vectored interrupt controllers that greatly improve interrupt response. , which greatly increases the processing speed and reduces the system power consumption. Using the new kernel's Thumb2 instruction set, designers can reduce code size by 45%, halving the amount of memory required by applications. In addition, STM32 provides a wide range of peripheral interfaces, which are currently widely used in industrial and household safety equipment, fire and heating ventilation and air conditioning systems, as well as home appliances, consumer electronics, low-power portable devices. This article uses STM32F103ZE as an example to study and use IAP technology.

2 IAP technology

2.1 Principles of IAP Technology

Firstly, the internal storage of the MCU is divided into two parts: one is called the Boot area, which is used to store the IAP function program code, and the other is called the normal storage area, which is used to store all the program codes except the IAP function. The IAP technology means that the MCU continuously reads the program instructions that need to be executed through the program (PC) pointer while the MCU is running. Under normal circumstances, the PC pointer moves only in the normal storage area and reads the command, as shown in Figure 1. When the user needs to update or upgrade the program, the program instruction will jump to the Boot area. The function of the instruction code of the storage area is to receive the program data that the user needs to update by means of communication, and confirm that the received program data is correct after verification, and write the normal storage area according to the agreed manner, as shown in FIG. 2 Show. When the user program update is completed, the PC pointer jumps back to the normal storage area and starts executing the user program stored thereon, thus implementing the IAP function.

Read program instructions via PC pointer

Figure 1 Reading program instructions through the PC pointer Figure 2 Updating the memory area code

2.2 Key Points of IAP Technology

By studying the process of user program update by IAP technology, it is not difficult to find that the PC pointer must be moved in the Boot area during the update process, and cannot jump to the normal storage area at will. Based on this requirement, combined with the microcontroller principle, several key points that require special attention can be drawn.

(1) Disabling interrupts

Undoubtedly, the interrupt will cause the PC pointer to jump to the interrupt service routine entry address, so all interrupts need to be disabled before entering the Boot area.

(2) Disable the underlying peripheral interface

For some peripheral interfaces, such as when multi-channel A/D sampling is performed by ADC+DMA, the sampling process performs A/D sampling according to the preset channel sequence. If the PC pointer is not disabled before jumping to the Boot area, when the program jumps back to the normal storage area, the A/D channel value may be misplaced.

(3) Using a real-time operating system

If you use a preemptive RTOS (hard real-time operating system), you need to disable all tasks and block all semaphores and mailboxes to prevent a task from being activated, causing the PC pointer to jump to the normal storage area.

(4) Using a watchdog

When considering the cause of the PC pointer jump, the watchdog is easy to ignore, and many of the watchdogs cannot be disabled once they are enabled, so they cannot be achieved by disabling them. The safest way is to add a watchdog dog feed command in the Boot area. It is important to note that when it is necessary to erase and write a large amount of Flash data, it is necessary to quantitatively estimate the time required for the process, and if necessary, the dog can be fed multiple times in the process.

(5) Storage space allocation

The size of the Boot area and the normal storage area can be artificially allocated. In general, the normal storage area is maximized as much as possible, because the function of the product is embodied in the area; and the Boot area makes the code as simple as possible, avoiding interruptions and Complex underlying drivers and algorithms.

2.3 IAP technology implementation

(1) Turn off related interrupts and disable related peripheral interfaces

Such as timer interrupt, SysTIck interrupt, A / D interrupt, external I / O interrupt.

(2) Set the jump address

Typedef void (*pFuncTIon)(void);

INT32U JumpAddress; / / define the IAP entry address pFuncTIon Jump_To_Application; / / define the function pointer to the IAP entry address program

JumpAddress=*(vu32*)(IAP_ADDR + 4);

Jump_To_Application=(pFunction) JumpAddress;

(3) Feed the dog and perform a jump

IWDG_ReloadCounter();//feed the dog

__set_MSP(*(__IO uint32_t*) IAP_ADDR);//Initialize the stack pointer of the user application

Jump_To_Application();

(4) IAP code (Boot area code)

Only need to drive the underlying interface, try not to use interrupts, take up as little storage space as possible, and need to feed the dog at the right time. In addition, the Flash operation of this series will be different. For example, when STM32F103ZE performs an erase operation, one page is 2 KB, and one chip of SMT32F103VC6 is 1 KB. When using other types of chips, you need to refer to the relevant data manual.

3 Summary

This paper starts with the analysis of the principle of IAP technology, and discusses in detail the key points of using IAP technology to achieve user program update. In addition, it is conceivable that if the Boot Zone joins the TCP/IP protocol and connects to the Internet, the product can be upgraded online by means of the network, which not only improves the maintainability of the system, but also reduces the maintenance cost of the product, which will surely be obtained in the future. For a wide range of applications.

What is a wall GFCI socket?
A wall GFCI socket is different from conventional sockets. In the event of a ground fault, a wall GFCI socket will trip and quickly stop the flow of electricity to prevent serious injury.
Wall GFCI socket protect You From Electric Shock Due To:
1.With safe lock protection function,wall GFCI socket safety is improved.when miswired,wall GFCI sockets have no power and can not be reset,so it is more safe than conventional socket.
2.The wall GFCI socket includes end-of -life monitoring function,it can not reset correctly when the wall GFCI socket reaches the end of life.
3.Improved resistance to surge and corrosion.
4.Easier installation.(installation instructions enclosed)

Generator GFCI UL

Generator GFCI UL,Industrial Generator GFCI UL,Generator GFCI UL for Generator,No Load Generator GFCI UL

Hoojet Electric Appliance Co.,Ltd , https://www.hoojetgfci.com

Posted on