A method for remote programming and remote status detection of a microcontroller
By using optocoupler electrical isolation and independent programming control circuit, combined with adjustable baud rate and check code, the stability and complexity issues of remote programming of microcontrollers are solved, realizing efficient and safe remote programming and testing of microcontrollers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- YANCHENG INST OF TECH
- Filing Date
- 2026-03-31
- Publication Date
- 2026-06-30
AI Technical Summary
Existing methods for remote programming of microcontrollers are prone to data errors that lead to programming failures, and existing detection methods are complex and difficult to understand in detail the microcontroller's operating status.
It adopts optocoupler electrical isolation and independent programming control circuit. It achieves level compatibility by adjusting the input current and voltage through optocoupler, transmits data using adjustable baud rate, and embeds inspection code in the microcontroller firmware for remote detection.
It achieves stability and security in remote programming of microcontrollers, simplifies the testing process, and allows for in-depth understanding of the microcontroller's status without affecting its normal operation.
Smart Images

Figure CN122308852A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of microcontroller technology, specifically relating to a method for remote programming of a microcontroller and a method for remote detection of the status of a microcontroller. Background Technology
[0002] The standard microcontroller programming process involves using the official download software to download the program via serial port, and then performing a cold boot to program the microcontroller. Microcontrollers can also be programmed remotely using a Wi-Fi serial module via a network-to-serial converter, typically employing the TCP / IP protocol. If an error occurs during programming, the TCP protocol would retransmit the correct data, but this alters the programming process, potentially causing programming failure. Summary of the Invention
[0003] Purpose of the invention: To address the problems existing in the prior art, this invention proposes a method for remote programming of a microcontroller and a method for remote detection of the status of a microcontroller.
[0004] Technical solution: Firstly, a method for remote programming of a microcontroller, comprising:
[0005] The experimental microcontroller remotely receives local firmware from the server; the local firmware includes program files.
[0006] The experimental microcontroller decodes the local firmware to obtain the program file;
[0007] The experimental microcontroller will burn the program file to the designated experimental microcontroller.
[0008] Furthermore, the experimental microcontrollers are connected via serial ports and electrically isolated by optocouplers.
[0009] Furthermore, by changing the input resistance and supply voltage of the optocoupler, the input current and voltage of the optocoupler can be adjusted to achieve compatibility with experimental microcontrollers with different voltage levels.
[0010] Furthermore, each experimental microcontroller has an independent programming control circuit, which is used to perform cold start control on the experimental microcontroller.
[0011] Furthermore, the programming control circuit includes a 4-to-16 decoder and a field-effect transistor. The pins of the experimental microcontroller carrying control signals are connected to the 4-to-16 decoder, which is then connected to the field-effect transistor.
[0012] After receiving the control signal from the experimental microcontroller, the 4-16 decoder drives the field-effect transistor, causing the experimental microcontroller to be suspended, thus realizing cold start control.
[0013] Furthermore, during the process of burning the program file to the designated experimental microcontroller, an adjustable baud rate is used to realize data transmission during download and serial communication during runtime. The baud rate corresponding to data transmission during download is lower than the baud rate corresponding to serial communication during runtime.
[0014] Secondly, this invention proposes a method for remote detection of a microcontroller's status, including:
[0015] The local firmware is programmed to the designated experimental microcontroller according to the microcontroller remote programming method; wherein, the local firmware also includes check code;
[0016] During the execution of the specified experimental microcontroller program file, the inspection code uses an interrupt method to periodically check the relevant pins and registers of the specified experimental microcontroller, and sends the detection data to the server via the serial port.
[0017] The server uses the received detection data to remotely reproduce the functions of the program file, thereby enabling the detection of the operation of the specified experimental microcontroller.
[0018] Thirdly, this invention proposes a remote status detection method for a microcontroller, applied to an OLED liquid crystal module, comprising:
[0019] The local firmware is programmed to the designated experimental microcontroller according to the microcontroller remote programming method; wherein, the local firmware also includes check code;
[0020] The control pin of the specified experimental microcontroller is connected to another experimental microcontroller, which is connected to the OLED output pin of the OLED liquid crystal module; the specified experimental microcontroller indirectly controls the OLED display by connecting to the other experimental microcontroller.
[0021] During the execution of the specified experimental microcontroller's program file, another experimental microcontroller is used to detect the OLED output pins, read the OLED LCD module's cache, obtain the OLED LCD module's display status, and send the detection data to the server via serial port. The server uses the received detection data to remotely reproduce the function of the program file, thereby detecting the operation of the specified experimental microcontroller.
[0022] Another experimental microcontroller was used to read the cache of the OLED liquid crystal module to obtain the display status of the OLED liquid crystal module;
[0023] When no testing is required, another experimental microcontroller transfers control authority to the designated experimental microcontroller, only transferring control information.
[0024] Fourthly, this invention proposes a remote status detection method for a microcontroller, applied to a stepper motor system, comprising:
[0025] The local firmware is programmed to the designated experimental microcontroller according to the microcontroller remote programming method; wherein, the local firmware also includes check code;
[0026] Connect the forward and reverse control pins of the stepper motor to another experimental microcontroller, connect the control pins of the specified experimental microcontroller to another experimental microcontroller, and the specified experimental microcontroller controls the stepper motor by connecting to the other experimental microcontroller.
[0027] During the execution of the specified experimental microcontroller program file, another experimental microcontroller uses an interrupt method to periodically check the status of the control-related pins and sends the detection data to the server via the serial port.
[0028] The server uses the received detection data to remotely reproduce the function of the program file, thereby detecting the operation of the specified experimental microcontroller; when an error occurs, another experimental microcontroller controls the stepper motor.
[0029] Beneficial effects: Compared with the prior art, the present invention has the following advantages:
[0030] (1) The present invention uses a microcontroller to program the microcontroller, which makes the remote programming scheme more stable and safer. Furthermore, the opto-isolation not only eliminates interference between signals but also solves the level matching problem.
[0031] (2) This invention utilizes a decoder and an automatic level sensing circuit to solve the problem of programming multiple types of microcontrollers, and programming and operation do not affect each other;
[0032] (3) In this invention, the remote transmission is changed from C / S structure to CSC structure. The local firmware is uploaded to the server, and the server sends it to the client. The client's microcontroller decodes the firmware and then starts the microcontroller programming process. The programming process is not placed on the network, which ensures the success rate of programming.
[0033] (4) After the programming is completed, in order to detect the operation of the microcontroller, the present invention analyzes the microcontroller firmware and transplants special function code into the firmware. Without affecting the normal operation of the microcontroller, the microcontroller, pins and registers are checked and the status of the microcontroller is transmitted to the client that needs to know the status of the microcontroller for display. The detection method of the present invention is simpler and more in-depth. Attached Figure Description
[0034] Figure 1 This is a circuit diagram for downloading three types of microcontrollers; where IO8 and IO18 are serial ports. Figure 1 The upper left corner is the optical coupler, which serves an isolation function. Figure 1The three blocks in the lower right corner represent the low, high, and low levels output by OUTA, OUTB, and OUTC respectively after the input signal changes. Detailed Implementation
[0035] The technical solution of the present invention will now be further described in conjunction with the accompanying drawings and embodiments.
[0036] Example 1:
[0037] This invention provides a method for remote programming of a microcontroller, comprising:
[0038] The experimental microcontroller remotely receives local firmware from the server; in this embodiment of the invention, the local firmware includes program files.
[0039] The experimental microcontroller decodes the local firmware to obtain the program file.
[0040] The experimental microcontroller will burn the program file to the designated experimental microcontroller.
[0041] In existing technologies, microcontrollers are programmed using a network-to-serial converter. The server and the microcontroller communicate according to the programming protocol, which can easily lead to data errors and programming failures. Therefore, this invention remotely transmits the local firmware to the microcontroller's cache. After receiving the firmware, the cached firmware is programmed into the specified microcontroller. Even if errors occur during firmware transmission, the programming process will not be affected.
[0042] Example 2:
[0043] This invention provides a method for remote programming of a microcontroller, comprising:
[0044] The experimental microcontroller remotely receives local firmware from the server; in this embodiment of the invention, the local firmware includes program files.
[0045] The experimental microcontroller decodes the local firmware to obtain the program file.
[0046] The experimental microcontroller will burn the program file to the designated experimental microcontroller.
[0047] As one implementation, this invention involves multiple experimental microcontrollers connected via serial ports and electrically isolated by optocouplers. The input current and voltage of the optocouplers are adjusted by changing their input resistance and supply voltage, resolving the issue of inconsistent signal levels and mutual interference between different serial port devices, thus achieving compatibility with experimental microcontrollers of different signal levels. Each experimental microcontroller has an independent programming control circuit for cold start control. For example, this programming control circuit includes a 4-to-16 decoder, a field-effect transistor (FET), and an inverter. The experimental microcontroller sends control signals through pins; the pins with control signals are connected to the 4-to-16 decoder, which is then connected to the FET. If the signal needs to be inverted, an inverter is connected to reverse the signal. The problem of programming and downloading control is solved in hardware. One end of the field-effect transistor is grounded, and the other end is connected to the ground pin of the experimental microcontroller. After the 4-16 decoder receives the control signal from the experimental microcontroller, it drives the field-effect transistor to make the ground of the experimental microcontroller floating, thereby realizing cold start control.
[0048] For example, using ESP32 as the master controller / programmer, the most suitable reset method is adopted for different types of microcontrollers (Arduino, STM32, 51 series) to achieve large-volume, high-efficiency firmware programming, including: Arduino programming method: RST reset, STM32 programming method: boot pin control, 51 microcontroller programming method: power cold start.
[0049] In this embodiment of the invention, during the process of burning the program file to the designated experimental microcontroller, an adjustable baud rate is used to achieve data transmission during download and serial communication during runtime. The baud rate corresponding to data transmission during download is lower than the baud rate corresponding to serial communication during runtime. This embodiment uses an adjustable baud rate to stabilize data transmission. During download, the data transmission volume is large, so a low baud rate (e.g., 9600) is used to address the error-prone nature of low-speed optical coupler transmission. During runtime, the serial communication volume is small, so a high baud rate, such as 115200, can be used as an optimization scheme. Parity checking is also added to ensure data accuracy.
[0050] In this embodiment of the invention, the TCP client and server are not always connected; they connect only when needed and do not consume resources. The TCP client can be specifically understood as a network application running inside the microcontroller. It is responsible for actively initiating a network connection with the server (usually a PC) to establish a communication channel and realize the transmission and burning of firmware data.
[0051] This invention employs a microcontroller-based programming method, resulting in a more stable and secure remote programming solution. Furthermore, opto-isolation eliminates signal interference and resolves level matching issues. A decoder and automatic level sensing circuit are used to program various types of microcontrollers, ensuring that programming and operation do not interfere with each other. Figure 1 The three block diagrams in the lower right corner show how OUTA, OUTB, and OUTC output low, high, and low levels respectively after the input signal changes. OUTB uses a transistor for signal inversion. The block diagram also shows a sensing circuit; once the input signal changes, such as from high to low, a fixed output signal is generated.
[0052] This invention changes the remote transmission from a C / S structure to a CSC structure (client-server-client). The local firmware is uploaded to the server, which then sends it to the client. The client's microcontroller decodes the firmware and begins the microcontroller programming process. The programming process is not placed on the network, which ensures the success rate of programming.
[0053] Example 3:
[0054] This invention proposes a method for remote detection of a microcontroller's status, comprising:
[0055] According to the microcontroller remote programming method proposed in Embodiment 1 or Embodiment 2, the local firmware is programmed to the specified experimental microcontroller; wherein, the local firmware also includes check code.
[0056] During the execution of the specified experimental microcontroller program file, the inspection code uses an interrupt method to periodically check the relevant pins and registers of the specified experimental microcontroller, and sends the detection data to the server via the serial port.
[0057] The server uses the received detection data to remotely reproduce the functions of the program file, thereby enabling the detection of the operation of the specified experimental microcontroller.
[0058] For example, the program code of the 51 microcontroller is stored starting from address 0000H. In this embodiment of the invention, the microcontroller firmware code is sent to the microcontroller's cache via remote transmission. Then, check code that periodically checks the microcontroller pins and registers is embedded into the firmware. The method is as follows: when burning the microcontroller program, 0000H is replaced with a preset address, and then the program jumps to the pre-designed check code. This check code executes like a virus. After running the check code, the pointer returns to the original program position. In this embodiment of the invention, the check code occupies a remote and infrequently used timer and uses interrupt mode to periodically detect the running microcontroller pins and some registers. Then, the serial port is used to send the detection data to the remote client. For example, if the microcontroller firmware is set to a running light display program, the check code will specifically check the level changes and timing of specified pins. It can also detect the microcontroller's internal registers to determine whether the program meets expectations, thereby evaluating the microcontroller firmware. The detected parameters are then used to reproduce the firmware's function on the remote client.
[0059] Example 4:
[0060] This invention proposes a remote status detection method for a microcontroller, applied to an OLED liquid crystal module. The display logic of an OLED liquid crystal module is very complex and difficult to parse, therefore it is not suitable for detecting the specified code proposed in Embodiment 3. Therefore, this invention makes hardware improvements, including:
[0061] According to the microcontroller remote programming method of Embodiment 1 or Embodiment 2, the local firmware is programmed to the specified experimental microcontroller; wherein, the local firmware also includes check code.
[0062] The control pins of the designated experimental microcontroller are connected to another experimental microcontroller, which in turn connects to the OLED LCD module. Here, the other experimental microcontroller serves as the evaluation microcontroller. The designated experimental microcontroller indirectly controls the OLED LCD module display through this adapter.
[0063] During the execution of the specified experimental microcontroller's program file, the evaluation microcontroller is used to test the connected OLED output pins, read the OLED LCD module's buffer, obtain the OLED LCD module's display status, and send the test data to the server via serial port. The testing microcontroller is used to detect pin changes of the specified experimental microcontroller, transferring the data to the OLED pins through high-frequency scanning, thus not affecting the normal display of the OLED. When it is necessary to understand the OLED display status, the testing microcontroller directly reads the OLED's buffer, thereby achieving mastery of the experimental microcontroller's program functionality.
[0064] The server uses the received detection data to remotely reproduce the functions of the program file, thereby enabling the detection of the operation of the specified experimental microcontroller.
[0065] Another experimental microcontroller is used to read the cache of the OLED LCD module to obtain its display status. The designated experimental microcontroller controls the evaluation microcontroller to indirectly control the OLED LCD module. When testing the data displayed on the OLED LCD module, the connection between the two is disconnected, i.e., the synchronization function of the testing microcontroller is broken. After desynchronization, the testing microcontroller directly reads the OLED display cache. This ensures that the two microcontrollers do not interfere with each other, yet both can control the OLED LCD module. The testing microcontroller then displays the test data on a remote client for reproduction. Furthermore, bandwidth and CPU usage are reduced, increasing flexibility. When not testing, the evaluation microcontroller relinquishes control to the experimental microcontroller, merely relaying control information.
[0066] In practical applications, there are typically two choices for data interaction between the client (experimental microcontroller) and the server. The first is the traditional polling mechanism, where the client needs to periodically send query requests to the server or actively send data after receiving it from the server. In this mode, the client must periodically check if there are any new data updates on the server to ensure the continuity of data transmission. In contrast, this embodiment of the invention employs an asynchronous mirroring technology similar to a 'digital twin'. Specifically, when detecting the microcontroller's status, the parameters of its ports and registers are extracted, and the corresponding functions are run on the server. For example, after completing the programming of the LED flashing light program, the relevant register parameters are extracted and uploaded to the remote server. After receiving these parameters, the remote end can reproduce the internal operating status of the microcontroller without the need for real-time monitoring of the camera footage. This parameter-based remote status reproduction method is called 'asynchronous mirroring', and its advantage lies in its ability to monitor and remotely send the internal status information of the microcontroller in real time, thereby achieving accurate remote reproduction and monitoring.
[0067] Example 5:
[0068] This invention proposes a remote status detection method for a microcontroller, applied to a stepper motor system, comprising:
[0069] According to the microcontroller remote programming method proposed in Embodiment 1 or Embodiment 2, the local firmware is programmed to the specified experimental microcontroller; wherein, the local firmware also includes check code.
[0070] The forward and reverse control pins of the stepper motor are connected to another experimental microcontroller, and the control pins of a designated experimental microcontroller are connected to another experimental microcontroller. The designated experimental microcontroller controls the stepper motor by transferring the other experimental microcontroller. In this embodiment of the invention, the other experimental microcontroller is used as the evaluation microcontroller.
[0071] During the execution of the specified experimental microcontroller's program file, the evaluation microcontroller checks the status of the control-related pins and sends the detection data to the server via the serial port. The server uses the received detection data to remotely reproduce the function of the program file, thereby enabling the detection of the specified experimental microcontroller's operation. When an error occurs, such as the motor rotating to its limit and needing to reverse, another experimental microcontroller controls the stepper motor.
[0072] When experimenting with remotely controlled stepper motor systems, the lack of camera monitoring typically relies on limit switches to determine the stepper motor's operating status. If the stepper motor exceeds its limit range due to firmware errors and no corresponding stop measures are taken, it may lead to bearing damage or even burnout. To effectively prevent such accidental damage caused by firmware errors, this embodiment of the invention modifies the control logic: the forward and reverse control pins of the stepper motor are directly connected to another experimental microcontroller, i.e., the evaluation microcontroller, while the control pins of a designated experimental microcontroller are connected to the evaluation microcontroller. During actual operation, if a firmware error causes the stepper motor to exceed its limit, the evaluation microcontroller will immediately identify the abnormal situation and take over control, triggering the stepper motor to turn around or stop rotating. Simultaneously, the evaluation microcontroller will send a warning signal to the designated experimental microcontroller. This embodiment of the invention successfully solves the safety hazards in the remote control process by introducing the evaluation microcontroller to take over the control logic, achieving comprehensive safety evaluation and protection.
[0073] In summary, programming requires a stable and reliable working environment. Therefore, the firmware for the microcontroller can be transferred to a high-performance microcontroller, such as an ESP32 microcontroller. The firmware program is downloaded to the ESP32's cache. When programming begins, the ESP32 microcontroller controls the microcontroller to perform a cold start operation, and then programs the microcontroller according to the official software's programming protocol. To ensure correct programming, improvements to the communication hardware and software are needed to match the programming protocol.
[0074] To support multiple MCUs (e.g., 30 different types of microcontrollers such as STM32, 51, and Arduino), level compatibility needs to be considered. Besides level compatibility, the mutual interference of different serial port devices must also be considered. If different serial port devices interfere with each other, all serial port devices will fail to communicate normally. Therefore, this invention uses optocouplers to isolate different serial port devices without affecting serial data transmission. Furthermore, for different level conditions (e.g., 3.3V, 5V), the input resistance and supply voltage of the optocoupler can be changed to adjust the input current and voltage, ensuring normal signal transmission. Because the transmission signal frequency of the optocoupler is not high, a variable baud rate scheme is required to avoid affecting transmission. During the programming process, a large amount of data needs to be transmitted. The microcontroller automatically reduces the transmission baud rate during programming. In ordinary serial communication, to improve transmission speed while the amount of data transmitted is generally small, and to avoid the serious consequences of programming failure when errors occur, parity checking can be added to correct errors, improving accuracy and speed.
[0075] To ensure proper programming of multiple microcontrollers without affecting their normal operation, this invention connects the microcontrollers for serial programming together via hardware. Furthermore, to prevent mutual interference during programming, each microcontroller has an independent control scheme. For example, when programming multiple 51 microcontrollers, a cold start control is implemented on one of them to prevent the other 51 microcontrollers from entering the programming state and affecting the programming process.
[0076] After the microcontroller is programmed, there are two ways to check its operation: one is to directly observe the display device status, and the other is to use an emulator to simulate the microcontroller and read its registers. There are also ways to check the status of external pins. However, the detection method of this invention is simpler and more in-depth. By parsing the microcontroller firmware and embedding special function code in the firmware, the microcontroller, its pins and registers are checked without affecting its normal operation. The microcontroller's status is then transmitted to the client that needs to know the microcontroller's status for display.
Claims
1. A method for remote programming of a microcontroller, characterized in that: include: The experimental microcontroller remotely receives local firmware from the server; the local firmware includes program files. The experimental microcontroller decodes the local firmware to obtain the program file; The experimental microcontroller will burn the program file to the designated experimental microcontroller.
2. The method for remote programming of a single-chip microcomputer according to claim 1, characterized in that: The experimental microcontrollers are connected via serial ports and electrically isolated by optocouplers.
3. The method of claim 2, wherein the single-chip microcomputer is remotely programmed. By changing the input resistance and supply voltage of the optocoupler, the input current and voltage of the optocoupler can be adjusted, enabling experimental microcontrollers with different voltage levels to be compatible.
4. The method for remote programming of a single-chip microcomputer according to claim 1, characterized in that: Each experimental microcontroller has an independent programming control circuit, which is used to perform cold start control on the experimental microcontroller.
5. The method for remote programming of a single-chip microcomputer according to claim 3, characterized in that: The programming control circuit includes a 4-to-16 decoder and a field-effect transistor. The control signal pin of the experimental microcontroller is connected to the 4-to-16 decoder, which is then connected to the field-effect transistor. After receiving the control signal from the experimental microcontroller, the 4-16 decoder drives the field-effect transistor, causing the experimental microcontroller to be suspended, thus realizing cold start control.
6. The method for remote burning of a single-chip microcomputer according to claim 1, characterized in that: During the process of burning the program file to the designated experimental microcontroller, an adjustable baud rate is used to realize data transmission during download and serial communication during runtime. The baud rate corresponding to data transmission during download is lower than the baud rate corresponding to serial communication during runtime.
7. A method for remote detection of the state of a single-chip computer, characterized in that: include: A method for remotely programming a microcontroller according to any one of claims 1 to 6 is used to program local firmware to a specified experimental microcontroller; wherein the local firmware further includes check code; During the execution of the specified experimental microcontroller program file, the inspection code uses an interrupt method to periodically check the relevant pins and registers of the specified experimental microcontroller, and calls the serial port to send the detection data to the server. The server uses the received detection data to remotely reproduce the functions of the program file, thereby enabling the detection of the operation of the specified experimental microcontroller.
8. A single-chip computer state remote detection method applied to an OLED liquid crystal module, characterized in that: include: A method for remotely programming a microcontroller according to any one of claims 1 to 6 is used to program local firmware to a specified experimental microcontroller; wherein the local firmware further includes check code; The control pin of the specified experimental microcontroller is connected to another experimental microcontroller, which is connected to the OLED output pin of the OLED liquid crystal module; the specified experimental microcontroller indirectly controls the OLED display by connecting to the other experimental microcontroller. During the execution of the specified experimental microcontroller's program file, another experimental microcontroller is used to detect the OLED output pins, read the OLED LCD module's cache, obtain the OLED LCD module's display status, and send the detection data to the server via serial port. The server uses the received detection data to remotely reproduce the function of the program file, thereby detecting the operation of the specified experimental microcontroller. Another experimental microcontroller was used to read the cache of the OLED liquid crystal module to obtain the display status of the OLED liquid crystal module; When no testing is required, another experimental microcontroller transfers control authority to the designated experimental microcontroller, only transferring control information.
9. A method for remote detection of microcontroller status, applied to a stepper motor system, characterized in that: A method for remotely programming a microcontroller according to any one of claims 1 to 6 is used to program local firmware to a specified experimental microcontroller; wherein the local firmware further includes check code; Connect the forward and reverse control pins of the stepper motor to another experimental microcontroller, connect the control pins of the specified experimental microcontroller to another experimental microcontroller, and the specified experimental microcontroller controls the stepper motor by connecting to the other experimental microcontroller. During the execution of the specified experimental microcontroller program file, another experimental microcontroller uses an interrupt method to periodically check the status of the control-related pins and sends the detection data to the server via the serial port. The server uses the received detection data to remotely reproduce the function of the program file, thereby detecting the operation of the specified experimental microcontroller; when an error occurs, another experimental microcontroller controls the stepper motor.