Usually, when implementing the IAP function, two project codes need to be written when designing the firmware program. The first project program, namely the BOOT program, does not perform normal functional operations, but only receives programs or data through a certain communication method ( such as USB , USART) to perform updates to the second part of the code; the second project program, namely the APP program, is the real functional code of the user. These two parts of the project code are burned into the Flash at the same time . When the chip is powered on, the first project program BOOT starts running first. It mainly implements the following functions:
1) Check whether the second APP program code needs to be updated
2) If no update is required, go to 4 )
3) Execute the update operation
4) Jump to the second part of the code execution
The first part of the BOOT code can be downloaded to the chip Flash through SWD or offline programmer , and the second part of the APP and the first part of the BOOT are burned into the chip together. In the future, if the program needs to be updated, it will be updated through the first BOOT code. According to the different address ranges of the Flash storage of the chip series , BOOT is stored from the lowest address area , followed by the APP program. This note is limited by the internal Flash capacity of the chip, and only one APP program is stored . That is, there are two programs inside the chip, namely BOOT and APP programs. The specific implementation of the IAP function generally starts from the Flash address 0x0000_0000 . Based on the Cortex-M0+ core characteristics, the internal interrupt vector table is used to respond to interrupts. The program takes out the reset interrupt vector from the interrupt vector table to execute the interrupt program. When an interrupt occurs, the chip's internal PC pointer is located in the interrupt vector table to take out the corresponding interrupt service program for execution. If no interrupt occurs, after the chip executes the reset interrupt service program, it jumps to the main function to execute an infinite loop in sequence. If an interrupt occurs, the corresponding interrupt service program is executed through the interrupt vector table. After adding IAP , the chip still takes out the reset interrupt vector from the interrupt vector table to execute the interrupt program. If no interrupt occurs, after the chip executes the reset interrupt service program, it jumps to the main function. After executing IAP , the reset interrupt vector address of the new program is 0x0000_0004 + BOOT program size, jumps to the reset vector table of the APP program, executes the reset interrupt service program of the APP , and then jumps to the main function of the APP program for execution. Among them: BOOT program size 3.5KB
Para area stores parameters and flags during IAP upgrade, occupying 0.5KB
APP program size is 24KB
Demo program, the operation process is as follows: first download the APP project HEX to the chip , open the BOOT project HEX and download it to the chip, or you can use the tool to merge the two HEX files together and download them to the chip. Use the host computer demonstration program and open the serial port baud rate to be fixed at 9600. According to the protocol, download the bin file of the APP project to the chip starting at 0x1000 , where the APP bin file is required to be less than 28KB . Reference samples and drivers Through the above introduction, using the demonstration Demo program IAP requires a specific protocol. The communication protocol format is as follows: ///*frame:68 A0 A1 C Page L0 L1 D0... DN-1 CRC0 CRC1 16*///
///*offset :0 1 2 3 4 5 6 7 8+N 9+N 10+N 11 +N*///
Header character: fixed character is 0x68 One-byte
address: A0 A1 Two-byte
control code C : read address is 0x15 write address is 0x25
Page address page : one byte represents the page to be operated
Length L0 L1 : two bytes L0 represents the high byte, L1 represents the low byte, the length here only represents the length of the data area
Data domain D0...DN-1 : represents the data read or written
Data check CRC : using CRC-16 method , represents the check of the data in the data domain.
End symbol: fixed character is 0x16. One byte
read instruction is as follows:
68 A0 A1 15 Page 0x00 0x00 CRC0 CRC1 16
Correct reply: 68 A0 A1 95 Page 0x04 0x00 D0 ………… D1023 CRC0 CRC1 16
Error reply 68 A0 A1 D5 Page 0x00 0x00 CRC0 CRC1 16
Page selection ( 0--27 ).
Read 1K bytes of data each time.
Write instruction is as follows:
68 A0 A1 25 Page 04 00 D0 ………… D1023 CRC0 CRC1 16
Correct reply: 68 A0 A1 A5 Page 04 00 CRC0 CRC1 16
Error reply 68 A0 A1 E5 Page 00 00 CRC0 CRC1 16
Page selection ( 0--27). )
Write 1K bytes of data each time.
Start IAP upgrade command
68 A0 A1 36 00 00 00 00 00 16
Correct reply 68 A0 A1 B6 00 00 00 00 00 16
Error reply 68 A0 A1 F6 00 00 00 00 00 16
End IAP upgrade command
68 A0 A1 49 00 00 00 00 00 16
Correct reply 68 A0 A1 C9 00 00 00 00 00 16
Error reply 68 A0 A1 09 00 00 00 00 00 16
Send data frame. If the time from sending to receiving is less than 2s, if it exceeds, it means IAP upgrade communication error.
The following section briefly introduces the key code for IAP implementation:
1 ) BOOT implementation jumps to APP code:
if(((*(__IO uint32_t*)appxaddr)&0x2FFE0000)==0x20000000) // Check whether the top address of the stack is legal
{
jump2app=(iapfun)*(__IO uint32_t*)(appxaddr+4); //APP program reset address
MSR_MSP(*(__IO uint32_t*)appxaddr); // Initialize APP stack pointer
jump2app(); // Jump to APP program
}
2 ) APP program interrupt vector offset:
new_vect_table EQU 0x00001000; Interrupt vector offset length
; reset Vector table address.
LDR R0, =0xE000ED08
LDR R2, =new_vect_table
STR R2, [R0] ; Vector table redefine click and drag to move
Summary
The above chapter briefly introduces the basic functions of the IAP control module of the HC32L110 series , and explains in detail the various functions and operation steps of the module. In the actual application development process, if the user needs to further understand the use and operation of the module, the HC32L110 user manual should prevail. The examples mentioned in this chapter can be used as further experiments and learning for users, and can also be directly applied in actual development.
|