Method for simultaneously burning multiple single-chip microcomputers based on serial ports

By creating multiple threads on the main control single -chip machine and using the recognition information in the file, the parallel burning records of multiple STM32 single -chip microcomputers have been achieved, solving the difficulty of recording different programs in the existing technology, and improving the record efficiency of the burning records. And reliability.

CN119336345APending Publication Date: 2025-01-21BEIJING DIGITAL PRECISION MEDICAL TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411485578.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-23
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

The existing STM32 microcontroller burning method cannot realize the burning of different programs on multiple microcontrollers at the same time, and depends on serial communication, so the speed may be limited.

Method used

By creating multiple threads on the master microcontroller, parallel serial port communication and data transmission with multiple slave microcontrollers are achieved, and the identification information in the file is used to selectively connect and burn specific slave microcontrollers.

Benefits of technology

It improves the efficiency of burning microcontrollers, enables simultaneous burning of different programs to multiple microcontrollers, reduces costs, and enhances the reliability and flexibility of the burning process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336345A_ABST
    Figure CN119336345A_ABST
Patent Text Reader

Abstract

The invention provides a serial port-based multi-single-chip microcomputer simultaneous burning method, which comprises the following steps that: a master control single-chip microcomputer reads a file to be burnt, and stores the read file into a storage medium according to identification information; the master control single-chip microcomputer creates a corresponding number of threads according to the number of the single-chip microcomputers to be upgraded, each thread selects and is connected with a slave single-chip microcomputer according to identification information in a file, and the slave single-chip microcomputers are controlled to enter a serial port burning mode; the nth created burning thread of the master control single-chip microcomputer obtains a frame of data from the nth stored file and writes a frame of data into the corresponding slave single-chip microcomputer, and a verification response of the slave single-chip microcomputer is waited; the burning thread of the nth master control single-chip microcomputer is reactivated after receiving the response of the corresponding slave single-chip microcomputer, and if it is determined that all the storage files to be burnt are sent, the thread quits burning; and if the burning fault does not exist, normally ending the burning. According to the invention, the problem that the upgrading speed is slow when a plurality of slave single-chip microcomputers are burnt by the existing STM32 single-chip microcomputer can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of embedded system program burning, and in particular to a method for simultaneously burning multiple single-chip microcomputers based on serial ports. Background Art

[0002] At present, there are four most commonly used methods for burning STM32 microcontrollers: 1. Use MCUISP software to burn through serial port 1; 2. Use STM official software to burn through serial port 1; 3. Use the emulator to download the program; 4. Selectively burn multiple microcontroller node programs based on the CAN bus.

[0003] However, using method 1, method 2 or method 3 can only burn one STM32 microcontroller at a time, and it depends on serial port communication, and the speed may be limited; using method 4 can only burn the same program to multiple microcontrollers at a time, and requires additional CAN bus hardware and configuration, and currently this method is usually used to burn the same program.

[0004] Therefore, the above methods are unable to realize burning different single-chip computer programs to multiple single-chip computers at the same time. Summary of the invention

[0005] The invention aims to provide a method for simultaneously burning multiple single-chip microcomputers based on a serial port, aiming to solve the problem of slow upgrade rate when the existing STM32 single-chip microcomputer burns multiple slave single-chip microcomputers.

[0006] The present invention achieves the above-mentioned purpose through the following technical solutions:

[0007] A method for simultaneously burning multiple single-chip microcomputers based on a serial port comprises the following steps:

[0008] Step A1: Turn on the master MCU and each slave MCU, and initialize their respective systems and serial communication modules;

[0009] Step A2: The main control microcontroller reads the file to be burned. If the file is read successfully, step A3 is executed;

[0010] Step A3: the main control microcontroller stores the read file into the storage medium according to the identification information. If the file is stored successfully, step A4 is executed;

[0011] Step A4: The master MCU creates a corresponding number of threads according to the number of MCUs to be upgraded. Each thread selects and connects to a slave MCU according to the identification information in the file to perform a connectivity test. If the test is successful, the slave MCU is controlled to enter the serial port burning mode and step A5 is executed.

[0012] Step A5: The nth created burning thread of the master MCU obtains a frame of data from the nth stored file and writes a frame of data to the corresponding slave MCU. After writing, the thread suspends and waits for the verification response from the slave MCU.

[0013] Step A6: the burning thread of the nth master microcontroller is reactivated after receiving the response from the corresponding slave microcontroller. If it is determined that all the storage files to be burned have been sent, step A7 is executed. If not, step A5 is continued.

[0014] Step A7: When a thread completes the burning task of the slave microcontroller, the thread exits the burning process;

[0015] Step A8: If there is no programming failure, the programming is completed normally; if there is a failure, a warning prompt is given.

[0016] According to a method for simultaneously burning multiple single-chip microcomputers based on a serial port provided by the present invention, in the step A2, identification information in the file is stored at a specific address position in each file. If the information exists at the address, the file is considered to be the required burning file and the reading is judged to be successful, otherwise the reading fails.

[0017] According to a method for simultaneously burning multiple single-chip computers based on a serial port provided by the present invention, in the step A3, the main control single-chip computer reads the file to be burned and parses the identification information in the file. According to the identification information of the file and the characteristics of the storage medium, the main control single-chip computer allocates corresponding storage space on the storage medium;

[0018] The master microcontroller writes the file data into the allocated storage space block by block or frame by frame. After the writing is completed, the master microcontroller updates the directory entry or file system information of the storage medium to reflect the newly stored file;

[0019] The main control microcontroller verifies the stored file to ensure that the written data is consistent with the original data. If the data verification is successful, the main control microcontroller confirms that the file has been successfully stored in the storage medium;

[0020] Among them, if any error is encountered during the storage process, the main control microcontroller needs to execute the corresponding error handling process, including retrying the write operation, replacing the storage medium, recording the error information and exiting the storage process.

[0021] According to a method for simultaneously burning multiple single-chip microcomputers based on a serial port provided by the present invention, in the step A4, the master single-chip microcomputer reads the identification information of the current file, and searches for matching items in the connected slave single-chip microcomputers according to the parsed identification information to determine which slave single-chip microcomputer needs to be upgraded for the current file; if a matching slave single-chip microcomputer is found, the master single-chip microcomputer determines that the slave single-chip microcomputer is the upgrade object of the current file, assuming that it is the nth slave single-chip microcomputer, the master single-chip microcomputer creates a new upgrade thread for the determined upgrade object, prepares task information, and sends the task information to the newly created upgrade thread through the inter-thread communication mechanism, so that the newly created upgrade thread completes the next step of the upgrade work.

[0022] According to a method for simultaneously burning multiple single-chip computers based on a serial port provided by the present invention, when an upgrade thread performs an upgrade, a newly created upgrade thread receives task information from a communication mechanism, and parses a serial port number and an upgrade file address. The upgrade thread opens serial port communication with the nth slave single-chip computer according to the serial port number, ensures that the serial port communication parameters are consistent with those of the slave single-chip computer, and the upgrade thread reads the upgrade file from a storage medium and prepares to write it into the slave single-chip computer.

[0023] The upgrade thread sends the data of the upgrade file to the slave microcontroller frame by frame through the serial port. When all the upgrade data are successfully sent and confirmed, the upgrade thread considers the upgrade operation completed. At this time, the upgrade thread can close the serial port communication and record the log information of the successful upgrade.

[0024] According to a method for simultaneously burning multiple single-chip microcomputers based on a serial port provided by the present invention, in the step A5, after the slave single-chip microcomputer receives a frame of data sent by the master single-chip microcomputer, the slave single-chip microcomputer writes the received data into its internal user flash area, and performs a checksum calculation on the written data; the slave single-chip microcomputer combines information such as a frame header, a current number of data packets, a data length, and a checksum of the previous frame data into a frame of response data and returns it to the master single-chip microcomputer; the master single-chip microcomputer receives a response frame sent by the slave single-chip microcomputer through the serial port, and determines whether the received response frame corresponds to the currently sent data packet based on the number of data packets currently sent. If so, the master single-chip microcomputer compares the received checksum with the checksum of the frame of data previously sent to the slave single-chip microcomputer. If the number of data packets matches and the checksum is consistent, the master single-chip microcomputer believes that the current data packet has been successfully sent and correctly received and processed by the slave single-chip microcomputer. At this time, the master single-chip microcomputer can send the next frame of data and update the internal data packet number counter.

[0025] According to a method for simultaneously burning multiple single-chip microcomputers based on a serial port provided by the present invention, in the step A6, before storing the file content in a storage medium, the total content length of the file is first calculated, and the calculated file content length is stored in the storage medium at the same time before storage, and the master single-chip microcomputer sends the file content frame by frame to the corresponding slave single-chip microcomputer through the serial port according to a predetermined protocol; after the master single-chip microcomputer sends a frame of data each time, it updates the value of the counter or progress bar, and when the master single-chip microcomputer sends the last frame of data, it checks whether the value of the internal counter or progress bar is equal to the previously stored file content length. If the two are equal, it is considered that the file content has been completely sent and the sending process is completed.

[0026] According to a method for simultaneously burning multiple single-chip computers based on a serial port provided by the present invention, the identification information in the file is a section of information describing the serial port where the single-chip computer to be burned is located and its version number stored in a fixed line in the file. During the burning process, the main control single-chip computer reads the identification information in the bin file, and selects the correct serial port and firmware version for burning according to the serial port information and version number;

[0027] Before burning, the main control microcontroller verifies whether the identification information matches the expected one. If not, burning is rejected and a warning or error message is issued.

[0028] According to a method for simultaneously burning multiple single-chip microcomputers based on a serial port provided by the present invention, in step A4, different priorities are assigned to different threads according to the burning priority or urgency of the single-chip microcomputer.

[0029] According to a method for simultaneously burning multiple single-chip microcomputers based on a serial port provided by the present invention, in the master single-chip microcomputer, an independent timer is set for each slave single-chip microcomputer, and when the master single-chip microcomputer sends a request or data to the slave single-chip microcomputer, the corresponding timer is started at the same time;

[0030] While the timer is running, the master MCU keeps checking the response from the slave MCU. If a response from the slave MCU is received within the timeout period, the timer is reset and the subsequent operation continues;

[0031] If the timer reaches the set timeout period and still does not receive a response from the slave microcontroller, the timeout mechanism is triggered. At this time, the master microcontroller issues a warning or performs error processing.

[0032] It can be seen that compared with the prior art, the design method provided by the present invention has the following beneficial effects:

[0033] 1. The present invention can improve the efficiency of burning single-chip microcomputers. Generally, the single-chip microcomputers in electronic products are connected to multiple communication serial ports by a main control board to communicate with multiple slave single-chip microcomputers across circuit boards. In general, in order to balance the stability and speed of data transmission, the baud rate of the serial port communication will not be too high when the single-chip microcomputer is running. Therefore, if it is necessary to short-circuit the serial port of the single-chip microcomputer to the single-chip microcomputer, when the serial port of the slave single-chip microcomputer is upgraded, the upgrade speed bottleneck is often the serial port communication rate, rather than the rate at which the main control board single-chip microcomputer obtains the upgrade file.

[0034] 2. When the master MCU is only connected to the slave MCU through the serial port, multiple slave MCUs can be burned at the same time through different physical serial ports, which can improve the burning efficiency; when the master MCU and the slave MCU form a set of products together, and the product only has the USB interface or other high-speed interface of the master MCU leading to the outside of the product, it can be burned easily.

[0035] 3. The present invention creates multiple threads, allowing the master microcontroller to communicate and transmit data with multiple slave microcontrollers at the same time, thereby realizing parallel burning and significantly improving the burning efficiency. In particular, when a large number of microcontrollers need to be burned at the same time, the traditional single-thread burning method needs to process each microcontroller in turn, resulting in a long overall burning time, while the multi-thread method can process multiple microcontrollers at the same time, greatly reducing the waiting time.

[0036] 4. The present invention mainly relies on serial port communication and does not require additional hardware devices (such as emulators) to support the burning process, thereby reducing costs, especially for application scenarios that require a large number of single-chip microcomputers to be burned.

[0037] 5. During the data transmission process, the present invention ensures the integrity and correctness of the data by waiting for the verification response from the slave microcontroller, reducing the possibility of programming failure caused by data transmission errors. If a slave microcontroller does not respond within a predetermined time, the master microcontroller can issue a warning or perform error processing. This helps to discover and solve problems in a timely manner and improves the reliability of the programming process.

[0038] 6. The present invention allows selective connection and burning of specific slave microcontrollers according to the identification information in the file, and can flexibly handle microcontrollers of different models and versions without reconfiguring the entire system. By reading different files, different programs or firmware can be burned into different microcontrollers, which increases the flexibility of the burning process and meets diverse needs.

[0039] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 The present invention is a flowchart of a method for simultaneously burning multiple single-chip microcomputers based on a serial port.

[0041] Figure 2 The present invention is a schematic diagram of the process principle of a method for simultaneously burning multiple single-chip microcomputers based on a serial port. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0043] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0044] See also Figure 1 and Figure 2 The present invention provides a method for simultaneously burning multiple single-chip microcomputers based on a serial port, the method comprising the following steps:

[0045] Step A1: Turn on the master MCU and each slave MCU, and initialize their respective systems and serial communication modules;

[0046] Step A2: The main control microcontroller reads the file to be burned. If the file is read successfully, step A3 is executed. If the file is read unsuccessfully, step A7 is executed.

[0047] Step A3: the main control microcontroller stores the read file in the storage medium according to the identification information. If the file storage is successful, step A4 is executed. If it fails, the storage medium is replaced. If the storage still fails, step A7 is executed.

[0048] Step A4: The master MCU creates a corresponding number of threads according to the number of MCUs to be upgraded. Each thread selects and connects to the slave MCU according to the identification information in the file to perform a connectivity test. If the test is successful, the slave MCU is controlled to enter the serial port burning mode and step A5 is executed; if the test fails, the thread exits and step A7 is executed;

[0049] Step A5: The nth created burning thread of the master MCU obtains a frame of data from the nth stored file and writes a frame of data to the corresponding slave MCU. After writing, the thread suspends and waits for the verification response from the slave MCU.

[0050] Step A6: the burning thread of the nth master microcontroller is reactivated after receiving the response from the corresponding slave microcontroller. If it is determined that all the storage files to be burned have been sent, step A7 is executed. If not, step A5 is continued.

[0051] Step A7: When a thread completes the burning task of the slave microcontroller, the thread exits the burning process;

[0052] Step A8: If there is no programming failure, the programming is completed normally; if there is a failure, a warning prompt is given.

[0053] In the above step A2, the identification information in the file is stored at a specific address position in each file. If the information exists at the address, the file is considered to be the required burning file and the reading is judged to be successful. Otherwise, the reading fails.

[0054] In the above step A3, the main control microcontroller reads the file to be burned and parses the identification information in the file. According to the identification information of the file and the characteristics of the storage medium, the main control microcontroller allocates corresponding storage space on the storage medium;

[0055] The master microcontroller writes the file data block by block or frame by frame into the allocated storage space. After writing is completed, the master microcontroller updates the directory entry or file system information of the storage medium to reflect the newly stored file, including updating the file size, timestamp and other information. ;

[0056] The main control microcontroller verifies the stored file to ensure that the written data is consistent with the original data. If the data verification is successful, the main control microcontroller confirms that the file has been successfully stored in the storage medium. The verification method includes byte-by-byte comparison, checksum calculation, etc.;

[0057] Among them, if any error is encountered during the storage process, the main control microcontroller needs to execute the corresponding error handling process, including retrying the write operation, replacing the storage medium, recording the error information and exiting the storage process.

[0058] Through the above step A3, it can be ensured that the main control microcontroller can accurately and reliably complete the storage task when storing files in the storage medium. At the same time, it is also convenient to perform error handling and log recording during the storage process to improve the stability and maintainability of the system.

[0059] In the above step A4, the master control microcontroller reads the identification information of the current file, searches for matching items in the connected slave microcontrollers according to the parsed identification information, and determines which slave microcontroller needs to be upgraded for the current file; if a matching slave microcontroller is found, the master control microcontroller determines that the slave microcontroller is the upgrade object of the current file, assuming that it is the nth slave microcontroller, the master control microcontroller creates a new upgrade thread for the determined upgrade object, prepares task information, and sends the task information to the newly created upgrade thread through the inter-thread communication mechanism (mailbox), so that the newly created upgrade thread completes the next step of the upgrade work. Among them, the mailbox mechanism can ensure that the task information is safely and reliably transmitted between multiple threads.

[0060] When the upgrade thread is performing the upgrade work, the newly created upgrade thread receives the task information from the communication mechanism and parses the serial port number and the upgrade file address. The upgrade thread opens the serial port communication with the nth slave microcontroller according to the serial port number, ensures that the serial port communication parameters (such as baud rate, data bit, stop bit, etc.) are consistent with those of the slave microcontroller, and the upgrade thread reads the upgrade file from the storage medium and prepares to write it to the slave microcontroller.

[0061] The upgrade thread sends the data of the upgrade file to the slave microcontroller frame by frame through the serial port. When all the upgrade data are successfully sent and confirmed, the upgrade thread considers the upgrade operation completed. At this time, the upgrade thread can close the serial port communication and record the log information of the successful upgrade.

[0062] Through the above step A4, the master MCU can accurately determine the slave MCU that needs to be upgraded, and assign the upgrade task to the corresponding thread for execution through the thread and mailbox mechanism, thereby ensuring the accuracy and reliability of the upgrade process and improving the concurrent processing capability and response speed of the system.

[0063] In the above step A5, the first created burning thread of the master microcontroller obtains a frame of data from the first stored file and writes a frame of data to the corresponding slave microcontroller, and then suspends and waits for the verification response from the slave microcontroller.

[0064] Step A5.1, the 2nd, 3rd, ... nth created burning threads of the master microcontroller write a frame of data to the corresponding microcontroller when other threads are suspended and waiting, and then suspend and wait for the verification response from the microcontroller.

[0065] In the above step A6, the burning thread of the first master microcontroller is reactivated after receiving the response from the corresponding slave microcontroller. If all the storage files to be burned have been sent, step A7 is performed; if not, step A5 is performed.

[0066] Step A6.1, the burning threads of the second, third, ...n master microcontrollers are reactivated after receiving the responses from the corresponding slave microcontrollers. If all the storage files to be burned have been sent, step A7 is performed; if not, step A5.1 is performed.

[0067] In the above step A5, after the slave microcontroller receives a frame of data sent by the master microcontroller, the slave microcontroller writes the received data into its internal user flash area and performs checksum calculation on the written data; the slave microcontroller combines the frame header, the current number of data packets, the data length, the checksum of the previous frame data and other information into a frame of response data and returns it to the master microcontroller; the master microcontroller receives the response frame sent by the slave microcontroller through the serial port, and determines whether the received response frame corresponds to the currently sent data packet according to the number of data packets currently sent. If so, the master microcontroller compares the received checksum with the checksum of the frame data previously sent to the slave microcontroller. If the number of data packets matches and the checksum is consistent, the master microcontroller believes that the current data packet has been successfully sent and correctly received and processed by the slave microcontroller. At this time, the master microcontroller can send the next frame of data and update the internal data packet counter.

[0068] The checksum may be a simple summation, XOR or other operations, or a more complex CRC check or the like.

[0069] If the number of data packets does not match, error information is recorded and an error handling process needs to be executed (such as resending the current data packet, skipping the data packet, etc.).

[0070] If the checksum is inconsistent, error information is recorded and an error handling process needs to be executed (such as requesting the microcontroller to resend the checksum, resend the current data packet, etc.).

[0071] Through the above step A5, the slave microcontroller can correctly receive, process and respond to the data frame sent by the master microcontroller. At the same time, the master microcontroller can accurately verify the response of the slave microcontroller and continue to send the next frame of data, ensuring the integrity and correctness of the data during the transmission process and improving the reliability and stability of the system.

[0072] In the above step A6, before storing the file content in the storage medium, the total content length of the file is first calculated, and the calculated file content length is stored in the storage medium before storage. The master microcontroller sends the file content frame by frame to the corresponding slave microcontroller through the serial port according to a predetermined protocol; after the master microcontroller sends a frame of data each time, it updates the value of the counter or progress bar. When the master microcontroller sends the last frame of data, it checks whether the value of the internal counter or progress bar is equal to the previously stored file content length. If the two are equal, it is considered that the file content has been completely sent and the sending process is completed.

[0073] Through the above step A6, it is ensured that the content length of the file can be correctly recorded when it is stored in the storage medium, and it is possible to accurately judge whether the file content has been completely sent during the sending process, thereby improving the reliability and accuracy of file transmission and providing strong support for the firmware upgrade or data update of the microcontroller.

[0074] In this embodiment, the identification information in the file is a section of information describing the serial port where the microcontroller to be burned is located and its version number stored in a fixed line in the file. During the burning process, the main control microcontroller reads the identification information in the bin file and selects the correct serial port and firmware version for burning according to the serial port information and version number;

[0075] Before burning, the main control microcontroller verifies whether the identification information matches the expected one. If not, burning is rejected and a warning or error message is issued.

[0076] In the above step A4, different priorities are assigned to different threads according to the priority or urgency of the burning of the slave microcontroller.

[0077] In this embodiment, in the master microcontroller, an independent timer is set for each slave microcontroller, and when the master microcontroller sends a request or data to the slave microcontroller, the corresponding timer is started at the same time;

[0078] While the timer is running, the master MCU keeps checking the response from the slave MCU. If a response from the slave MCU is received within the timeout period, the timer is reset and the subsequent operation continues;

[0079] If the timer reaches the set timeout period and still does not receive a response from the slave microcontroller, the timeout mechanism is triggered. At this time, the master microcontroller issues a warning or performs error processing.

[0080] In practical applications, the number of files to be burned in the above step A2 is generally equal to the number of slave microcontrollers to be burned, and the file format is bin.

[0081] The way of storing files in the above step A3 is that different files are stored separately in different sectors or addresses of the storage medium, and there are no adjacent addresses between the two files. The identification information in the file refers to a section of information describing the serial port where the microcontroller to be burned is located and its version number stored in a fixed line in the file; the storage medium refers to the memory, flash or external flash of the main microcontroller through SPI communication.

[0082] In the above step A5, the data is obtained from the storage medium from the beginning to the end of the file, and it is coherent. A frame of data refers to the frame header + the number of data packets + the data length + the data; the check response refers to the frame header + the number of data packets + the data length + the check code of the previous frame data, and the number of data packets refers to the content of the number of data packets currently being sent; this embodiment uses the XOR check method.

[0083] In summary, the method provided in this embodiment can improve the efficiency of burning single-chip microcomputers. Generally, the single-chip microcomputers in electronic products are connected to multiple communication serial ports by a main control board to communicate with multiple slave single-chip microcomputers across circuit boards. In general, in order to take into account the stability and speed of data transmission, the baud rate of the serial port communication will not be too high when the single-chip microcomputer is running. Therefore, if it is necessary to short-circuit the serial port from one single-chip microcomputer to another, when upgrading the serial port of the slave single-chip microcomputer, the upgrade speed bottleneck is often the serial port communication rate, rather than the rate at which the main control board single-chip microcomputer obtains the upgrade file.

[0084] Furthermore, when the master microcontroller is only connected to the slave microcontroller through a serial port, multiple slave microcontrollers can be burned simultaneously through different physical serial ports, which can improve the burning efficiency; when the master microcontroller and the slave microcontrollers form a set of products together, the product only has the USB interface or other high-speed interface of the master microcontroller leading to the outside of the product, it can be easily burned.

[0085] Furthermore, the method provided in this embodiment creates multiple threads, allowing the master microcontroller to communicate and transmit data with multiple slave microcontrollers at the same time, thereby realizing parallel burning and significantly improving the burning efficiency. In particular, when a large number of microcontrollers need to be burned at the same time, the traditional single-thread burning method needs to process each microcontroller in turn, resulting in a long overall burning time, while the multi-threaded method can process multiple microcontrollers at the same time, greatly reducing the waiting time.

[0086] Furthermore, the method provided in this embodiment mainly relies on serial port communication and does not require additional hardware devices (such as emulators) to support the burning process, thereby reducing costs, especially for application scenarios that require a large number of microcontrollers to be burned.

[0087] Furthermore, during the data transmission process, the method provided in this embodiment ensures the integrity and correctness of the data by waiting for the verification response from the slave microcontroller, thereby reducing the possibility of programming failure caused by data transmission errors. If a slave microcontroller does not respond within a predetermined time, the master microcontroller can issue a warning or perform error processing. This helps to discover and solve problems in a timely manner and improves the reliability of the programming process.

[0088] Furthermore, the method provided in this embodiment allows selective connection and burning of a specific slave microcontroller according to the identification information in the file, and can flexibly handle microcontrollers of different models and versions without reconfiguring the entire system. By reading different files, different programs or firmware can be burned into different microcontrollers, which increases the flexibility of the burning process and meets diverse needs.

[0089] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0090] The above-mentioned embodiments are only preferred embodiments of the present invention and cannot be used to limit the scope of protection of the present invention. Any non-substantial changes and substitutions made by technicians in this field on the basis of the present invention shall fall within the scope of protection required by the present invention.

Claims

1. A method for simultaneously burning multiple single-chip microcomputers based on a serial port, characterized in that: The following steps are involved: Step A1: Turn on the master MCU and each slave MCU, and initialize their respective systems and serial communication modules; Step A2: The main control microcontroller reads the file to be burned. If the file is read successfully, step A3 is executed; Step A3: the main control microcontroller stores the read file into the storage medium according to the identification information. If the file is stored successfully, step A4 is executed; Step A4: The master MCU creates a corresponding number of threads according to the number of MCUs to be upgraded. Each thread selects and connects to a slave MCU according to the identification information in the file to perform a connectivity test. If the test is successful, the slave MCU is controlled to enter the serial port burning mode and step A5 is executed. Step A5: The nth created burning thread of the master MCU obtains a frame of data from the nth stored file and writes a frame of data to the corresponding slave MCU. After writing, the thread suspends and waits for the verification response from the slave MCU. Step A6: the burning thread of the nth master microcontroller is reactivated after receiving the response from the corresponding slave microcontroller. If it is determined that all the storage files to be burned have been sent, step A7 is executed. If not, step A5 is continued. Step A7: When a thread completes the burning task of the slave microcontroller, the thread exits the burning process; Step A8: If there is no programming failure, the programming is completed normally; if there is a failure, a warning prompt is given.

2. The method according to claim 1, characterized in that: In step A2, the identification information in the file is stored at a specific address position in each file. If the information exists at the address, the file is considered to be the required burning file and the reading is judged to be successful. Otherwise, the reading fails.

3. The method according to claim 1, characterized in that: In step A3, the main control microcontroller reads the file to be burned and parses the identification information in the file. According to the identification information of the file and the characteristics of the storage medium, the main control microcontroller allocates corresponding storage space on the storage medium; The master microcontroller writes the file data into the allocated storage space block by block or frame by frame. After the writing is completed, the master microcontroller updates the directory entry or file system information of the storage medium to reflect the newly stored file; The main control microcontroller verifies the stored file to ensure that the written data is consistent with the original data. If the data verification is successful, the main control microcontroller confirms that the file has been successfully stored in the storage medium; Among them, if any error is encountered during the storage process, the main control microcontroller needs to execute the corresponding error handling process, including retrying the write operation, replacing the storage medium, recording the error information and exiting the storage process.

4. The method according to claim 1, characterized in that: In step A4, the master microcontroller reads the identification information of the current file, searches for matching items in the connected slave microcontrollers based on the parsed identification information, and determines which slave microcontroller needs to be upgraded for the current file; if a matching slave microcontroller is found, the master microcontroller determines that the slave microcontroller is the upgrade object of the current file, assuming it is the nth slave microcontroller, the master microcontroller creates a new upgrade thread for the determined upgrade object, prepares task information, and sends the task information to the newly created upgrade thread through the inter-thread communication mechanism, so that the newly created upgrade thread completes the next step of the upgrade work.

5. The method according to claim 4, characterized in that: When the upgrade thread is performing the upgrade work, the newly created upgrade thread receives the task information from the communication mechanism and parses the serial port number and the upgrade file address. The upgrade thread opens the serial port communication with the nth slave microcontroller according to the serial port number, ensures that the serial port communication parameters are consistent with those of the slave microcontroller, and reads the upgrade file from the storage medium and prepares to write it to the slave microcontroller. The upgrade thread sends the data of the upgrade file to the slave microcontroller frame by frame through the serial port. When all the upgrade data are successfully sent and confirmed, the upgrade thread considers the upgrade operation completed. At this time, the upgrade thread can close the serial port communication and record the log information of the successful upgrade.

6. The method according to claim 1, characterized in that: In step A5, after the slave microcontroller receives a frame of data sent by the master microcontroller, the slave microcontroller writes the received data into its internal user flash area, and performs checksum calculation on the written data; the slave microcontroller combines the frame header, the current number of data packets, the data length, the checksum of the previous frame data and other information into a frame of response data and returns it to the master microcontroller; The master microcontroller receives the response frame sent from the slave microcontroller through the serial port, and determines whether the received response frame corresponds to the currently sent data packet based on the number of currently sent data packets. If so, the master microcontroller compares the received check code with the checksum of the frame data previously sent to the slave microcontroller. If the number of data packets matches and the checksum is consistent, the master microcontroller believes that the current data packet has been successfully sent and correctly received and processed by the slave microcontroller. At this time, the master microcontroller can send the next frame of data and update the internal data packet counter.

7. The method according to any one of claims 1 to 6, characterized in that: In step A6, before storing the file content in the storage medium, the total content length of the file is first calculated, and the calculated file content length is stored in the storage medium before storage. The master microcontroller sends the file content frame by frame to the corresponding slave microcontroller through the serial port according to a predetermined protocol; after the master microcontroller sends a frame of data each time, it updates the value of the counter or progress bar. When the master microcontroller sends the last frame of data, it checks whether the value of the internal counter or progress bar is equal to the previously stored file content length. If the two are equal, it is considered that the file content has been completely sent and the sending process is completed.

8. The method according to any one of claims 1 to 6, characterized in that: The identification information in the file is a section of information describing the serial port where the microcontroller to be burned is located and its version number, which is stored in a fixed line in the file. During the burning process, the main control microcontroller reads the identification information in the bin file and selects the correct serial port and firmware version for burning according to the serial port information and version number; Before burning, the main control microcontroller verifies whether the identification information matches the expected one. If not, burning is rejected and a warning or error message is issued.

9. The method according to any one of claims 1 to 6, characterized in that: In step A4, different priorities are assigned to different threads according to the priority or urgency of the burning of the slave microcontroller.

10. The method according to any one of claims 1 to 6, characterized in that: In the master microcontroller, an independent timer is set for each slave microcontroller. When the master microcontroller sends a request or data to the slave microcontroller, the corresponding timer is started at the same time. While the timer is running, the master MCU keeps checking the response from the slave MCU. If a response from the slave MCU is received within the timeout period, the timer is reset and the subsequent operation continues; If the timer reaches the set timeout period and still does not receive a response from the slave microcontroller, the timeout mechanism is triggered. At this time, the master microcontroller issues a warning or performs error processing.

Citation Information

Cited By

  • Cascade single-chip microcomputer upgrading method and system based on custom packaging

    CN120371363A

  • Cascaded microcontroller upgrade method and system based on custom packaging

    CN120371363B