Single-chip microcomputer upgrading method based on CAN communication
By addressing the microcontroller equipment on the CAN bus and using on-demand or broadcast upgrade mode, the problem of low equipment identification and upgrading efficiency in the existing technology is solved, and the accurate upgrade and upgrade package retransmission of microcontroller equipment is achieved, and the upgrade is improved. Efficiency and accuracy.
Patent Information
- Application Number
- CN202411716198.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-01-10
AI Technical Summary
The existing Ethernet-based device on-demand upgrade method does not support broadcast upgrades, lacks the upgrade packet retransmission mechanism, and cannot upgrade multiple same microcontroller devices simultaneously, resulting in low upgrade efficiency and poor accuracy.
By addressing microcontroller devices on the CAN bus, giving each device a unique address, and using on-demand or broadcast upgrade mode, it supports checksum retransmission of the upgrade package to ensure that each microcontroller device can be correctly identified and upgraded.
It realizes unique identification and upgrade of microcontroller equipment, supports broadcast upgrades and retransmission of upgrade packages, improves upgrade efficiency and accuracy, and ensures that all devices can be upgraded in sequence and correctly.
Smart Images

Figure CN119292640A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a single chip microcomputer upgrading method, in particular to a single chip microcomputer upgrading method based on CAN communication. Background Art
[0002] The Ethernet-based device on-demand upgrade method can find the corresponding device along the line and upgrade it according to the given device name or device type. However, it uses network communication, does not support broadcast upgrades, lacks an upgrade package retransmission mechanism, and the hierarchical division is only to the device layer, rather than the smaller microcontroller layer.
[0003] CN111459526A provides a method for online upgrading of single-chip microcomputer based on CAN communication, which completes the program update of C8051F single-chip microcomputer through the commonly used CAN bus, and provides a new idea for upgrading single-chip microcomputer. In actual application, a device may contain multiple identical or different single-chip microcomputers. When a device along the line contains multiple identical single-chip microcomputers, due to the lack of unique identification, the above technical solution will be unable to correctly identify the single-chip microcomputer to be upgraded and upgrade its specific functions.
[0004] In addition, if multiple identical devices need to upgrade the same application, the upgrade client must be called manually multiple times, and it is not possible to upgrade all devices with a single call.
[0005] In order to solve the above problems, people have been seeking an ideal technical solution. Summary of the invention
[0006] The purpose of the present invention is to provide a single chip microcomputer upgrading method based on CAN communication in view of the deficiencies in the prior art.
[0007] In order to achieve the above object, the technical solution adopted by the present invention is: A first aspect provides a single chip microcomputer upgrade method based on CAN communication, comprising the following steps: Address the MCU devices on the CAN bus so that each MCU device has a unique device address to distinguish different MCUs; Receive upgrade parameters provided by the caller, wherein the upgrade parameters include upgrade mode, type of device to be upgraded, target device address of the device to be upgraded, and location of upgrade file, wherein the upgrade mode includes on-demand upgrade and broadcast upgrade; Get the upgrade file from the upgrade file location; When the upgrade mode is on-demand upgrade, on-demand upgrade is adopted according to the target device address, and the device to be upgraded is upgraded separately based on the upgrade file; When the upgrade mode is broadcast upgrade, the broadcast upgrade method is adopted according to the target device address, and all devices to be upgraded are upgraded based on the upgrade file.
[0008] In one embodiment of the first aspect, performing device addressing on a single-chip microcomputer device on a CAN bus comprises the following steps: Receive the addressing request sent by the first single-chip microcomputer device, set the device address for the first single-chip microcomputer device, and send device address setting success information to the first single-chip microcomputer device, so that the first single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success information; Receiving an addressing request sent by a non-first single-chip microcomputer device after power-on, setting a device address for the single-chip microcomputer device, and sending a device address setting success message to the single-chip microcomputer device, so that the single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Repeat the previous step until the last MCU addressing is completed and no new addressing request is received within the specified time, the device addressing is determined to be completed, and the number of MCU devices on the CAN bus is recorded; Among them, any single-chip microcomputer automatically sends an addressing request after power-on, and the first single-chip microcomputer device defaults to power-on mode.
[0009] In an embodiment of the first aspect, after acquiring the upgrade file from the location where the upgrade file is located, a complete CRC check code of the entire upgrade file is calculated; the upgrade file is split into N upgrade packages, and the CRC check code of each upgrade package is calculated respectively.
[0010] In an embodiment of the first aspect, the step of upgrading on demand includes: The single-chip microcomputer device that sets the target device address enters a synchronous waiting mode, wherein the synchronous waiting mode means that the single-chip microcomputer device no longer runs the original application program but is in a state of waiting for an upgrade; Send the description information of the i-th upgrade package to the single-chip microcomputer device at the target device address, where i=[1,N]; the upgrade package description information includes the upgrade program version number of this upgrade, the total number of upgrade packages, and the order of the upgrade packages currently sent; Send the i-th upgrade package to the MCU device at the target device address; After each upgrade package is sent, the MCU device receiving the target device address returns the CRC check code of the current upgrade package, the current upgrade package order and the upgrade program version number, searches for the corresponding built-in CRC check code according to the current upgrade package order and the upgrade program version number, and compares and verifies it with the received CRC check code. If the comparison and verification pass, continue to send the description information of the i+1th upgrade package and the i+1th upgrade package; if the comparison and verification fails, retransmit the current upgrade package; Repeat the above steps until the Nth upgrade package is sent. The complete CRC check code and upgrade program version number returned by the MCU device receiving the target device address are searched for the corresponding built-in complete CRC check code according to the upgrade program version number, and compared with the received complete CRC check code. If the comparison and verification pass, the MCU device is controlled to exit the synchronous waiting mode, and the MCU device is restarted to complete the on-demand upgrade. If the comparison and verification fails, it is determined that the upgrade has failed and the upgrade is manually performed again. Among them, after the single-chip microcomputer device at the target device address determines that all upgrade packages have been received according to the upgrade package description, it calculates the complete CRC check code of the complete upgrade file and returns the upgrade program version number and the complete CRC check code to the upgrade client.
[0011] In an embodiment of the first aspect, the step of broadcasting the upgrade includes: Broadcast a synchronous waiting command to all MCU devices at the target device address, so that all MCU devices along the line enter the synchronous waiting mode; Broadcasting the description information of the i-th upgrade package to all single-chip microcomputer devices at the target device address, where i=[1,N]; the upgrade package description information includes the upgrade program version number of this upgrade, the total number of upgrade packages, and the order of the upgrade packages currently sent; Broadcast the i-th upgrade package to all MCU devices at the target device address; After each upgrade package is sent, the CRC check code of the current upgrade package, the current upgrade package order and the upgrade program version number returned by the single-chip microcomputer devices of all target device addresses are received, and the corresponding built-in CRC check code is found according to the current upgrade package order and the upgrade program version number, and compared and verified with all the received CRC check codes respectively. If the comparison and verification pass, continue to send the description information of the i+1th upgrade package and the i+1th upgrade package; if the comparison and verification fails, the target device address and the upgrade program version number that failed the comparison and verification are recorded; Repeat the above steps until the Nth upgrade package is sent, obtain the complete CRC check code and upgrade program version number returned by the MCU devices of all target device addresses along the line, find the corresponding built-in complete CRC check code according to the upgrade program version number, and compare and verify it with all the received complete CRC check codes respectively; if the verification fails, record the target device address and upgrade program version number that failed the comparison and verification; According to the recorded target device address, the upgrade package of the single-chip microcomputer device that failed to be upgraded is individually upgraded on demand, wherein the upgrade packages upgraded on demand are all upgrade packages corresponding to the upgrade program version number of the failed upgrade; Control the devices along the line to exit the synchronization waiting mode, restart the devices along the line, and broadcast the upgrade completion.
[0012] A second aspect of the present invention provides a single chip microcomputer upgrading method based on CAN communication, comprising the following steps: Receive upgrade parameters provided by the caller, wherein the upgrade parameters include upgrade mode, type of device to be upgraded, target device address of the device to be upgraded, and location of upgrade file, wherein the upgrade mode includes on-demand upgrade and broadcast upgrade; Address the MCU devices on the CAN bus so that each MCU device has a unique device address to distinguish different MCUs; After each device addressing of a single-chip microcomputer device is completed, it is determined whether the device address is consistent with the target device address of the device to be upgraded. If they are consistent, the single-chip microcomputer device is determined to be the device to be upgraded, and the upgrade file is directly obtained from the location of the upgrade file. The device to be upgraded is upgraded on demand, and addressing of the subordinate devices of the device to be upgraded is stopped at the same time.
[0013] In one embodiment of the second aspect, performing device addressing on a single-chip microcomputer device on a CAN bus comprises the following steps: Receive the addressing request sent by the first single-chip microcomputer device, set the device address for the first single-chip microcomputer device, and determine whether the device address is consistent with the target device address of the device to be upgraded. If not, send a device address setting success message to the first single-chip microcomputer device, so that the first single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Receive an addressing request sent by a non-first single-chip microcomputer device after power-on, set a device address for the single-chip microcomputer device, and determine whether the device address is consistent with the target device address of the device to be upgraded. If not, send a device address setting success message to the single-chip microcomputer device, so that the single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Repeat the previous step until the device address set for a certain MCU device is consistent with the target device address of the device to be upgraded, and stop encoding; Among them, any single-chip microcomputer automatically sends an addressing request after power-on, and the first single-chip microcomputer device defaults to power-on mode.
[0014] The third aspect provides a single-chip microcomputer upgrading device, which is used to execute the single-chip microcomputer upgrading method based on CAN communication provided by the first aspect; or to execute the single-chip microcomputer upgrading method based on CAN communication provided by the second aspect.
[0015] The present invention has outstanding substantive features and significant progress compared to the prior art. Specifically, 1. Before upgrading, the present invention first addresses the single-chip microcomputer devices along the line. Since the addressing process is that the lower-level power supply will be turned on to address the next single-chip microcomputer only after the previous single-chip microcomputer is addressed, the addressing order is the actual connection order of the single-chip microcomputer devices, and each single-chip microcomputer has a unique corresponding address; when upgrading, a certain device or a certain single-chip microcomputer can be specified to upgrade a specific function according to the actual connection order of the single-chip microcomputer devices.
[0016] 2. Based on the CAN bus, all devices along the line can be upgraded at the same time by broadcasting. The upgrade client broadcasts the upgrade command, and the microcontroller device responds asynchronously with a delay according to its own address to ensure the stability of communication.
[0017] 3. During on-demand upgrade, if the upgrade package verification fails, the current upgrade package can be retransmitted immediately to ensure the correct sending of the upgrade file.
[0018] 4. During broadcast upgrade, the device address where the upgrade package fails to be sent can be automatically recorded. After the upgrade of other devices is completed, the single device can be upgraded again through on-demand mode to ensure the success of the broadcast upgrade. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is a flow chart of the single chip microcomputer upgrading method described in Example 1.
[0020] Figure 2 This is a schematic diagram of the line topology of a single-chip microcomputer described in Example 1.
[0021] Figure 3 This is a schematic diagram of the first along-line topology of the single-chip microcomputer described in Example 2.
[0022] Figure 4 These are the specific implementation steps for the on-demand upgrade described in Example 2.
[0023] Figure 5 This is a schematic diagram of the second along-line topology of the single-chip microcomputer described in Example 2. DETAILED DESCRIPTION
[0024] The devices connected to the bus can be divided into master devices and slave devices according to whether they have the ability to control the bus. The master device of the bus refers to the device that obtains the control right of the bus. The slave device of the bus refers to the device accessed by the master device, which can only respond to various bus commands sent by the master device. In view of the characteristics of device upgrades on the CAN bus, this application proposes a single-chip microcomputer upgrade method based on CAN communication. Before the upgrade, the single-chip microcomputer devices along the line are addressed. Based on the addressing, the single-chip microcomputers that need to complete specific functions can be upgraded on demand, and the functions of all single-chip microcomputers can also be upgraded using broadcast upgrades.
[0025] The technical solution of the present invention is further described in detail below through specific implementation methods.
[0026] Example 1 This embodiment provides a single chip microcomputer upgrade method based on CAN communication, which is applied to a main device and includes the following steps: Receive the upgrade parameters given by the caller, the upgrade parameters include the upgrade mode, the type of device to be upgraded, the target device address of the device to be upgraded and the location of the upgrade file, the upgrade mode includes on-demand upgrade and broadcast upgrade; wherein, the device address of each single-chip microcomputer device on the CAN bus is pre-addressed by the master device, and each single-chip microcomputer device has a unique device address.
[0027] Specifically, the master device addresses the single-chip device on the CAN bus, including the following steps: Receive the addressing request sent by the first single-chip microcomputer device, set the device address for the first single-chip microcomputer device, and send device address setting success information to the first single-chip microcomputer device, so that the first single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success information; Receiving an addressing request sent by a non-first single-chip microcomputer device after power-on, setting a device address for the single-chip microcomputer device, and sending a device address setting success message to the single-chip microcomputer device, so that the single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Repeat the previous step until the last MCU addressing is completed and no new addressing request is received within the specified time, the device addressing is determined to be completed, and the number of MCU devices on the CAN bus is recorded; Among them, any single-chip microcomputer automatically sends an addressing request after power-on, and the first single-chip microcomputer device defaults to power-on mode.
[0028] It is understandable that the CAN bus must have a master device and a slave device; for the addressing process, the master device should have the function of active addressing, and the slave device intelligently sends an addressing request and passively waits for the master device to set its address. And the master device should have the ability to power the lower-level single-chip device, that is, the slave device, that is, the master device (which is already powered) can directly power the slave device without any operation, without manual input to turn on the power supply of the slave device.
[0029] It should be noted that the first MCU is the first one in the actual MCU connection order, and because the addressing process is that the lower-level power supply will not be turned on to address the second MCU until the previous MCU is addressed, the specific addressing order is the actual MCU connection order.
[0030] like Figure 2The figure shows the topology diagram of the MCU line. It can be seen that it includes a master device and two sub-lines, namely CAN line 1 and CAN line 2. The device addresses of all MCU devices on CAN line 1 and CAN line 2 are the positions of the MCU devices in the actual connection sequence.
[0031] Among them, for slave MCU device A and slave MCU device D, the two MCU devices are connected to the master device in parallel and belong to two different lines under the master device. Therefore, their connection order is 1, so the device address is also 1, but one is device 1 on CAN line 1, and the other is device 1 on CAN line 2. The two MCU devices do not affect each other.
[0032] Obtain the upgrade file from its location.
[0033] Specifically, the corresponding upgrade file is searched and obtained according to the location of the upgrade file in the upgrade parameter. Generally, the upgrade file is a binary file.
[0034] After obtaining the upgrade file from the upgrade file location, calculate the complete CRC checksum of the entire upgrade file; Then the upgrade file is split into N upgrade packages, and the CRC check code of each upgrade package is calculated respectively.
[0035] When the upgrade mode is on-demand upgrade, on-demand upgrade is adopted according to the target device address, and the device to be upgraded is upgraded separately based on the upgrade file.
[0036] When the upgrade mode is broadcast upgrade, the broadcast upgrade method is adopted according to the target device address, and all devices to be upgraded are upgraded based on the upgrade file.
[0037] It can be understood that when the types of equipment along the line are various and the equipment that needs to be upgraded accounts for only a small number of the equipment along the line, the on-demand upgrade can be used to upgrade the designated equipment.
[0038] When the types of devices along the line are relatively uniform and most of them are of the same type, broadcast upgrade is used to uniformly upgrade the devices of the same type along the line.
[0039] It is understandable that for the scenario solved by broadcast upgrade, before the upgrade, the upgrade command is broadcast first, and each MCU device can respond asynchronously with a delayed response according to its own address to ensure the stability of communication.
[0040] Furthermore, when the upgrade client determines that there is a fault in the broadcast according to the delayed response of each single-chip device, it can also adopt the on-demand upgrade solution one by one, but the upgrade time is long and the single-chip devices need to be upgraded one by one.
[0041] It can be understood that since this embodiment has an addressing function, and the addressing is performed according to the actual microcontroller connection sequence, the connection number of the actual microcontroller can be directly specified during the upgrade to upgrade the device separately. The upgrade method is simpler and more flexible, and can cope with the upgrade of devices with special functions.
[0042] Example 2 This embodiment provides a specific implementation method for on-demand upgrade and broadcast upgrade of a single-chip microcomputer device.
[0043] For ease of understanding, this embodiment uses Figure 3 and Figure 4 Take the following as an example to explain the specific implementation steps of on-demand upgrade. Figure 5 Take the following as an example to explain the specific implementation steps of broadcast upgrade.
[0044] like Figure 3 As shown, there is a line under the main device, and there are 4 types of equipment in the line, represented by different shapes.
[0045] When it is necessary to upgrade the device whose device type is a triangle and whose device address is 3 along the first line of the master device, an upgrade parameter is sent to the master device, and the upgrade parameter includes: Upgrade mode: on-demand upgrade; Type of device to be upgraded: triangle; Target device address of the device to be upgraded: 3; Upgrade file location: The location where the V2 version of the application is located.
[0046] The master device receives the upgrade parameters given by the caller, obtains the upgrade file from the upgrade file location, and calculates the complete CRC checksum of the entire upgrade file. 总 ; and split the upgrade file into N upgrade packages, and calculate the CRC checksum of each upgrade package [CRC1, CRC2,…CRC N ], where the size of each upgrade package is 1024 bytes; at the same time, the microcontroller device of the target device address is set, that is, slave device 3 enters the synchronous waiting mode; Send the description information of the first upgrade package to the slave device 3, wherein the description information of the upgrade package includes the upgrade program version number V2 of this upgrade, the total number of upgrade packages N, and the order 1 of the currently sent upgrade package; Send the first upgrade package to slave device 3, and receive the information returned by slave device 3, the information format of which is [CRC1,1,V2]. Find the corresponding built-in CRC check code CRC1 according to the current upgrade package sequence 1 and the upgrade program version number V2, and compare and verify it with the received CRC check code. If the comparison and verification pass, continue to send the description information of the second upgrade package and the second upgrade package; if the comparison and verification fails, retransmit the current upgrade package; Repeat the above steps until the Nth upgrade package is sent and the MCU device receiving the target device address returns the complete CRC check code CRC 总 And the upgrade program version number V2, according to the upgrade program version number V2 to find the corresponding built-in complete CRC check code CRC 总 and compares it with the received complete CRC check code; if the comparison is successful, the MCU device is controlled to exit the synchronous waiting mode, and the MCU device is restarted to complete the on-demand upgrade; if the comparison fails, the upgrade is determined to have failed and is manually upgraded again.
[0047] It is understandable that during on-demand upgrade, if a certain upgrade package fails to be verified, the current upgrade package can be retransmitted immediately to ensure the correct sending of the upgrade file.
[0048] like Figure 4 As shown, there is a line under the main equipment, and there are 1 type of equipment in the line, all represented by circles.
[0049] When it is necessary to upgrade a certain application of all circular device types along the first line of the master device, and the upgrade version is V2, an upgrade parameter is sent to the master device, and the upgrade parameter includes: Upgrade mode: broadcast upgrade; Type of device to be upgraded: round; Target device address of the device to be upgraded: 1, 2, 3, 4, 5; Upgrade file location: The location where the V2 version of the application is located.
[0050] The master device receives the upgrade parameters given by the caller, and broadcasts a synchronization wait command to all MCU devices at the target device address, namely slave device 1 to slave device 5, so that slave devices 1 to 5 enter the synchronization wait mode; at the same time, the upgrade file is obtained from the location of the upgrade file, and the complete CRC checksum of the entire upgrade file is calculated. 总 ; and split the upgrade file into N upgrade packages, and calculate the CRC checksum of each upgrade package [CRC1, CRC2,…CRC N ], where each upgrade package is 1024 bytes in size.
[0051] Broadcast the description information of the first upgrade package to slave devices 1 to 5, where the upgrade package description information includes the upgrade program version number V2 of this upgrade, the total number of upgrade packages N, and the order 1 of the currently sent upgrade package; The first upgrade package is broadcasted to slave device 1-slave device 5, and the information returned by the broadcast from slave device 1-slave device 5 is received. The information is [CRC 11 ,1,V2],[CRC 21,1,V2],[CRC 31 ,1,V2],[CRC 41 ,1,V2],[CRC 51 ,1,V2]; where CRC 11 CRC is the CRC checksum of the first upgrade package from device 1. 21 CRC is the CRC checksum of the first upgrade package from device 2. 31 CRC is the CRC checksum of the first upgrade package from device 3. 41 CRC is the CRC checksum of the first upgrade package from device 4. 51 It is the CRC check code of the first upgrade package from device 5.
[0052] According to the current upgrade package sequence 1 and the upgrade program version number V2, find the corresponding built-in CRC check code CRC1 and compare it with the received CRC check code CRC 11 , CRC 21 , CRC 31 , CRC 41 , CRC 51 Perform comparison and verification. If any slave device fails the comparison and verification, the target device address and upgrade program version number of the failed comparison and verification are recorded; if the comparison and verification are all passed, the description information of the second upgrade package and the second upgrade package are continued to be sent; and the information broadcasted back from slave device 1 to slave device 5 is received, and the information is respectively [CRC 12 ,2,V2],[CRC 22 ,2,V2],[CRC 32 ,2,V2],[CRC 42 ,2,V2],[CRC 52 ,2,V2]; where CRC 12 CRC is the CRC checksum of the second upgrade package from device 1. 22 CRC is the CRC checksum of the second upgrade package from device 2. 32 CRC is the CRC checksum of the second upgrade package from device 3. 42 CRC is the CRC checksum of the second upgrade package from device 4. 52 It is the CRC check code of the second upgrade package from device 5.
[0053] According to the current upgrade package sequence 2 and the upgrade program version number V2, find the corresponding built-in CRC check code CRC2 and compare it with the received CRC check code CRC 112 , CRC 22 , CRC 32 , CRC 42 , CRC 52Perform comparison and verification. If any slave device fails the comparison and verification, the target device address and upgrade program version number of the failed comparison and verification are recorded; if the comparison and verification are all passed, continue to send the description information of the third upgrade package and the third upgrade package; Repeat the above steps until the Nth upgrade package is sent, and receive the complete CRC checksum returned by the MCU device of each target device address. 总 and the upgrade program version number V2, that is, the information is [CRC 1总 ,V2],[CRC 2总 ,V2],[CRC 3总 , V2],[CRC 4总 , V2],[CRC 5总 , V2], find the corresponding built-in complete CRC check code CRC according to the upgrade program version number V2 总 and compares it with the received complete CRC check code; if the comparison is successful, the MCU device is controlled to exit the synchronous waiting mode, and the MCU device is restarted to complete the on-demand upgrade; if the comparison fails, the target device address and upgrade program version number that failed the comparison are recorded.
[0054] Assuming that the comparison and verification of the above record from device 2 fails, the upgrade package of the single-chip microcomputer device that failed to upgrade, i.e., slave device 2, is upgraded on demand according to the recorded target device address, wherein the upgrade packages upgraded on demand are all upgrade packages of version V2.
[0055] It should be noted that for Figure 5 For each target device address in Figure 4 The processes are consistent, so no specific flow chart is given.
[0056] Furthermore, in order to reduce the upgrade amount during on-demand upgrade after the broadcast upgrade fails, when any slave device comparison verification fails, in addition to recording the target device address and upgrade program version number that failed the comparison verification, the current upgrade package order is also recorded. Therefore, after the broadcast upgrade fails, the corresponding upgrade package is obtained according to the recorded upgrade program version number of the failed upgrade and the current upgrade package order, and the upgrade package on-demand upgrade is performed separately for the single-chip microcomputer device that failed to upgrade according to the recorded target device address.
[0057] It can be understood that during broadcast upgrade, the device address to which the upgrade package fails to be sent is automatically recorded first. After the upgrade of other devices is completed, the single device can be upgraded again on demand, which can ensure the efficiency of broadcast upgrade.
[0058] Example 3 This embodiment provides a single-chip microcomputer upgrade method based on CAN communication. The difference between this embodiment and embodiment 1 is that when addressing reaches the specified single-chip microcomputer position, the single-chip microcomputer is directly upgraded, and subsequent devices of the single-chip microcomputer are no longer addressed.
[0059] Specific steps are as follows Figure 5 As shown below: Receive upgrade parameters provided by the caller, wherein the upgrade parameters include upgrade mode, type of device to be upgraded, target device address of the device to be upgraded, and location of upgrade file, wherein the upgrade mode includes on-demand upgrade and broadcast upgrade; Address the MCU devices on the CAN bus so that each MCU device has a unique device address to distinguish different MCUs; After each device addressing of a single-chip microcomputer device is completed, it is determined whether the device address is consistent with the target device address of the device to be upgraded. If they are consistent, the single-chip microcomputer device is determined to be the device to be upgraded, and the upgrade file is directly obtained from the location of the upgrade file. The device to be upgraded is upgraded on demand, and addressing of the subordinate devices of the device to be upgraded is stopped at the same time.
[0060] The device addressing of the microcontroller device on the CAN bus includes the following steps: Receive the addressing request sent by the first single-chip microcomputer device, set the device address for the first single-chip microcomputer device, and determine whether the device address is consistent with the target device address of the device to be upgraded. If not, send a device address setting success message to the first single-chip microcomputer device, so that the first single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Receive an addressing request sent by a non-first single-chip microcomputer device after power-on, set a device address for the single-chip microcomputer device, and determine whether the device address is consistent with the target device address of the device to be upgraded. If not, send a device address setting success message to the single-chip microcomputer device, so that the single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Repeat the previous step until the device address set for a certain MCU device is consistent with the target device address of the device to be upgraded, and stop encoding; Among them, any single-chip microcomputer automatically sends an addressing request after power-on, and the first single-chip microcomputer device defaults to power-on mode.
[0061] For ease of understanding, this application is Figure 3 Take this as an example to illustrate.
[0062] When it is necessary to upgrade the device whose device type is a triangle and whose device address is 3 along the first line of the master device, an upgrade parameter is sent to the master device, and the upgrade parameter includes: Upgrade mode: on-demand upgrade; Type of device to be upgraded: triangle; Target device address of the device to be upgraded: 3; The location of the upgrade file.
[0063] The master device receives the upgrade parameters given by the caller and starts device addressing; Specifically, receiving the addressing request sent by the first single-chip microcomputer device, setting the device address for the first single-chip microcomputer device, i.e., slave device 1, after judging that the device address of slave device 1 is inconsistent with the target device address of the device to be upgraded, sending device address setting success information to slave device 1, so that slave device 1 can turn on the power supply of slave device 2 after receiving the device address setting success information; Receive the addressing request sent by the slave device 2 after it is powered on, set the device address for the single-chip device, and after judging that the device address of the slave device 2 is inconsistent with the target device address of the device to be upgraded, send the device address setting success information to the slave device 2, so that the slave device 2 can turn on the power supply of the slave device 3 after receiving the device address setting success information; Receive the addressing request sent by the slave device 3 after it is powered on, set the device address for the single-chip device, and after judging that the device address of the slave device 3 is consistent with the target device address of the device to be upgraded, set the slave device to enter the synchronous waiting mode, at which time the slave device 3 will not turn on the power supply of the slave device 4; At the same time, obtain the upgrade file from the upgrade file location and calculate the complete CRC checksum of the entire upgrade file 总 ; and split the upgrade file into N upgrade packages, and calculate the CRC checksum of each upgrade package [CRC1, CRC2,…CRC N ], where each upgrade package is 1024 bytes in size.
[0064] Sending the description information of the first upgrade package to the slave device 3, wherein the upgrade package description information includes the upgrade program version number V2 of this upgrade, the total number of upgrade packages N, and the order 1 of the currently sent upgrade package; Send the first upgrade package to slave device 3, and receive the information returned by slave device 3, the information format of which is [CRC1,1,V2]. Find the corresponding built-in CRC check code CRC1 according to the current upgrade package sequence 1 and the upgrade program version number V2, and compare and verify it with the received CRC check code. If the comparison and verification pass, continue to send the description information of the second upgrade package and the second upgrade package; if the comparison and verification fails, retransmit the current upgrade package; Repeat the above steps until the Nth upgrade package is sent and the complete CRC checksum CRC returned by the microcontroller device of slave device 3 is received. 总And the upgrade program version number V2, according to the upgrade program version number V2 to find the corresponding built-in complete CRC check code CRC 总 and compares it with the received complete CRC check code; if the comparison is successful, the MCU device is controlled to exit the synchronous waiting mode, and the MCU device is restarted to complete the on-demand upgrade; if the comparison fails, the upgrade is determined to have failed and is manually upgraded again.
[0065] It is understandable that, during on-demand upgrade, if a certain upgrade package fails to be verified, the current upgrade package can be retransmitted immediately to ensure the correct sending of the upgrade file.
[0066] Compared with the upgrade method described in Example 1 and Example 2, in this embodiment, after upgrading one single-chip microcomputer, the next one can be upgraded only after addressing again and finding the corresponding single-chip microcomputer.
[0067] Example 4 This embodiment provides a single-chip microcomputer upgrading device, which is used to execute the single-chip microcomputer upgrading method based on CAN communication described in Embodiment 1, Embodiment 2 or Embodiment 3.
[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, ordinary technicians in the field should understand that the specific implementation methods of the present invention can still be modified or some technical features can be replaced by equivalents without departing from the spirit of the technical solution of the present invention, which should be included in the scope of the technical solution for protection of the present invention.
Claims
1. A single chip microcomputer upgrade method based on CAN communication, characterized in that: The following steps are involved: Receive the upgrade parameters given by the caller, the upgrade parameters include the upgrade mode, the type of the device to be upgraded, the target device address of the device to be upgraded and the location of the upgrade file, the upgrade mode includes on-demand upgrade and broadcast upgrade; wherein each single-chip microcomputer device on the CAN bus has a unique device address; Get the upgrade file from the upgrade file location; When the upgrade mode is on-demand upgrade, on-demand upgrade is adopted according to the target device address, and the device to be upgraded is upgraded separately based on the upgrade file; When the upgrade mode is broadcast upgrade, the broadcast upgrade method is adopted according to the target device address, and all devices to be upgraded are upgraded based on the upgrade file.
2. According to the CAN communication-based single-chip microcomputer upgrade method of claim 1, it is characterized in that: By addressing the MCU devices on the CAN bus, the unique device address of each MCU device is obtained; The device addressing of the microcontroller device on the CAN bus includes the following steps: Receive the addressing request sent by the first single-chip microcomputer device, set the device address for the first single-chip microcomputer device, and send device address setting success information to the first single-chip microcomputer device, so that the first single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success information; Receiving an addressing request sent by a non-first single-chip microcomputer device after power-on, setting a device address for the single-chip microcomputer device, and sending a device address setting success message to the single-chip microcomputer device, so that the single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Repeat the previous step until the last MCU addressing is completed and no new addressing request is received within the specified time, the device addressing is determined to be completed, and the number of MCU devices on the CAN bus is recorded; Among them, any single-chip microcomputer automatically sends an addressing request after power-on, and the first single-chip microcomputer device defaults to power-on mode.
3. A single chip microcomputer upgrading method based on CAN communication according to claim 1 or 2, characterized in that: After obtaining the upgrade file from the upgrade file location, calculate the complete CRC checksum of the entire upgrade file; The upgrade file is split into N upgrade packages, and the CRC check code of each upgrade package is calculated respectively.
4. The method for upgrading a single chip microcomputer based on CAN communication according to claim 3 is characterized in that: The steps for on-demand upgrade include: The single-chip microcomputer device that sets the target device address enters a synchronous waiting mode, wherein the synchronous waiting mode means that the single-chip microcomputer device no longer runs the original application program but is in a state of waiting for an upgrade; Send the description information of the i-th upgrade package to the single-chip microcomputer device at the target device address, where i=[1,N]; the upgrade package description information includes the upgrade program version number of this upgrade, the total number of upgrade packages, and the order of the upgrade packages currently sent; Send the i-th upgrade package to the MCU device at the target device address; After each upgrade package is sent, the MCU device receiving the target device address returns the CRC check code of the current upgrade package, the current upgrade package order and the upgrade program version number, searches for the corresponding built-in CRC check code according to the current upgrade package order and the upgrade program version number, and compares and verifies it with the received CRC check code. If the comparison and verification pass, continue to send the description information of the i+1th upgrade package and the i+1th upgrade package; if the comparison and verification fails, retransmit the current upgrade package; Repeat the above steps until the Nth upgrade package is sent. The complete CRC check code and upgrade program version number returned by the MCU device receiving the target device address are searched for the corresponding built-in complete CRC check code according to the upgrade program version number, and compared with the received complete CRC check code. If the comparison and verification pass, the MCU device is controlled to exit the synchronous waiting mode, and the MCU device is restarted to complete the on-demand upgrade. If the comparison and verification fails, it is determined that the upgrade has failed and the upgrade is manually performed again. Among them, after the single-chip microcomputer device at the target device address determines that all upgrade packages have been received according to the upgrade package description, it calculates the complete CRC check code of the complete upgrade file and returns the upgrade program version number and the complete CRC check code to the upgrade client.
5. The method for upgrading a single chip microcomputer based on CAN communication according to claim 3 is characterized in that: The steps for broadcast upgrade include: Broadcast a synchronous waiting command to all MCU devices at the target device address, so that all MCU devices along the line enter the synchronous waiting mode; Broadcasting the description information of the i-th upgrade package to all single-chip microcomputer devices at the target device address, where i=[1,N]; the upgrade package description information includes the upgrade program version number of this upgrade, the total number of upgrade packages, and the order of the upgrade packages currently sent; Broadcast and send the i-th upgrade package to all MCU devices with target device addresses; After each upgrade package is sent, the CRC check code of the current upgrade package, the current upgrade package order and the upgrade program version number returned by the single-chip microcomputer devices of all target device addresses are received, and the corresponding built-in CRC check code is found according to the current upgrade package order and the upgrade program version number, and compared and verified with all the received CRC check codes respectively. If the comparison and verification pass, continue to send the description information of the i+1th upgrade package and the i+1th upgrade package; if the comparison and verification fails, the target device address and the upgrade program version number that failed the comparison and verification are recorded; Repeat the above steps until the Nth upgrade package is sent, obtain the complete CRC check code and upgrade program version number returned by the MCU devices of all target device addresses along the line, find the corresponding built-in complete CRC check code according to the upgrade program version number, and compare and verify it with all the received complete CRC check codes respectively; if the verification fails, record the target device address and upgrade program version number that failed the comparison and verification; According to the recorded target device address, the upgrade package of the single-chip microcomputer device that failed to be upgraded is individually upgraded on demand, wherein the upgrade packages upgraded on demand are all upgrade packages corresponding to the upgrade program version number of the failed upgrade; Control the devices along the line to exit the synchronization waiting mode, restart the devices along the line, and broadcast the upgrade completion.
6. A method for upgrading a single-chip microcomputer based on CAN communication, characterized in that , including the following steps: Receive upgrade parameters provided by the caller, wherein the upgrade parameters include upgrade mode, type of device to be upgraded, target device address of the device to be upgraded, and location of upgrade file, wherein the upgrade mode includes on-demand upgrade and broadcast upgrade; Address the MCU devices on the CAN bus. Each MCU device has a unique device address. After each device addressing of a single-chip microcomputer device is completed, it is determined whether the device address is consistent with the target device address of the device to be upgraded. If they are consistent, the single-chip microcomputer device is determined to be the device to be upgraded, and the upgrade file is directly obtained from the location of the upgrade file. The device to be upgraded is upgraded on demand, and addressing of the subordinate devices of the device to be upgraded is stopped at the same time.
7. The method for upgrading a single chip microcomputer based on CAN communication according to claim 6, characterized in that: The device addressing of the microcontroller device on the CAN bus includes the following steps: Receive the addressing request sent by the first single-chip microcomputer device, set the device address for the first single-chip microcomputer device, and determine whether the device address is consistent with the target device address of the device to be upgraded. If not, send a device address setting success message to the first single-chip microcomputer device, so that the first single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Receive an addressing request sent by a non-first single-chip microcomputer device after power-on, set a device address for the single-chip microcomputer device, and determine whether the device address is consistent with the target device address of the device to be upgraded. If not, send a device address setting success message to the single-chip microcomputer device, so that the single-chip microcomputer device can turn on the power supply of its subordinate single-chip microcomputer device after receiving the device address setting success message; Repeat the previous step until the device address set for a certain MCU device is consistent with the target device address of the device to be upgraded, set the slave device to synchronous waiting mode, and stop encoding; Among them, any single-chip microcomputer automatically sends an addressing request after power-on, and the first single-chip microcomputer device defaults to power-on mode.
8. A method for upgrading a single chip microcomputer based on CAN communication according to claim 6 or 7, characterized in that: After obtaining the upgrade file from the upgrade file location, calculate the complete CRC checksum of the entire upgrade file; The upgrade file is split into N upgrade packages, and the CRC check code of each upgrade package is calculated respectively.
9. A method for upgrading a single chip microcomputer based on CAN communication according to claim 8, characterized in that: The steps for on-demand upgrade include: The single-chip microcomputer device that sets the target device address enters a synchronous waiting mode, wherein the synchronous waiting mode means that the single-chip microcomputer device no longer runs the original application program but is in a state of waiting for an upgrade; Send the description information of the i-th upgrade package to the single-chip microcomputer device at the target device address, where i=[1,N]; the upgrade package description information includes the upgrade program version number of this upgrade, the total number of upgrade packages, and the order of the upgrade packages currently sent; Send the i-th upgrade package to the MCU device at the target device address; After each upgrade package is sent, the MCU device receiving the target device address returns the CRC check code of the current upgrade package, the current upgrade package order and the upgrade program version number, searches for the corresponding built-in CRC check code according to the current upgrade package order and the upgrade program version number, and compares and verifies it with the received CRC check code. If the comparison and verification pass, continue to send the description information of the i+1th upgrade package and the i+1th upgrade package; if the comparison and verification fails, retransmit the current upgrade package; Repeat the above steps until the Nth upgrade package is sent. The complete CRC check code and upgrade program version number returned by the MCU device receiving the target device address are searched for the corresponding built-in complete CRC check code according to the upgrade program version number, and compared with the received complete CRC check code. If the comparison and verification pass, the MCU device is controlled to exit the synchronous waiting mode, and the MCU device is restarted to complete the on-demand upgrade. If the comparison and verification fails, it is determined that the upgrade has failed and the upgrade is manually performed again. Among them, after the single-chip microcomputer device at the target device address determines that all upgrade packages have been received according to the upgrade package description, it calculates the complete CRC check code of the complete upgrade file and returns the upgrade program version number and the complete CRC check code to the upgrade client.
10. A single chip computer upgrade device, characterized in that: Used to execute the single-chip microcomputer upgrade method based on CAN communication as described in any one of claims 1-5; or used to execute the single-chip microcomputer upgrade method based on CAN communication as described in any one of claims 6-9.
Citation Information
Patent Citations
Single-chip microcomputer online upgrading method based on CAN communication
CN111459526A
Cited By
Equipment batch upgrading method and system based on carousel, upgrader and medium
CN119806600A
Carousel-based Device Batch Upgrade Method, System, Upgrader and Medium
CN119806600B
Embedded software remote upgrading method based on CAN bus
CN121644359A