Self-defined upgrading method of single chip microcomputer

文档序号:7208 发布日期:2021-09-17 浏览:43次 中文

1. A self-defined upgrading method of a single chip microcomputer is characterized in that: the method comprises the following steps:

the upper computer starts updating and upgrading;

pressing a BOOT key of the single chip microcomputer, and powering on the single chip microcomputer;

the upper computer sends the firmware leading frame to the single chip microcomputer, a bootstrap program area of the single chip microcomputer receives and verifies the firmware leading frame, and the firmware leading frame is stored in the memory after being verified correctly;

after the single chip microcomputer receives the firmware preamble frame, the upper computer continuously sends the data frame to the single chip microcomputer, a bootstrap program area of the single chip microcomputer continuously receives the data frame and checks the data frame, and the data frame is stored in a buffer area after the data frame is checked to be correct;

and after the firmware data frame is received, storing the data frame in the cache region into the memory of the single chip microcomputer, performing IAP programming, and operating the APP region to realize the upgrading of the single chip microcomputer.

2. The self-defined upgrading method of the single chip microcomputer according to claim 1, characterized in that: and after the single chip microcomputer completes the reception of the firmware leading frame and the data frame, feeding back the received information to the upper computer.

3. The self-defined upgrading method of the single chip microcomputer according to claim 1, characterized in that: the data received by the bootstrap area of the single chip microcomputer are specifically as follows:

when the singlechip is checked to receive the data, the data is stored in a buffer area; when a frame ending event is generated at regular time, carrying out data analysis and judging whether the frame is a firmware leading frame or a firmware data frame;

if the firmware is the leading frame, checking is carried out, and the initial address, the length and the check of the firmware are stored in the memory after the check is correct;

if the current frame is the data frame, checking, and storing the base address, the length and the check of the current frame into a memory after the check is correct, and storing the specific data of the current frame into a buffer area; and after all the firmware data frames are received, carrying out integral verification on the firmware data frames, storing the data of the buffer area into the memory after the verification is correct, carrying out IAP programming and operating the APP area.

4. The self-defined upgrading method of the single chip microcomputer according to claim 1, characterized in that: and when the singlechip receives the firmware leading frame and the data frame, the singlechip collects data sent by the upper computer by adopting an inquiry method.

5. The custom upgrading method of the single chip microcomputer according to any one of claims 1 to 4, characterized in that: the firmware preamble frame includes a feature byte and a check byte.

6. The self-defined upgrading method of the single chip microcomputer according to claim 5, characterized in that: the check bytes of the fixed leading frame comprise firmware and bytes, starting high address bytes, low address bytes, firmware length high address bytes, firmware length low address bytes and exclusive-or check value bytes.

7. The custom upgrading method of the single chip microcomputer according to any one of claims 1 to 4, characterized in that: the firmware data frame includes a feature byte, a check byte, and a data byte.

8. The custom upgrading method of the single chip microcomputer according to claim 7, characterized in that: the check bytes of the firmware data frame comprise high address bytes of a base address of the firmware of the frame, low address bytes of the base address of the firmware of the frame, high address bytes of the base address of the firmware of the frame, low address bytes of the firmware of the frame, check sum bytes of the firmware of the frame and exclusive or check value bytes.

Background

With the wide application of the single chip microcomputer technology, custom upgrading is more and more important, and generally, MCU manufacturers provide built-in BOOT programs (BOOTLOADER) for us, but the BOOT pins need to be controlled additionally or handshake through serial ports (or other interfaces) when the BOOT pins are powered on, and the BOOT programs enter after the handshake is successful, but the requirements on the timing and operation are strict, which is not beneficial to the operation. Moreover, the upgrading mode of the current manufacturer is that the protocol is received and upgraded at the same time and can not be defined by user, so that the defects that the success rate is not high due to no error in the upgrading process and the upgrading can not be carried out after the integral verification are difficult to avoid.

That is to say, the existing single chip microcomputer upgrading method is easy to make mistakes in the upgrading process, and the upgrading stability and safety are poor.

Disclosure of Invention

Aiming at the problems in the prior art, the invention aims to provide a self-defined upgrading method for a single chip microcomputer, which can effectively improve the stability and safety of upgrading.

In order to achieve the purpose, the invention adopts the technical scheme that:

a self-defined upgrading method of a single chip microcomputer comprises the following steps:

the upper computer starts updating and upgrading;

pressing a BOOT key of the single chip microcomputer, and powering on the single chip microcomputer;

the upper computer sends the firmware leading frame to the single chip microcomputer, a bootstrap program area of the single chip microcomputer receives and verifies the firmware leading frame, and the firmware leading frame is stored in the memory after being verified correctly;

after the single chip microcomputer receives the firmware preamble frame, the upper computer continuously sends the data frame to the single chip microcomputer, a bootstrap program area of the single chip microcomputer continuously receives the data frame and checks the data frame, and the data frame is stored in a buffer area after the data frame is checked to be correct;

and after the firmware data frame is received, storing the data frame in the cache region into the memory of the single chip microcomputer, performing IAP programming, and operating the APP region to realize the upgrading of the single chip microcomputer.

And after the single chip microcomputer completes the reception of the firmware leading frame and the data frame, feeding back the received information to the upper computer.

The data received by the bootstrap area of the single chip microcomputer are specifically as follows:

when the singlechip is checked to receive the data, the data is stored in a buffer area; when a frame ending event is generated at regular time, carrying out data analysis and judging whether the frame is a firmware leading frame or a firmware data frame;

if the firmware is the leading frame, checking is carried out, and the initial address, the length and the check of the firmware are stored in the memory after the check is correct;

if the current frame is the data frame, checking, and storing the base address, the length and the check of the current frame into a memory after the check is correct, and storing the specific data of the current frame into a buffer area; and after all the firmware data frames are received, carrying out integral verification on the firmware data frames, storing the data of the buffer area into the memory after the verification is correct, carrying out IAP programming and operating the APP area.

And when the singlechip receives the firmware leading frame and the data frame, the singlechip collects data sent by the upper computer by adopting an inquiry method.

The firmware preamble frame includes a feature byte and a check byte.

The check bytes of the fixed leading frame comprise firmware and bytes, starting high address bytes, low address bytes, firmware length high address bytes, firmware length low address bytes and exclusive-or check value bytes.

The firmware data frame includes a feature byte, a check byte, and a data byte.

The check bytes of the firmware data frame comprise high address bytes of a base address of the firmware of the frame, low address bytes of the base address of the firmware of the frame, high address bytes of the base address of the firmware of the frame, low address bytes of the firmware of the frame, check sum bytes of the firmware of the frame and exclusive or check value bytes.

After the scheme is adopted, the BOOT key is arranged, the BOOT key is pressed before power-on, then the mainboard is powered on, and the mainboard directly enters a bootstrap program state after detecting the pressed state of the key, so that the time sequence problem between an upper computer and a single chip microcomputer is not required to be considered, and the difficulty of handshaking can be greatly reduced. And when the single chip microcomputer receives the upgrade firmware file, before the firmware file is received, the data bytes of the firmware data frame are stored in the buffer area, and after the firmware file is received, the data in the buffer area is stored in the memory, and the IAP programming is carried out to upgrade the single chip microcomputer, so that errors in the upgrading process are avoided, and the upgrading safety and stability of the single chip microcomputer are improved.

Drawings

FIG. 1 is an overall flow chart of the present invention;

FIG. 2 is a transmission flow chart of the upper computer;

FIG. 3 is a flow chart of the program guide of the single chip microcomputer;

FIG. 4 is a circuit diagram of BOOT keys of the single chip microcomputer.

Detailed Description

As shown in fig. 1-3, the invention discloses a self-defined upgrading method for a single chip microcomputer, which guides handshake between an upper computer and the single chip microcomputer by pressing a BOOT key for a long time, enters an upgrading state, waits for all firmware to be received and is upgraded after verification is successful. The invention specifically comprises the following steps:

and step 1, connecting serial port lines of the upper computer and the single chip microcomputer, and starting updating.

And step 2, pressing a BOOT key of the single chip microcomputer, and powering on the single chip microcomputer. Fig. 4 is a circuit diagram of the BOOT key, in the diagram, the key s1 is the BOOT key, the BOOT key is pressed before the power-on, the main board is powered on, and the main board directly enters the BOOT program state after detecting the pressed state of the key, so that the timing sequence problem between the upper computer and the single chip microcomputer is not required to be considered, and the difficulty of handshaking can be greatly reduced.

And 3, the upper computer sends the firmware preamble frame to the single chip microcomputer, a bootstrap program area of the single chip microcomputer receives and verifies the firmware preamble frame, and the firmware preamble frame is stored in the memory after being verified correctly.

And 4, after the single chip microcomputer finishes receiving the firmware preamble frame, the upper computer continuously sends the data frame to the single chip microcomputer, the boot program area of the single chip microcomputer continuously receives the data frame and checks the data frame, and the data frame is stored in the buffer area after the data frame is checked to be correct.

And 5, after the firmware data frame is received, storing the data frame in the cache region into a memory of the single chip microcomputer, performing IAP programming, and operating an APP region to realize the upgrading of the single chip microcomputer.

In the above step 3 and step 4, the fixed leading frame and the firmware data frame together form a firmware, and the firmware is a file for upgrading the single chip microcomputer. In this embodiment, the firmware is a hex file. And after the singlechip finishes receiving the firmware leading frame and the data frame, feeding back the received information to the upper computer.

The firmware leading frame comprises a characteristic byte and a check byte, the characteristic byte is used for the single chip microcomputer to confirm that the firmware leading frame is a fixed leading frame, and the check byte contains the relevant information of the firmware and is used for the single chip microcomputer to check the received firmware data frame. In this embodiment, the format of the firmware preamble frame is as follows: the bytes 0 to 9 are fixed characteristic bytes, the specific values are 10 bytes in total, i.e., 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 and 0x99, the 10 byte is a firmware sum, the 11 byte is a start high address of the firmware, the 12 byte is a firmware low address, the 13 byte is a firmware length high address, the 14 byte is a firmware length low address, and the 15 byte is a parity or value of the previous 15 bytes. The 0 th byte to the 9 th byte may be set by themselves, and are not limited to the above-listed values.

The firmware data frame comprises a characteristic byte, a check byte and a data byte, wherein the characteristic byte is used for indicating that the type of the frame data is firmware; the check byte is used for checking whether the data is correct or not; the data bytes are used for upgrading the singlechip. In this embodiment, the format of the firmware data frame is as follows: 7+ N bytes, 7 bytes being fixed bytes, N bytes being specific data. The 0 th byte of the fixed byte of 7 bytes is a characteristic byte fixed to 0x46, and similarly, the value of the 0 th byte may be set by itself, and is not limited to the enumerated values. The 1 st byte is the high address of the base address of the firmware of the frame, the 2 nd byte is the low address of the base address of the firmware of the frame, the 3 rd byte is the high address of the length of the firmware of the frame, the 4 th byte is the low address of the firmware of the frame, the 5 th byte is the checksum of the firmware of the frame, and the 6 th byte is the exclusive or check value of the previous 6 bytes. The length value and the check value of the N-byte firmware data are determined by the corresponding contents of the fixed byte.

As shown in fig. 3, in step 3 and step 4, the bootstrap area of the single chip microcomputer collects data sent by the upper computer by using an inquiry method. The method comprises the following specific steps:

and inquiring a status register of the serial port every 500US, directly storing the data into a buffer area when detecting the change of the status bit, and generating a frame ending event when the MS does not receive the next data by more than 50. And then, carrying out data analysis to judge whether the frame is a firmware leading frame or a firmware data frame. If the firmware is the leading frame, corresponding verification is carried out, and the initial address, the length and the verification of the firmware are stored in the memory after the verification is correct. If the frame is a data frame, the previous 7 bytes of words are checked, the base address, the length and the check of the current firmware frame are stored into the memory after the check is correct, the data of the firmware frame with N bytes are stored into a buffer area, and the buffer area can be composed of an external EEPROM or FLASH. After receiving the complete firmware, the firmware can be integrally verified, and after the firmware is correctly verified, the data in the buffer area is stored in the memory of the single chip microcomputer, and then application programming (IAP programming) is performed. After the IAP programming is finished, the interrupt vector table of the APP area is remapped, if the single chip microcomputer supports the register to set the interrupt vector offset, the interrupt vector table is directly set, and if the register setting can not be supported, the interrupt jump address is remapped, so that the interrupt jump address can jump to the corresponding interrupt inlet of the APP area.

In summary, when the single chip microcomputer receives the upgrade firmware file, before the firmware file is received, the data bytes of the firmware data frame are stored in the buffer area, and after the firmware file is received, the data in the buffer area is stored in the memory, and the IAP programming is performed to upgrade the single chip microcomputer, so that errors are avoided in the upgrading process, and the safety and the stability of upgrading of the single chip microcomputer are improved.

The above description is only exemplary of the present invention and is not intended to limit the technical scope of the present invention, so that any minor modifications, equivalent changes and modifications made to the above exemplary embodiments according to the technical spirit of the present invention are within the technical scope of the present invention.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:计算机软件功能的动态扩充方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!