Wireless firmware upgrading method and system of microcontroller

By using segmented download of wireless communication modules and HTTP breakpoint resume, combined with a backup area and BootLoader program, the hardware complexity and transmission efficiency issues of the STM32 OTA solution are solved, achieving simplified design and efficient and reliable firmware upgrades.

CN121879810APending Publication Date: 2026-04-17SHANGHAI PINDOU CHENGFU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI PINDOU CHENGFU INTELLIGENT TECH CO LTD
Filing Date
2025-12-24
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Traditional STM32 OTA solutions require external Flash storage, increasing hardware design complexity and cost. Furthermore, the HTTP protocol is inefficient in terms of breakpoint resumption, file verification, and cross-platform compatibility, making it difficult to meet the upgrade requirements of low cost and high reliability.

Method used

The firmware information file is downloaded in segments using a wireless communication module. Taking advantage of the HTTP protocol's ability to resume interrupted downloads, the backup area is used for storage, and the main program area is overwritten after confirmation of completeness. Combined with the upgrade flag and the BootLoader program, the control logic is simplified, ensuring a safe and reliable upgrade.

Benefits of technology

No external storage device is required, simplifying hardware design, improving transmission stability and security, avoiding upgrade failures due to network interruptions, and meeting the needs for efficient and reliable firmware upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121879810A_ABST
    Figure CN121879810A_ABST
Patent Text Reader

Abstract

The invention discloses a wireless firmware upgrading method and system for a microcontroller, and relates to the technical field of artificial intelligence, and the method comprises the steps: obtaining a firmware information file from a server through the microcontroller in response to a hypertext transfer protocol obtaining request; downloading the firmware information file segment by segment through a wireless communication module, and transmitting the firmware information file to a backup area of the microcontroller by taking a preset data volume as a single transmission unit; whether the firmware information file is completely downloaded or not is judged, if yes, an upgrading flag bit of the microcontroller is set, the microcontroller is controlled to be restarted, the firmware information file in the backup area is overwritten to a main program area of the microcontroller, and the problem that wireless firmware upgrading of the microcontroller cannot be achieved in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a wireless firmware upgrade method and system for a microcontroller. Background Technology

[0002] With the popularization of IoT technology, microcontrollers (such as the STM32 series) are widely used in smart hardware, industrial control and other scenarios. Over-the-air (OTA) firmware upgrades have become a key technology to ensure the iteration of equipment functions and the repair of faults.

[0003] Traditional STM32 OTA solutions have significant limitations in practical applications: On the one hand, most solutions rely on external Flash storage for upgrade files, which not only increases the complexity of hardware design but also raises material and production costs, hindering the miniaturization and low-cost design of devices; on the other hand, existing implementations often rely on complex communication protocols such as MQTT, while the inherent advantages of Hypertext Transfer Protocol (HTTP) in terms of breakpoint resumption, file verification, and cross-platform compatibility are not fully utilized, resulting in cumbersome protocol deployment and low data transmission efficiency, making it difficult to meet the upgrade requirements of low cost and high reliability.

[0004] Therefore, there is an urgent need for a wireless firmware upgrade method for microcontrollers that does not require external storage and fully leverages the advantages of the HTTP protocol. Summary of the Invention

[0005] In view of this, the present invention proposes a wireless firmware upgrade method and system for microcontrollers, which can realize wireless firmware upgrade of microcontrollers.

[0006] To achieve the above objectives, the present invention provides the following technical solution: A method for wireless firmware upgrade of a microcontroller, comprising: In response to a Hypertext Transfer Protocol (HTTP) request, the firmware information file is retrieved from the server via the microcontroller. The firmware information file is downloaded in segments via a wireless communication module, and the firmware information file is transmitted to the backup area of ​​the microcontroller in a single transmission unit with a preset data volume. Determine whether the firmware information file has been completely downloaded. If so, overwrite the firmware information file in the backup area to the main program area of ​​the microcontroller.

[0007] Based on the above technical solution, the present invention can be further improved as follows: Optionally, before the step of transferring the firmware information file to the backup area of ​​the microcontroller in a single transmission unit of a preset data volume, the following steps are included: A file system access loop is triggered whenever a fixed number of firmware information files are downloaded.

[0008] Optionally, the microcontroller is an STM32 series microcontroller.

[0009] Optionally, the fixed quantity is 20,000 bytes, and the preset data quantity is 800 bytes.

[0010] Optionally, if the firmware information file is fully downloaded, the method further includes: Set the upgrade flag of the microcontroller; after overwriting the firmware information file in the backup area to the main program area of ​​the microcontroller, clear the upgrade flag of the microcontroller.

[0011] Optionally, the wireless firmware upgrade method for the microcontroller further includes: If the wireless communication module fails to download the firmware information file, the wireless communication module will be restarted to download the firmware information file again.

[0012] Optionally, the microcontroller is an STM32 microcontroller, and the wireless communication module is an EC800 series 4G module.

[0013] A wireless firmware upgrade system for a microcontroller, comprising: The microcontroller is used to retrieve firmware information files from the server in response to a Hypertext Transfer Protocol (HTTP) request. A wireless communication module is used to download the firmware information file in segments, and transmit the firmware information file to the backup area of ​​the microcontroller in a single transmission unit with a preset data volume. The microcontroller is also used to determine whether the firmware information file has been completely downloaded. If so, the firmware information file in the backup area is overwritten to the main program area of ​​the microcontroller.

[0014] An electronic device includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of the method described herein.

[0015] A non-transitory computer-readable storage medium having a computer program stored thereon, the computer program implementing the steps of the method when executed by a processor.

[0016] The present invention has the following advantages: The wireless firmware upgrade method for microcontrollers in this invention eliminates the need for external Flash storage, directly utilizing the microcontroller's own backup area to store firmware files, significantly simplifying hardware design. Based on the HTTP protocol and segmented downloading, the advantages of HTTP's resume capability avoid the need to re-download all files due to network interruptions. The preset data volume per transmission unit also reduces the risk of data loss and improves transmission stability. The process of complete download judgment, setting the upgrade flag, and then restarting to overwrite effectively avoids device failures caused by upgrade interruptions. It eliminates the need for complex partition mutual exclusion logic, simplifying control logic while ensuring upgrade security, and meeting the needs for efficient and reliable firmware upgrades in various scenarios. Attached Figure Description

[0017] For illustrative and not limiting purposes, the present invention will now be described in conjunction with embodiments and accompanying drawings, wherein: Figure 1 This is a schematic diagram of the first process of the wireless firmware upgrade method for a microcontroller in an embodiment of the present invention. Figure 2 This is a schematic diagram of the second process of the wireless firmware upgrade method for a microcontroller in an embodiment of the present invention. Figure 3 This is a schematic diagram of the main components of the wireless firmware upgrade system for a microcontroller in an embodiment of the present invention. Figure 4 This is a hardware connection diagram of the wireless firmware upgrade system for a microcontroller in an embodiment of the present invention. Figure 5 This is a diagram showing the firmware storage partition structure of the wireless firmware upgrade system for a microcontroller in an embodiment of the present invention. Figure 6 This is a schematic diagram of the physical structure of the electronic device provided by the present invention. Detailed Implementation

[0018] To enable those skilled in the art to better understand the present invention, 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 a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0019] It should be noted that the terms "first," "second," etc., in the specification and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be used interchangeably where appropriate for the embodiments of the invention described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0020] It should be noted that, where there is no conflict, the embodiments and features of the present invention can be combined with each other. The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0021] Figure 1 This is a schematic diagram of the first process of the wireless firmware upgrade method for a microcontroller according to an embodiment of the present invention, as shown below. Figure 1 As shown, the wireless firmware upgrade method for a microcontroller provided in this embodiment of the invention includes the following steps S101 to S103.

[0022] S101, in response to a Hypertext Transfer Protocol (HTTP) retrieval request, retrieves the firmware information file from the server via the microcontroller.

[0023] The microcontroller is an STM32 microcontroller (RAM≥20KB, Flash≥256KB).

[0024] The firmware information file typically contains the download address of the actual firmware package, providing the target path for segmented download of the wireless communication module (EC800 module).

[0025] S102 downloads firmware information files in segments through the wireless communication module, transmitting the firmware information files to the microcontroller's backup area with a preset data volume as a single transmission unit.

[0026] Before the step of transferring the firmware information file to the backup area of ​​the microcontroller in a single transmission unit using a preset data volume, the following steps are included: A file system access loop is triggered whenever a fixed number of firmware information files are downloaded.

[0027] The fixed quantity is 20,000 bytes, and the preset data quantity is 800 bytes.

[0028] Large firmware packages (such as tens to hundreds of KB) are divided into 20,000-byte chunks for download. Combined with the HTTPRange header to support resume download (if the network is interrupted, there is no need to re-download the entire package, only the incomplete part is re-downloaded), thus improving download reliability. The / ota / user.bin path in the EC800 module's built-in file system is used as a "temporary repository" to cache the downloaded firmware information file first, avoiding memory overflow caused by the STM32 directly receiving it (STM32 RAM is usually only about 20KB, which cannot directly hold the complete firmware information file). Using 800 bytes as the minimum transmission unit, the firmware information file cached by EC800 is gradually transferred to the backup area of ​​STM32. This matches the UART communication bandwidth of STM32 (115200bps) and avoids packet loss caused by excessive data transmission in a single transmission. At the same time, the "backup area" is independent of the main program area and will not overwrite the currently running firmware (ensuring that the device does not crash during the upgrade process).

[0029] S103 determines whether the firmware information file has been completely downloaded. If so, it sets the upgrade flag of the microcontroller and controls the microcontroller to restart, overwriting the firmware information file in the backup area to the main program area of ​​the microcontroller.

[0030] Writing a preset identifier (such as 0x55AA) to a specific address (such as 0x08021FFC) in the STM32 Flash is equivalent to leaving a "note" for the BootLoader program, informing it that "there is new firmware in the backup area, which needs to be installed"; The purpose of controlling the STM32 to restart is to switch the device from "normal operation mode" to "upgrade preparation mode". After restarting, the BootLoader program will be executed first instead of the main program, in order to prepare for subsequent firmware overwrite. A reboot is only triggered after the firmware has been completely downloaded (confirmed to be undamaged via a verification code) to avoid upgrade failure due to incomplete firmware. After the STM32 reboots, it will first execute the bootloader stored in the BootLoader area (0x08000000-0x08004000). This program is small in size, has a single function, and is only responsible for firmware upgrade-related operations, making it extremely stable. The BootLoader checks the previously set upgrade flag. Once it confirms that an upgrade is needed, it performs a firmware overwrite in the "backup area → main program area" (equivalent to "copying and pasting" the new firmware to the old firmware location). After the overwrite is complete, the upgrade flag is restored to its default value (e.g., 0x0000) to prevent the upgrade from being performed repeatedly on the next reboot. The overwrite process is completed independently by the BootLoader, without relying on the main program, and is only executed when the firmware is confirmed to be intact to prevent the main program area from being damaged (if the overwrite fails, the old firmware in the backup area can still be used through the BootLoader on the next restart of the device to avoid bricking).

[0031] The wireless firmware upgrade method for the microcontroller further includes: If the wireless communication module fails to download the firmware information file, the wireless communication module should be restarted to download the firmware information file again.

[0032] Figure 2 This is a schematic diagram of the second process of the wireless firmware upgrade method for a microcontroller in an embodiment of the present invention, as shown below. Figure 2 As shown, this invention achieves remote firmware upgrades for 4G modules in conjunction with STM32 through a closed loop of "command triggering → communication adjustment → file download → data transfer → program replacement," solving the pain point of "device programs needing on-site updates" and supporting "remote operation and maintenance and online iteration functions" for IoT devices. It is commonly found in OTA (over-the-air) upgrade scenarios for industrial data acquisition terminals and smart IoT devices.

[0033] 1. Upgrade Trigger Upgrade command received via TCP channel: The device receives the "upgrade command" issued by the platform / server via TCP communication and initiates the upgrade process.

[0034] 2. Communication configuration adjustment Adjust the HTTP settings of the 4G module, including disabling response headers: Modify the HTTP communication parameters of the 4G module (such as disabling default response headers and simplifying the protocol) to prepare for "obtaining upgrade files" (reduce data redundancy and improve download efficiency).

[0035] 3. Obtaining the upgrade file The HTTP GET request accesses the URL where the upgrade files are stored, and retrieves the upgrade package. Retry continuously until the update file is successfully obtained: If the download fails (due to network fluctuations or file non-existence), keep retrying to ensure that the complete upgrade file is obtained.

[0036] 4. Data transfer and writing Transfer to the internal flash memory of the 4G module: First, temporarily store the downloaded upgrade file in the flash memory of the 4G module (as transitional storage). Repeatedly read the 4G module flash memory and write it to the STM32's backup area: Read the upgrade data from the 4G module flash memory and write it to the STM32 microcontroller's "backup storage area" (in preparation to replace the original program).

[0037] 5. Program replacement and restart Return to the bootloader and perform the app replacement: Enter the STM32's Bootloader mode (system bootloader), replace the original APP area with the new program in the backup area, and complete the firmware upgrade; after replacement, restart the device, and the new program will take effect.

[0038] Figure 3 This is a schematic diagram of the main components of the wireless firmware upgrade system for a microcontroller according to an embodiment of the present invention. Figure 3 As shown, the wireless firmware upgrade system 1 for a microcontroller provided in this embodiment of the invention includes a microcontroller 10 and a wireless communication module 20.

[0039] Microcontroller 10 is used to retrieve firmware information files from the server in response to a Hypertext Transfer Protocol (HTTP) retrieval request; The wireless communication module 20 is used to download the firmware information file in segments, and transmit the firmware information file to the backup area of ​​the microcontroller in a single transmission unit with a preset data volume. The microcontroller is also used to determine whether the firmware information file has been completely downloaded. If so, it sets the upgrade flag of the microcontroller and controls the microcontroller to restart, overwriting the firmware information file in the backup area to the main program area of ​​the microcontroller.

[0040] Figure 4 This is a hardware connection diagram of the wireless firmware upgrade system for a microcontroller according to an embodiment of the present invention. Figure 4 As shown, the STM32 acts as the main controller, controlling the power supply module through the PC2 pin to achieve intelligent management of the EC800's power supply, such as shutting down the module to save energy in low-power scenarios. Simultaneously, a UART serial communication link is established using PB10 (connected to the EC800's RXD receiver) and PB11 (connected to the EC800's TXD transmitter). The STM32 can send AT commands and control commands to the EC800 through this link, and the EC800 will return network responses and data, facilitating device networking and information exchange. This is commonly seen in IoT remote data acquisition and 4G networked devices.

[0041] Figure 5 This is a diagram showing the firmware storage partition structure of the wireless firmware upgrade system for a microcontroller according to an embodiment of the present invention. Figure 5 As shown, the Flash space is divided into a main program area and a backup area, and storage units are managed using "sectors". The core logic is as follows: Main program area: Contains multiple sectors (sector1, sector2, etc.), starting from address 0x08004000 and ending at address 0x08022000, used to store the currently running program code and data.

[0042] Backup area: It is also divided into sectors, starting from address 0x08022000 and ending at address 0x08040000. It serves as a redundancy / upgrade backup for the "main program area" (e.g., during OTA upgrades, the new program is first stored here, verified, and then replaced in the main area).

[0043] By using "primary-backup partitions", functions such as redundant program storage, fault recovery, and remote upgrades are achieved, ensuring system reliability (for example, if the program in the primary partition is damaged, it can be recovered from the backup partition).

[0044] Figure 6 This is a schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as... Figure 6 As shown, the electronic device 30 includes: a processor 301, a memory 302, and a bus 303; The processor 301 and the memory 302 communicate with each other via the bus 303. The processor 301 is used to call program instructions in the memory 302 to execute the methods provided in the above-described method embodiments, and to execute the methods provided in the embodiments of the present invention.

[0045] This embodiment provides a non-transitory computer-readable storage medium that stores computer instructions, which cause a computer to execute the method provided in this embodiment of the invention.

[0046] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various storage media capable of storing program code, such as ROM, RAM, magnetic disk, or optical disk.

[0047] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A wireless firmware upgrade method for a microcontroller, characterized in that, include: In response to a Hypertext Transfer Protocol (HTTP) request, the firmware information file is retrieved from the server via the microcontroller. The firmware information file is downloaded in segments via a wireless communication module, and the firmware information file is transmitted to the backup area of ​​the microcontroller in a single transmission unit with a preset data volume. Determine whether the firmware information file has been completely downloaded. If so, overwrite the firmware information file in the backup area to the main program area of ​​the microcontroller.

2. The wireless firmware upgrade method for a microcontroller according to claim 1, characterized in that, Before the step of transferring the firmware information file to the backup area of ​​the microcontroller in a single transmission unit using a preset data volume, the following steps are included: A file system access loop is triggered whenever a fixed number of firmware information files are downloaded.

3. The wireless firmware upgrade method for a microcontroller according to claim 1, characterized in that, The microcontroller is an STM32 series microcontroller.

4. The wireless firmware upgrade method for a microcontroller according to claim 2, characterized in that, The fixed quantity is 20,000 bytes, and the preset data quantity is 800 bytes.

5. The wireless firmware upgrade method for a microcontroller according to claim 1, characterized in that, When the firmware information file is fully downloaded, the method further includes: Set the upgrade flag of the microcontroller; after overwriting the firmware information file in the backup area to the main program area of ​​the microcontroller, clear the upgrade flag of the microcontroller.

6. The wireless firmware upgrade method for a microcontroller according to claim 1, characterized in that, The wireless firmware upgrade method for the microcontroller further includes: If the wireless communication module fails to download the firmware information file, the wireless communication module will be restarted to download the firmware information file again.

7. The wireless firmware upgrade method for a microcontroller according to claim 1, characterized in that, The microcontroller is an STM32 microcontroller, and the wireless communication module is an EC800 series 4G module.

8. A system for wireless firmware upgrade of a microcontroller, characterized in that, include: The microcontroller is used to retrieve firmware information files from the server in response to a Hypertext Transfer Protocol (HTTP) request. A wireless communication module is used to download the firmware information file in segments, and transmit the firmware information file to the backup area of ​​the microcontroller in a single transmission unit with a preset data volume. The microcontroller is also used to determine whether the firmware information file has been completely downloaded. If so, the firmware information file in the backup area is overwritten to the main program area of ​​the microcontroller.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 7.

10. A non-transitory computer-readable 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 as described in any one of claims 1 to 7.