Application solidification is an important link in embedded product development and production process. The commonly used program solidification method of embedded system based on arm is to burn the program into flash through JTAG port. In the product development stage, it is almost inevitable to use the simulator. However, in the production stage, it is often the workers on the production line who burn or upgrade the application program. They are not easy to master the use method of the simulator, and they are in production The JTAG debug port should also be sealed to prevent the software from being peeped at. In the process of developing products with STM’s str730, a scheme of ISP (in system programming) through serial port is designed. The cost of the scheme is low, and the production line is very convenient to use. Even if the power failure occurs during the upgrade process, it will not affect the next upgrade, which is safe and reliable.
1. Hardware connection
The hardware connection of ISP scheme is shown in Figure 1. RS232 adapter board is used to convert RS232 level to TTL level, and through ISP_ The EN pin provides signal to arm development board to enter ISP state. PC runs isp.exe written in VC language. The program encrypts the. Bin file that needs to be burned into F1ash and sends it to arm development board. At the same time, it displays the progress prompt of burning to the user. The shadow part in Figure 1 has a fixed program.
2. Flash burning principle
2.1 memory allocation
Str730 is a microcontroller chip based on ARM7TDMI produced by Italian semiconductor. It has 16 KB RAM (0xa000000 ～ oxa0003fff) and 256 KB flash (ox80000 ～ ox8003fff). The allocation of built-in 256 KB flash is shown in Figure 2. The scatter file is written according to the memory allocation in Figure 2. When the executable file is generated, the linker will locate the relevant code segment to a specific address according to the content of the scatter file. In this case, the program starts from flash and does not use memory remapping, so the interrupt vector must be positioned to the start of the flash.
The contents of sector o need to be burned through JTAG port in advance. After that, the burning program programmer. O in sector o can be used to ISP through serial port. In the whole ISP process, the contents of sector 0 remain unchanged, so as to prevent accidents such as power failure in the ISP process, resulting in damage to the initialization code startup or the burning program programmer, and unable to perform ISP again.
Whether adding new functions to embedded products or modifying the original software bug, it only involves the change of user application program. The initialization code startup. S does not need to be changed. Therefore, whether the content of sector o remains unchanged in the ISP process depends on whether the vector. 0 generated by the first compilation always matches the app. O compiled many times later.
It should be pointed out that when the user application program changes, the actual interrupt service function (usually C language function) is likely to change, or the entry address of the actual interrupt service function changes. How to find the entry of the changed interrupt service function through the constant interrupt vector. O? As long as this problem is solved, the vector. O generated by the first compilation can always match the app. O compiled many times later, which is the key to the feasibility of the scheme. In order to solve this problem, the author makes an interrupt mapping table in the fixed position of flash (0x80002000 ~ 0x800020ff). In fact, there are jump instructions in it. Because the interrupt mapping table intmap. S and user application app. C are compiled and linked together, the jump instructions in the interrupt mapping table can of course find the actual interrupt service program entry accurately. Although the interrupt vector vector vector. S in sector o is not compiled with the user application program, the jump instruction in the interrupt vector is absolutely jump to the fixed interrupt mapping table area. In this way, the entrance of interrupt service program can be accurately found through two jumps.
As can be seen from Figure 3, the processing flow of fast interrupts is similar to that of other interrupts.
2.2 steps of ISP implementation
The author compiles and links the flash burning program as a project to generate a. Bin file, and then converts the. Bin file into an unsigned file Finally, use scatter file to locate programmer. O in a fixed address space (0x80001000 ~ ox8001fff, as shown in Figure 2). In this way, we can write an assembler, copy the burning program pro – grammer. O into RAM, and let PC pointer jump to ram to perform burning. Since there is no external flash in str730, it is necessary to copy programmer. O into RAM in order to burn flash program. The following code is taken from startup. S.
The software flow of burning program program is shown in Figure 4.
It should be noted that:
① Erasing flash is not completely erasing, but erasing other sectors except sector 0;
② The data buffer is limited, only the specified size data is received each time, so the receiving and burning can be carried out in parallel, which improves the speed of ISP;
③ In order to improve the security of the software, the original. Bin file is encrypted, and the original data needs to be decrypted before burning.
This method described in this paper has been used in the actual development and production process. Practice has proved that compared with other flash burning methods, it has many advantages, such as low cost, simple hardware connection, convenient operation, enhanced software security and so on. The MCU used by the author is str730. With a little modification, this ISP method can be extended to other MCU of arm architecture.
Editor in charge: GT