A dual single-chip program upgrading system and method

The system and method for upgrading programs using dual microcontrollers utilizes the RS-485 interface to achieve safe and convenient upgrades for multiple microcontrollers. This solves the problems of cumbersome, costly, and insecure program upgrades in existing technologies and is applicable to MCU systems with communication interfaces such as RS-485, CAN, and Ethernet.

CN122240145APending Publication Date: 2026-06-19JIANGSU EASTONE TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JIANGSU EASTONE TECH
Filing Date
2025-12-22
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

In the existing technology, the program upgrade process for multiple microcontroller devices is cumbersome, prone to damaging the device, costly, and has poor security. It is impossible to achieve safe and convenient program upgrades through a single external interface.

Method used

The dual-microcontroller program upgrade system and method utilizes the RS-485 external communication interface to send upgrade-related information to the first microcontroller, generate activation commands to switch communication states, perform mode control on the second microcontroller, and transmit external upgrade tools in data pass-through mode to complete the program upgrade and restore it to the corresponding state.

Benefits of technology

It enables multi-microcontroller program upgrades without disassembling equipment, is easy to operate, and has high security, saving costs. It is suitable for serial communication interfaces such as RS-485, CAN, and Ethernet, and is widely used in various MCU systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122240145A_ABST
    Figure CN122240145A_ABST
Patent Text Reader

Abstract

A dual-microcontroller program upgrade system and method includes: sending upgrade-related information to a first microcontroller to enable it to upgrade its program; generating an activation command for a second microcontroller, and according to the activation command, switching the communication state of the first microcontroller and controlling the mode of the second microcontroller; transmitting an external upgrade tool to the second microcontroller when the first microcontroller is in a data pass-through state; upgrading the second microcontroller based on the data received by the second microcontroller and the external upgrade tool; and restoring the first and second microcontrollers to their respective states upon completion of the upgrade. Through a single RS-485 external communication interface, the system can sequentially upgrade the programs of the two microcontrollers within the device, eliminating the need for physical disassembly, simplifying operation, and ensuring high security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of embedded systems, and more particularly to a program upgrade system and method for dual microcontrollers. Background Technology

[0002] In complex electronic devices such as industrial controllers, communication modules, and power supplies, a multi-microcontroller collaborative framework is often used. For example, one microcontroller is responsible for the main business logic and external communication, while another microcontroller is responsible for proprietary functions such as motor drive and precision sampling. These devices typically only reserve one external communication interface (such as RS-485, CAN, UART-USB) for debugging and upgrades, and these communication interfaces are generally directly connected to the main microcontroller by default. When it is necessary to upgrade the programs of multiple microcontrollers, the following difficulties are encountered: First, physical disassembly is required, which requires opening the device casing, locating the microcontroller's programming interface, and using dedicated programming for the upgrade, a cumbersome process that can easily damage the device; Second, interface reservation is inconvenient, as reserving separate external upgrade interfaces for each microcontroller increases connector costs, occupies space, and reduces the device's protection level; Third, security is poor, as directly exposing the internal programming interface poses a risk of unauthorized access. Therefore, a solution is needed that allows for safe and convenient program upgrades of all internal microcontrollers without disassembling the device, using only a single external interface. Summary of the Invention

[0003] The purpose of this invention is to provide a program upgrade system and method for dual microcontrollers. The system sends upgrade-related information to the first microcontroller to enable it to upgrade its program. It generates an activation command for the second microcontroller, which, based on the activation command, causes the first microcontroller to switch its communication state and controls the mode of the second microcontroller. When the first microcontroller is in a data pass-through state, it transmits an external upgrade tool to the second microcontroller. Based on the data received by the second microcontroller and the external upgrade tool, the second microcontroller is upgraded. When the second microcontroller completes its upgrade, the first and second microcontrollers are restored to their respective states. Through a single RS-485 external communication interface, the system can sequentially upgrade the programs of the two microcontrollers within the device without physical disassembly, offering ease of operation and high security.

[0004] The objective of this invention is achieved through the following technical solution: A program upgrade system for dual microcontrollers, comprising: The first upgrade processing module is used to send upgrade association information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade. The mode change module is used to generate an activation command for the second microcontroller, and according to the activation command, to switch the communication state of the first microcontroller and to perform mode control on the second microcontroller. The transmission control module is used to transmit external upgrade tools to the second microcontroller when the first microcontroller is in a data pass-through state. The second upgrade processing module is used to upgrade the second microcontroller based on the data received by the second microcontroller and the external upgrade tool; The state recovery module is used to restore the first microcontroller and the second microcontroller to their respective states when the second microcontroller completes the upgrade.

[0005] In one embodiment, the first upgrade processing module is used to send upgrade association information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade, including: The external upgrade tool is instructed to send standard upgrade commands and upgrade data packets to the first microcontroller via the RS-485 interface, which serves as upgrade association information. The standard upgrade command received by the first microcontroller is verified. If the verification is successful, the standard upgrade process is executed according to the upgrade data packet to complete the update of the first microcontroller's own program. The standard upgrade process includes jumping to the built-in bootloader. After the first microcontroller completes the program update, it is instructed to reset and run the updated program.

[0006] In one embodiment, the mode change module is used to generate an activation instruction for the second microcontroller, and according to the activation instruction, to switch the communication state of the first microcontroller and to perform mode control on the second microcontroller, including: The external upgrade tool is instructed to generate an activation command for the second microcontroller via the RS-485 interface; wherein the activation command includes a function code or a password; The activation command is verified. If the verification is successful, the communication state of the first microcontroller is switched from "self-upgrade mode" to "second microcontroller upgrade gateway mode". The program upgrade circuit controls its own GPIO pin to output a high level, thereby driving the BOOT0 pin of the second microcontroller, so that the second microcontroller enters the system memory boot mode when it is reset next time. A reset signal is sent to the second microcontroller to restart it and enter ISP programming mode.

[0007] In one embodiment, the transmission control module is used to transmit external upgrade tools to the second microcontroller when the first microcontroller is in a data pass-through state, including: When the first microcontroller is in data pass-through mode, it switches to a transparent data bridge connector, thereby forwarding the data from the RS-485 interface to the second microcontroller in ISP programming mode through the internal UART interface without modification, and thus forwarding the external upgrade tool from the RS-485 interface to the second microcontroller.

[0008] In one embodiment, the second upgrade processing module is used to upgrade the second microcontroller based on data received by the second microcontroller and an external upgrade tool, including: The second microcontroller identifies the virtual serial port connected to it based on the external upgrade tool received by the second microcontroller, thereby completing the program download and burning of the second microcontroller and upgrading the program of the second microcontroller. The state recovery module is used to restore the first and second microcontrollers to their respective states when the second microcontroller completes the upgrade, including: When the second microcontroller completes the program upgrade, a "Exit Transparent Transmission" command is sent to the second microcontroller. This is done by controlling the GPIO pin of the program upgrade circuit to output a low level, pulling the BOOT0 pin of the second microcontroller low, resetting the second microcontroller, so that it exits the ISP programming mode and runs the upgraded program normally. Control the first microcontroller to exit the "second microcontroller upgrade gateway mode" and re-parse its own application layer protocol.

[0009] A method for upgrading the program of dual microcontrollers, comprising: Send upgrade association information to the first microcontroller to enable the first microcontroller to upgrade its program; An activation instruction is generated for the second microcontroller. Based on the activation instruction, the first microcontroller switches its communication state, and the second microcontroller is subjected to mode control. When the first microcontroller is in data pass-through mode, it transmits external upgrade tools to the second microcontroller. Based on the data received by the second microcontroller and the external upgrade tool, the second microcontroller is upgraded; when the second microcontroller completes the upgrade, the first microcontroller and the second microcontroller are restored to their respective states.

[0010] In one embodiment, sending upgrade association information to a first microcontroller to enable the first microcontroller to perform a program upgrade includes: The external upgrade tool is instructed to send standard upgrade commands and upgrade data packets to the first microcontroller via the RS-485 interface, which serves as upgrade association information. The standard upgrade command received by the first microcontroller is verified. If the verification is successful, the standard upgrade process is executed according to the upgrade data packet to complete the update of the first microcontroller's own program. The standard upgrade process includes jumping to the built-in bootloader. After the first microcontroller completes the program update, it is instructed to reset and run the updated program.

[0011] In one embodiment, an activation instruction is generated for the second microcontroller. Based on the activation instruction, the first microcontroller switches its communication state, and mode control is performed on the second microcontroller, including: The external upgrade tool is instructed to generate an activation command for the second microcontroller via the RS-485 interface; wherein the activation command includes a function code or a password; The activation command is verified. If the verification is successful, the communication state of the first microcontroller is switched from "self-upgrade mode" to "second microcontroller upgrade gateway mode". The program upgrade circuit controls its own GPIO pin to output a high level, thereby driving the BOOT0 pin of the second microcontroller, so that the second microcontroller enters the system memory boot mode when it is reset next time. A reset signal is sent to the second microcontroller to restart it and enter ISP programming mode.

[0012] In one embodiment, when the first microcontroller is in a data pass-through state, transmitting an external upgrade tool to the second microcontroller includes: When the first microcontroller is in data pass-through mode, it switches to a transparent data bridge connector, thereby forwarding the data from the RS-485 interface to the second microcontroller in ISP programming mode through the internal UART interface without modification, and thus forwarding the external upgrade tool from the RS-485 interface to the second microcontroller.

[0013] In one embodiment, the second microcontroller is upgraded based on data received by the second microcontroller and an external upgrade tool; when the second microcontroller completes the upgrade, the first microcontroller and the second microcontroller are restored to their respective states, including: The second microcontroller identifies the virtual serial port connected to it based on the external upgrade tool received by the second microcontroller, thereby completing the program download and burning of the second microcontroller and upgrading the program of the second microcontroller. When the second microcontroller completes the program upgrade, a "Exit Transparent Transmission" command is sent to the second microcontroller. This is done by controlling the GPIO pin of the program upgrade circuit to output a low level, pulling the BOOT0 pin of the second microcontroller low, resetting the second microcontroller, so that it exits the ISP programming mode and runs the upgraded program normally. Control the first microcontroller to exit the "second microcontroller upgrade gateway mode" and re-parse its own application layer protocol.

[0014] Compared with the prior art, the present invention has the following beneficial effects: The dual-microcontroller program upgrade system and method provided in this application have the following advantages: First, the external interface is extremely simple. The upgrade of all internal microcontrollers can be completed using only the original RS-485 interface of the device. There is no need to reserve additional interfaces, which saves costs and maintains the integrity of the device. Secondly, it is easy to operate, requiring no disassembly. All components can be upgraded with one click through the host computer software at the equipment installation site, greatly reducing maintenance difficulty and time costs. Third, it has high security. It uses a specific activation command as a switch to prevent accidental operation and unauthorized access to the microcontroller, ensuring that only authorized users who know the activation command can upgrade the microcontroller. Fourth, it has strong versatility. Program upgrades can be applied to any serial communication interface such as RS-485, CAN, and Ethernet. The combination of gateway switching and data pass-through is widely used in various MCU systems. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein: Figure 1 This is a schematic diagram of the dual microcontroller program upgrade system provided in this application.

[0016] Figure 2 This is a flowchart illustrating the program upgrade method for dual microcontrollers provided in this application. Detailed Implementation

[0017] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the specific embodiments of this application will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, it should be noted that, for ease of description, only the parts relevant to this application are shown in the accompanying drawings, not the entire structure. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this application.

[0018] The terms “comprising” and “having”, and any variations thereof, used in this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.

[0019] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0020] Please see Figure 1 As shown, an embodiment of this application provides a program upgrade system for dual microcontrollers, comprising: The first upgrade processing module is used to send upgrade association information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade. The mode change module is used to generate an activation command for the second microcontroller. Based on the activation command, the first microcontroller switches its communication state and performs mode control on the second microcontroller. The transmission control module is used to transmit external upgrade tools to the second microcontroller when the first microcontroller is in data pass-through mode. The second upgrade processing module is used to upgrade the second microcontroller based on the data received by the second microcontroller and external upgrade tools; The state recovery module is used to restore the first and second microcontrollers to their respective states when the second microcontroller completes the upgrade.

[0021] The beneficial effects of the above embodiments are as follows: This dual-microcontroller program upgrade system sends upgrade-related information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade; it generates an activation command for the second microcontroller, and according to the activation command, the first microcontroller switches its communication state and performs mode control on the second microcontroller; when the first microcontroller is in a data pass-through state, it transmits an external upgrade tool to the second microcontroller; based on the data received by the second microcontroller and the external upgrade tool, it upgrades the second microcontroller; when the second microcontroller completes the upgrade, it restores the first and second microcontrollers to their respective states. Through a single RS-485 external communication interface, the program upgrades of the two microcontrollers inside the device can be performed sequentially without physical disassembly of the device, making operation simple and highly secure.

[0022] In one embodiment, the first upgrade processing module is used to send upgrade association information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade, including: The external upgrade tool is instructed to send standard upgrade commands and upgrade data packets to the first microcontroller via the RS-485 interface, which serves as upgrade association information. The standard upgrade command received by the first microcontroller is verified. If the verification is successful, the standard upgrade process is executed according to the upgrade data packet to complete the update of the first microcontroller's own program. The standard upgrade process includes jumping to the built-in bootloader. After the first microcontroller completes the program update, it is instructed to reset and run the updated program.

[0023] The beneficial effects of the above embodiments are as follows: In actual operation, the first microcontroller can be, but is not limited to, an STM32F103, responsible for communication and control logic; the second microcontroller can be, but is not limited to, an STM32F407, responsible for advanced algorithm calculations; the first and second microcontrollers are connected via USRT, and the BOOT0 pin of the second microcontroller is connected to the PC15 pin of the first microcontroller through a 1K resistor. An external upgrade tool sends a standard upgrade command and an upgrade data packet for the first microcontroller via an RS-485 interface. After receiving and verifying the standard upgrade command and upgrade data packet, the first microcontroller executes its own standard upgrade process, such as jumping to the built-in bootloader to update its own program. After the upgrade is complete, the first microcontroller resets and runs the new program, thus ensuring efficient and accurate program upgrades for the first microcontroller.

[0024] In one embodiment, the mode change module is used to generate an activation command for the second microcontroller, and according to the activation command, to switch the communication state of the first microcontroller and to perform mode control on the second microcontroller, including: The external upgrade tool is instructed to generate an activation command for the second microcontroller via the RS-485 interface; the activation command includes a function code or a password. The activation command is verified. If the verification is successful, the communication state of the first microcontroller is switched from "self-upgrade mode" to "second microcontroller upgrade gateway mode". The program upgrade circuit controls its own GPIO pin to output a high level, thereby driving the BOOT0 pin of the second microcontroller, so that the second microcontroller enters the system memory boot mode when it is reset next time. A reset signal is sent to the second microcontroller, thereby restarting the second microcontroller and entering ISP programming mode.

[0025] The beneficial effects of the above embodiment are as follows: In actual operation, the external upgrade tool generates an activation command for the second microcontroller through the RS-485 interface. This activation command can be defined as a special Modbus RTU command [DeviceID] [0x59][0x6B] [CRC16], where 0x59 and 0x6B are user-defined function codes. The application program of the first microcontroller parses the Modbus RTU protocol and performs the following operations upon receiving the above command: HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); / / Pull high the second microcontroller _BOOT0; Sending the character 0x7F to the second microcontroller via UART serves as a soft reset signal (STM32 ISP protocol handshake signal), thereby restarting the second microcontroller and putting it into ISP programming mode; The first microcontroller switches its UART receive interrupt service function to a simple data pass-through function, which simply copies data from one UART buffer to another.

[0026] In one embodiment, the transmission control module is used to transmit external upgrade tools to the second microcontroller when the first microcontroller is in a data pass-through state, including: When the first microcontroller is in data pass-through mode, it switches to a transparent data bridge connector, thereby forwarding the data from the RS-485 interface to the second microcontroller in ISP programming mode through the internal UART interface without modification. This allows the external upgrade tool from the RS-485 interface to be forwarded to the second microcontroller.

[0027] The beneficial effects of the above embodiments are as follows: In actual operation, when the first microcontroller enters the data pass-through state, it no longer parses the application layer protocol for itself, but acts as a transparent data bridge connector. It forwards all data received from the RS-485 interface to the second microcontroller, which is already in ISP programming mode, through the internal UART interface. At the same time, it forwards the data returned from the ISP interface of the second microcontroller to the external upgrade tool through the RS-485 interface.

[0028] In one embodiment, the second upgrade processing module is used to upgrade the second microcontroller based on the data received by the second microcontroller and an external upgrade tool, including: The second microcontroller identifies the virtual serial port connected to it by the external upgrade tool received by the second microcontroller, thereby completing the program download and burning of the second microcontroller and upgrading the program of the second microcontroller. The state recovery module is used to restore the first and second microcontrollers to their respective states when the second microcontroller completes its upgrade, including: When the second microcontroller completes the program upgrade, a "Exit Transparent Transmission" command is sent to the second microcontroller. This is done by controlling the GPIO pin of the program upgrade circuit to output a low level, pulling the BOOT0 pin of the second microcontroller low, resetting the second microcontroller, causing it to exit the ISP programming mode and run the upgraded program normally. Control the first microcontroller to exit the "second microcontroller upgrade gateway mode" and re-parse its own application layer protocol.

[0029] The beneficial effects of the above embodiments are as follows: In actual operation, when the external upgrade tool is sent to the second microcontroller, the external upgrade tool recognizes a virtual serial port connected to the second microcontroller (although the physical path passes through the first microcontroller). It then communicates with the second microcontroller using the second microcontroller manufacturer's standard ISP editing protocol to complete the program download and burning to the second microcontroller. After the second microcontroller upgrade is complete, the external upgrade tool sends a predefined "exit transparent transmission" command, or the first microcontroller automatically executes it after detecting an RS-485 bus idle timeout; it controls the GPIO output to a low level, pulling the BOOT0 pin of the second microcontroller low; it then resets the second microcontroller, causing it to exit ISP editing mode and run the new user program normally. The first microcontroller itself exits "gateway mode," resumes normal application program operation, and restarts parsing its own application layer protocol.

[0030] Please see Figure 2 As shown in the figure, an embodiment of this application provides a method for upgrading the program of dual microcontrollers, including: Send upgrade association information to the first microcontroller to enable the first microcontroller to upgrade its program; Generate an activation command for the second microcontroller. Based on the activation command, switch the communication state of the first microcontroller and perform mode control on the second microcontroller. When the first microcontroller is in data pass-through mode, it transmits external upgrade tools to the second microcontroller. Based on the data received by the second microcontroller and the external upgrade tool, the second microcontroller is upgraded; when the second microcontroller completes the upgrade, the first and second microcontrollers are restored to their respective states.

[0031] The beneficial effects of the above embodiments are as follows: This dual-microcontroller program upgrade method sends upgrade-related information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade; generates an activation command for the second microcontroller, and according to the activation command, causes the first microcontroller to switch its communication state and performs mode control on the second microcontroller; when the first microcontroller is in a data pass-through state, it transmits an external upgrade tool to the second microcontroller; based on the data received by the second microcontroller and the external upgrade tool, it upgrades the second microcontroller; when the second microcontroller completes the upgrade, it restores the first and second microcontrollers to their respective states. Through a single RS-485 external communication interface, the program upgrades of the two microcontrollers inside the device can be performed sequentially without physical disassembly of the device, making operation simple and highly secure.

[0032] In one embodiment, sending upgrade association information to a first microcontroller to enable the first microcontroller to perform a program upgrade includes: The external upgrade tool is instructed to send standard upgrade commands and upgrade data packets to the first microcontroller via the RS-485 interface, which serves as upgrade association information. The standard upgrade command received by the first microcontroller is verified. If the verification is successful, the standard upgrade process is executed according to the upgrade data packet to complete the update of the first microcontroller's own program. The standard upgrade process includes jumping to the built-in bootloader. After the first microcontroller completes the program update, it is instructed to reset and run the updated program.

[0033] The beneficial effects of the above embodiments are as follows: In actual operation, the first microcontroller can be, but is not limited to, an STM32F103, responsible for communication and control logic; the second microcontroller can be, but is not limited to, an STM32F407, responsible for advanced algorithm calculations; the first and second microcontrollers are connected via USRT, and the BOOT0 pin of the second microcontroller is connected to the PC15 pin of the first microcontroller through a 1K resistor. An external upgrade tool sends a standard upgrade command and an upgrade data packet for the first microcontroller via an RS-485 interface. After receiving and verifying the standard upgrade command and upgrade data packet, the first microcontroller executes its own standard upgrade process, such as jumping to the built-in bootloader to update its own program. After the upgrade is complete, the first microcontroller resets and runs the new program, thus ensuring efficient and accurate program upgrades for the first microcontroller.

[0034] In one embodiment, an activation instruction is generated for the second microcontroller. Based on the activation instruction, the first microcontroller switches its communication state, and mode control is performed on the second microcontroller, including: The external upgrade tool is instructed to generate an activation command for the second microcontroller via the RS-485 interface; the activation command includes a function code or a password. The activation command is verified. If the verification is successful, the communication state of the first microcontroller is switched from "self-upgrade mode" to "second microcontroller upgrade gateway mode". The program upgrade circuit controls its own GPIO pin to output a high level, thereby driving the BOOT0 pin of the second microcontroller, so that the second microcontroller enters the system memory boot mode when it is reset next time. A reset signal is sent to the second microcontroller, thereby restarting the second microcontroller and entering ISP programming mode.

[0035] The beneficial effects of the above embodiment are as follows: In actual operation, the external upgrade tool generates an activation command for the second microcontroller through the RS-485 interface. This activation command can be defined as a special Modbus RTU command [DeviceID] [0x59][0x6B] [CRC16], where 0x59 and 0x6B are user-defined function codes. The application program of the first microcontroller parses the Modbus RTU protocol and performs the following operations upon receiving the above command: HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); / / Pull high the second microcontroller _BOOT0; Sending the character 0x7F to the second microcontroller via UART serves as a soft reset signal (STM32 ISP protocol handshake signal), thereby restarting the second microcontroller and putting it into ISP programming mode; The first microcontroller switches its UART receive interrupt service function to a simple data pass-through function, which simply copies data from one UART buffer to another.

[0036] In one embodiment, when the first microcontroller is in a data pass-through state, transmitting an external upgrade tool to the second microcontroller includes: When the first microcontroller is in data pass-through mode, it switches to a transparent data bridge connector, thereby forwarding the data from the RS-485 interface to the second microcontroller in ISP programming mode through the internal UART interface without modification. This allows the external upgrade tool from the RS-485 interface to be forwarded to the second microcontroller.

[0037] The beneficial effects of the above embodiments are as follows: In actual operation, when the first microcontroller enters the data pass-through state, it no longer parses the application layer protocol for itself, but acts as a transparent data bridge connector. It forwards all data received from the RS-485 interface to the second microcontroller, which is already in ISP programming mode, through the internal UART interface. At the same time, it forwards the data returned from the ISP interface of the second microcontroller to the external upgrade tool through the RS-485 interface.

[0038] In one embodiment, the second microcontroller is upgraded based on data received by the second microcontroller and an external upgrade tool; when the second microcontroller completes the upgrade, the first and second microcontrollers are restored to their respective states, including: The second microcontroller identifies the virtual serial port connected to it by the external upgrade tool received by the second microcontroller, thereby completing the program download and burning of the second microcontroller and upgrading the program of the second microcontroller. When the second microcontroller completes the program upgrade, a "Exit Transparent Transmission" command is sent to the second microcontroller. This is done by controlling the GPIO pin of the program upgrade circuit to output a low level, pulling the BOOT0 pin of the second microcontroller low, resetting the second microcontroller, causing it to exit the ISP programming mode and run the upgraded program normally. Control the first microcontroller to exit the "second microcontroller upgrade gateway mode" and re-parse its own application layer protocol.

[0039] The beneficial effects of the above embodiments are as follows: In actual operation, when the external upgrade tool is sent to the second microcontroller, the external upgrade tool recognizes a virtual serial port connected to the second microcontroller (although the physical path passes through the first microcontroller). It then communicates with the second microcontroller using the second microcontroller manufacturer's standard ISP editing protocol to complete the program download and burning to the second microcontroller. After the second microcontroller upgrade is complete, the external upgrade tool sends a predefined "exit transparent transmission" command, or the first microcontroller automatically executes it after detecting an RS-485 bus idle timeout; it controls the GPIO output to a low level, pulling the BOOT0 pin of the second microcontroller low; it then resets the second microcontroller, causing it to exit ISP editing mode and run the new user program normally. The first microcontroller itself exits "gateway mode," resumes normal application program operation, and restarts parsing its own application layer protocol.

[0040] The above is only one specific embodiment of the present invention, and any improvements made based on the concept of the present invention shall be considered within the scope of protection of the present invention.

Claims

1. A program upgrade system for dual microcontrollers, characterized in that, include: The first upgrade processing module is used to send upgrade association information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade. The mode change module is used to generate an activation command for the second microcontroller, and according to the activation command, to switch the communication state of the first microcontroller and to perform mode control on the second microcontroller. The transmission control module is used to transmit external upgrade tools to the second microcontroller when the first microcontroller is in a data pass-through state. The second upgrade processing module is used to upgrade the second microcontroller based on the data received by the second microcontroller and the external upgrade tool; The state recovery module is used to restore the first microcontroller and the second microcontroller to their respective states when the second microcontroller completes the upgrade.

2. The dual-microcontroller program upgrade system according to claim 1, characterized in that, The first upgrade processing module is used to send upgrade association information to the first microcontroller, thereby enabling the first microcontroller to perform a program upgrade, including: The external upgrade tool is instructed to send standard upgrade commands and upgrade data packets to the first microcontroller via the RS-485 interface, which serves as upgrade association information. The standard upgrade command received by the first microcontroller is verified. If the verification is successful, the standard upgrade process is executed according to the upgrade data packet to complete the update of the first microcontroller's own program. The standard upgrade process includes jumping to the built-in bootloader. After the first microcontroller completes the program update, it is instructed to reset and run the updated program.

3. The dual-microcontroller program upgrade system according to claim 2, characterized in that, The mode change module is used to generate an activation command for the second microcontroller, and according to the activation command, to switch the communication state of the first microcontroller and to perform mode control on the second microcontroller, including: The external upgrade tool is instructed to generate an activation command for the second microcontroller via the RS-485 interface; wherein the activation command includes a function code or a password; The activation command is verified. If the verification is successful, the communication state of the first microcontroller is switched from "self-upgrade mode" to "second microcontroller upgrade gateway mode". The program upgrade circuit controls its own GPIO pin to output a high level, thereby driving the BOOT0 pin of the second microcontroller, so that the second microcontroller enters the system memory boot mode when it is reset next time. A reset signal is sent to the second microcontroller to restart it and enter ISP programming mode.

4. The dual-microcontroller program upgrade system according to claim 3, characterized in that, The transmission control module is used to transmit external upgrade tools to the second microcontroller when the first microcontroller is in a data pass-through state, including: When the first microcontroller is in data pass-through mode, it switches to a transparent data bridge connector, thereby forwarding the data from the RS-485 interface to the second microcontroller in ISP programming mode through the internal UART interface without modification, and thus forwarding the external upgrade tool from the RS-485 interface to the second microcontroller.

5. The dual-microcontroller program upgrade system according to claim 4, characterized in that, The second upgrade processing module is used to upgrade the second microcontroller based on the data received by the second microcontroller and external upgrade tools, including: The second microcontroller identifies the virtual serial port connected to it based on the external upgrade tool received by the second microcontroller, thereby completing the program download and burning of the second microcontroller and upgrading the program of the second microcontroller. The state recovery module is used to restore the first microcontroller and the second microcontroller to their respective states when the second microcontroller completes the upgrade, including: When the second microcontroller completes the program upgrade, a "Exit Transparent Transmission" command is sent to the second microcontroller. This is done by controlling the GPIO pin of the program upgrade circuit to output a low level, pulling the BOOT0 pin of the second microcontroller low, resetting the second microcontroller, causing it to exit the ISP programming mode and run the upgraded program normally. Control the first microcontroller to exit the "second microcontroller upgrade gateway mode" and re-parse its own application layer protocol.

6. A method for upgrading the program of dual microcontrollers, characterized in that, Send upgrade association information to the first microcontroller to enable the first microcontroller to upgrade its program; An activation instruction is generated for the second microcontroller. Based on the activation instruction, the first microcontroller switches its communication state, and the second microcontroller is subjected to mode control. When the first microcontroller is in data pass-through mode, it transmits external upgrade tools to the second microcontroller. Based on the data received by the second microcontroller and the external upgrade tool, the second microcontroller is upgraded; when the second microcontroller completes the upgrade, the first microcontroller and the second microcontroller are restored to their respective states.

7. The program upgrade method for dual microcontrollers according to claim 6, characterized in that, Send upgrade association information to the first microcontroller to enable the first microcontroller to perform a program upgrade, including: The external upgrade tool is instructed to send standard upgrade commands and upgrade data packets to the first microcontroller via the RS-485 interface, which serves as upgrade association information. The standard upgrade command received by the first microcontroller is verified. If the verification is successful, the standard upgrade process is executed according to the upgrade data packet to complete the update of the first microcontroller's own program. The standard upgrade process includes jumping to the built-in bootloader. After the first microcontroller completes the program update, it is instructed to reset and run the updated program.

8. The program upgrade method for dual microcontrollers according to claim 7, characterized in that, Generate an activation command for the second microcontroller, and based on the activation command, cause the first microcontroller to switch its communication state and perform mode control on the second microcontroller, including: The external upgrade tool is instructed to generate an activation command for the second microcontroller via the RS-485 interface; wherein the activation command includes a function code or a password; The activation command is verified. If the verification is successful, the communication state of the first microcontroller is switched from "self-upgrade mode" to "second microcontroller upgrade gateway mode". The program upgrade circuit controls its own GPIO pin to output a high level, thereby driving the BOOT0 pin of the second microcontroller, so that the second microcontroller enters the system memory boot mode when it is reset next time. A reset signal is sent to the second microcontroller to restart it and enter ISP programming mode.

9. The program upgrade method for dual microcontrollers according to claim 8, characterized in that, When the first microcontroller is in data pass-through mode, it transmits external upgrade tools to the second microcontroller, including: When the first microcontroller is in data pass-through mode, it switches to a transparent data bridge connector, thereby forwarding the data from the RS-485 interface to the second microcontroller in ISP programming mode through the internal UART interface without modification, and thus forwarding the external upgrade tool from the RS-485 interface to the second microcontroller.

10. The program upgrade method for dual microcontrollers according to claim 9, characterized in that, The second microcontroller is upgraded based on the data received by the second microcontroller and the external upgrade tool; When the second microcontroller completes the upgrade, the first and second microcontrollers are restored to their respective states, including: The second microcontroller identifies the virtual serial port connected to it based on the external upgrade tool received by the second microcontroller, thereby completing the program download and burning of the second microcontroller and upgrading the program of the second microcontroller. When the second microcontroller completes the program upgrade, a "Exit Transparent Transmission" command is sent to the second microcontroller. This is done by controlling the GPIO pin of the program upgrade circuit to output a low level, pulling the BOOT0 pin of the second microcontroller low, resetting the second microcontroller, causing it to exit the ISP programming mode and run the upgraded program normally. Control the first microcontroller to exit the "second microcontroller upgrade gateway mode" and re-parse its own application layer protocol.