Anti-interference and high-stability single-line live-line burning method for MCU (Microprogrammed Control Unit)
By introducing a special interrupt, a 16x variable oversampling counter, and an accumulated error clearing bit into the MCU, the stability and anti-interference issues of single-wire power-on programming of the MCU are solved, achieving efficient single-wire programming and reducing resource consumption and cost.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-03-27
AI Technical Summary
Existing MCUs suffer from insufficient stability and anti-interference capabilities during single-wire power-on programming, and require additional communication pins, which limits their application scenarios.
A single-wire live programming method is adopted. By introducing a special interrupt vector entry address, a 16x variable oversampling counter and an accumulated error clear bit in the MCU design, combined with an independent reset circuit, single-wire communication is achieved. Different processing of command frames and data frames is adopted to ensure the stability and anti-interference of data transmission.
It achieves high stability and anti-interference programming in single-wire communication, reduces the consumption of MCU IO resources, and lowers the cost of program upgrades.
Smart Images

Figure CN121742860A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electronic communication technology, specifically to a single-wire live programming method for MCUs that offers high anti-interference and stability. Background Technology
[0002] A microcontroller unit, also known as a single-chip microcomputer or microcontroller, is a chip-level computer that integrates a central processing unit (CPU) with a reduced frequency and specifications, along with peripheral interfaces such as memory, counters, USB, A / D converters, UART, PLC, DMA, and even LCD driver circuits, onto a single chip. This allows for different combinations of control for various applications.
[0003] Currently, changing the program on an MCU generally requires disconnecting the power supply and then using a programmer for secondary programming. This often involves using a two-wire or four-wire protocol, which has significant limitations in application. Sufficient communication pins must be reserved to complete the programming process, and there are issues with insufficient stability and anti-interference capabilities in single-wire powered programming, thus leaving room for improvement. Summary of the Invention
[0004] The purpose of this invention is to provide a single-wire live programming method for MCUs that is highly resistant to interference and has high stability, in order to solve the problems mentioned in the background art.
[0005] This invention discloses a single-wire live programming method for MCUs that offers high anti-interference and stability, comprising the following steps: Step 1: Connect the data pins of the programmer and the data pins of the MCU, check if they share a common ground, and confirm that the pull-up function is enabled on the data pins of both the programmer and the MCU when in input mode; Step 2: When the MCU recognizes a special interrupt requesting hot-programming, the MCU will jump to the corresponding special interrupt entry address, and the software will enable the hot-programming enable bit in the interrupt service function; Step 3: The MCU will enter the single-wire live programming mode. First, it will set the corresponding data pin to digital pull-up state, and then it will send a PWM waveform to allow the programmer to determine the length of each bit of data. Step 4: After determining the data length per bit, the programmer starts sending command frames and data frames to the MCU according to the agreed commands to begin programming the MCU. Step 5: After programming is complete, the programmer sends a readback command to check if the programmed data is correct. When the MCU outputs data, it will first send a 0 to allow the programmer to determine the starting point of the data. Step 6: If the readback data is abnormal, send a reset data stream to reset the state machine and restart the programming process until the readback is normal, then end the live programming process.
[0006] The invention is further configured such that, during the design of the MCU, a special interrupt vector entry address is created. Once this interrupt is triggered, the software enables the power-on programming bit in this special interrupt function. When this bit takes effect, the MCU's internal CPU will stop running, and the corresponding communication pins will also be ready for communication. As for how to trigger this interrupt, it depends on the agreed-upon "protocol".
[0007] The present invention is further configured such that the MCU has only one data line for single-pin communication, and the communication reference clock is provided by the MCU's internal clock clk; the data on the data line is sampled using a variable oversampling method of up to 16 times; the clock sample_clk for data reception and transmission both depend on the counter that implements the 16 times variable oversampling.
[0008] The present invention is further configured such that the 16x variable oversampling counter means that when the start bit is detected, the 4-bit counter will start counting from 0 to F. If no data change is detected on the data line between 0 and F, the counter will continue counting from 0 to F. If a data change is detected on the data line between 0 and F, the counter will be cleared to 0 in advance.
[0009] The present invention is further configured such that the communication frames between the MCU and the programmer are divided into two formats: a command frame and a data frame; both frame formats have a start bit '0' and an end bit '1'; the difference between the command frame and the data frame is that an accumulated error clear bit is inserted every 4 bits in the data frame.
[0010] The present invention is further configured such that, when receiving consecutive identical data, the sending end has a certain difference in the time length of sending each bit. Since the data does not change, the 16x variable oversampling counter will keep counting from 0 to F, causing the data error of each bit to accumulate. After reaching a certain limit, the data will be received incorrectly. At this time, the introduction of the accumulated error clear bit in the data frame will solve this problem and improve the error tolerance.
[0011] The present invention is further configured such that when the burning is completed and the data is read back for confirmation, an abnormality is found in the data readback. In this case, the internal state machine is likely to have malfunctioned. At this time, this independent reset circuit is required to restore the state machine to the idle state.
[0012] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described above.
[0013] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.
[0014] Compared with existing technologies, the beneficial effects of this invention are as follows: This single-wire hot-spinning method for MCUs, which is highly resistant to interference and stable, does not require an additional clock pin during programming communication; only a data pin is needed. This data pin is responsible for writing data input to the MCU and reading data output from the MCU. The MCU design incorporates two frame structures, accumulated error clearing, and an independent reset circuit, which not only solves the problem that most MCUs on the market cannot be hot-spinned but also reduces the consumption of MCU I / O resources. It also has strong anti-interference capabilities and excellent stability. At the application level, it reduces the cost of on-board program upgrades. Attached Figure Description
[0015] Figure 1 This is a simplified timing diagram illustrating the present invention; Figure 2 This is a schematic diagram illustrating a frame example of the present invention; Figure 3 This is a schematic diagram of the single-wire live programming module architecture of the present invention. Detailed Implementation
[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0017] Please see Figure 1-2 This invention provides a technical solution: a single-wire live programming method for MCUs with high anti-interference and stability, comprising the following steps: Step 1: Connect the data pins of the programmer and the data pins of the MCU, check if they share a common ground, and confirm that the pull-up function is enabled on the data pins of both the programmer and the MCU when in input mode; Step 2: When the MCU recognizes a special interrupt requesting hot-programming, the MCU will jump to the corresponding special interrupt entry address, and the software will enable the hot-programming enable bit in the interrupt service function; Step 3: The MCU will enter the single-wire live programming mode. First, it will set the corresponding data pin to digital pull-up state, and then it will send a PWM waveform to allow the programmer to determine the length of each bit of data. Step 4: After determining the data length per bit, the programmer starts sending command frames and data frames to the MCU according to the agreed commands to begin programming the MCU. Step 5: After programming is complete, the programmer sends a readback command to check if the programmed data is correct. When the MCU outputs data, it will first send a 0 to allow the programmer to determine the starting point of the data. Step 6: If the readback data is abnormal, send a reset data stream to reset the state machine and restart the programming process until the readback is normal, then end the live programming process.
[0018] In this embodiment, a special interrupt vector entry address is created during MCU design. Once this interrupt is triggered, the software enables the power-on programming bit in this special interrupt function. After this bit takes effect, the MCU's internal CPU will stop running, and the corresponding communication pins will also be ready for communication. As for how to trigger this interrupt, it depends on the agreed "protocol".
[0019] Furthermore, the MCU uses only one data line for single-pin communication, and the communication reference clock is provided by the MCU's internal clock clk. It uses a variable oversampling method of up to 16x to sample the data on the data line. The clock sample_clk for both data reception and transmission depends on the counter that implements the 16x variable oversampling. The 16x variable oversampling counter means that when the start bit is detected, the 4-bit counter will start counting from 0 to F. If no data change is detected on the data line between 0 and F, it will continue counting from 0 to F. If a data change is detected on the data line between 0 and F, the counter will be cleared to 0 in advance.
[0020] The communication frames between the MCU and the programmer are divided into two formats: command frames and data frames. Both of these frame formats have a start bit '0' and an end bit '1'. The difference between command frames and data frames is that an accumulated error clear bit is inserted every 4 bits in the data frame.
[0021] Accumulated error refers to the situation where, when receiving consecutive identical data, the sending end has a certain difference in the time length of each bit. Since the data does not change, the 16x variable oversampling counter will keep counting from 0 to F, causing the data error per bit to accumulate. After reaching a certain limit, the data will be received incorrectly. At this point, introducing an accumulated error clear bit in the data frame will solve this problem and also improve the error tolerance.
[0022] It is worth mentioning that when the data is read back and confirmed after the burning is completed, if an abnormality is found, it is highly likely that the internal state machine has run into trouble. In this case, the independent reset circuit is needed to restore the state machine to the idle state.
[0023] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method.
[0024] A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above method.
[0025] Reference Figure 3 The single-wire live programming method is implemented through a single-wire live programming module, which consists of the following circuits: Digital filtering circuit: filters out small glitches on the data line to ensure that other circuits use clean signals.
[0026] Data change detection circuit: Used to detect data changes in the filtered data signal, obtaining data_fall and data_rise. These two signals are used in the start bit control logic circuit of subsequent command frames / data frames.
[0027] The control circuit for the start and end bits of the data: controls the start and end of the command frame / data frame based on the received data and feedback from the state machine.
[0028] 16x Variable Oversampling Counter Circuit: This circuit is responsible for generating the clock and data to control the operation of the state machine, and also for clearing accumulated errors.
[0029] Command and data frame recognition and ROM IP interface control state machine: This circuit executes corresponding operations based on the clock and data, such as the logic control of ROM IP address, data, programming, and reading, thereby realizing programming and reading. It is also responsible for feedback on the end of data or command frames.
[0030] Reset control circuit: Responsible for controlling the reset of the state machine. When the state machine runs away, it needs to be reset so that the state machine is in a known and controllable state.
[0031] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
Claims
1. A single-wire live programming method for MCUs with high anti-interference and stability, characterized in that, Includes the following steps: Step 1: Connect the data pins of the programmer and the data pins of the MCU, check if they share a common ground, and confirm that the pull-up function is enabled on the data pins of both the programmer and the MCU when in input mode; Step 2: When the MCU recognizes a special interrupt requesting hot-programming, the MCU will jump to the corresponding special interrupt entry address, and the software will enable the hot-programming enable bit in the interrupt service function; Step 3: The MCU will enter the single-wire live programming mode. First, it will set the corresponding data pin to digital pull-up state, and then it will send a PWM waveform to allow the programmer to determine the length of each bit of data. Step 4: After determining the data length per bit, the programmer starts sending command frames and data frames to the MCU according to the agreed commands to begin programming the MCU. Step 5: After programming is complete, the programmer sends a readback command to check if the programmed data is correct. When the MCU outputs data, it will first send a 0 to allow the programmer to determine the starting point of the data. Step 6: If the readback data is abnormal, send a reset data stream to reset the state machine and restart the programming process until the readback is normal, then end the live programming process.
2. The single-wire live programming method for MCUs with high anti-interference and stability according to claim 1, characterized in that, When designing the MCU, a special interrupt vector entry address is created. Once this interrupt is triggered, the software enables the power-on programming bit in this special interrupt function. After this bit takes effect, the MCU's internal CPU will stop running, and the corresponding communication pins will also be ready for communication. As for how to trigger this interrupt, it depends on the agreed "protocol".
3. The single-wire live programming method for MCUs with high anti-interference and stability according to claim 1, characterized in that, The MCU uses only one data line for single-pin communication, and the communication reference clock is provided by the MCU's internal clock clk. It uses a variable oversampling method of up to 16x to sample the data on the data line. The clock sample_clk for both data reception and transmission depends on a counter that implements the 16x variable oversampling.
4. The single-wire live programming method for MCUs with high anti-interference and stability according to claim 3, characterized in that, The 16x variable oversampling counter means that after the start bit is detected, the 4-bit counter will start counting from 0 to F. If no data change is detected on the data line between 0 and F, the counter will continue counting from 0 to F. If a data change is detected on the data line between 0 and F, the counter will be cleared to 0 in advance.
5. The single-wire live programming method for MCUs with high anti-interference and stability according to claim 1, characterized in that, The communication frames between the MCU and the programmer are divided into two formats: command frames and data frames. Both of these frame formats have a start bit '0' and an end bit '1'. The difference between command frames and data frames is that an accumulated error clear bit is inserted every 4 bits in the data frame.
6. The single-wire live programming method for MCUs with high anti-interference and stability according to claim 5, characterized in that, Accumulated error refers to the situation where, when receiving consecutive identical data, the sending end has a certain difference in the time length of each bit. Since the data does not change, the 16x variable oversampling counter will keep counting from 0 to F, causing the data error per bit to accumulate. After reaching a certain limit, the data will be received incorrectly. At this point, introducing an accumulated error clear bit in the data frame will solve this problem and also improve the error tolerance.
7. The single-wire live programming method for MCUs with high anti-interference and stability according to claim 6, characterized in that, When the burning process is complete and the data is read back for confirmation, if an abnormality is found during the data readback, it is highly likely that the internal state machine has malfunctioned. In this case, the independent reset circuit is needed to restore the state machine to the idle state.
8. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.