MCU bootstrap mode switching method, switching circuit and software upgrading method

By configuring mode switching control ports and using edge trigger signals to switch MCU bootstrap mode, the problems of cumbersome upgrade methods and security risks of traditional MCU software are solved, and efficient software upgrade without disassembly is achieved.

CN119536770APending Publication Date: 2025-02-28CHINA ENERGY CONSTR ENERGY STORAGE TECH (WUHAN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411608869.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-12
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

The traditional MCU software upgrade method requires disassembly, which is cumbersome and has security risks, and the bootstrap mode switching is complex, resulting in high development costs and low efficiency.

Method used

By configuring the mode switching control port as the input port to prevent error switching, it is converted to the output port when upgrading is required, and the MCU bootstrap mode is switched using edge trigger signals to achieve software upgrade.

Benefits of technology

It realizes the MCU software upgrade without disassembling the machine, improving the security, convenience, speed, efficiency and simplicity of the upgrade.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536770A_ABST
    Figure CN119536770A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of power electronics, and provides an MCU bootstrap mode switching method, a switching circuit and a software upgrading method, a mode switching control port used for controlling bootstrap mode switching is configured as an input port when an MCU operates normally, and mistaken bootstrap mode switching is prevented; when software upgrading needs to be carried out, the mode switching control port is converted into an output port, and the state of the mode configuration port is controlled in an edge triggering mode, so that the bootstrap mode of the MCU is switched, and online programming / software updating is carried out. And after updating is completed, the system is powered off and powered on again, the bootstrap mode of the main Flash (flash memory) is restored by default, and the MCU can enter application program operation. According to the method, manual operation configuration or changing is not needed, online upgrading or changing of MCU software can be achieved only through software operation, the bootstrap mode of the MCU can be switched and kept, software upgrading is achieved under the condition that a machine is not disassembled, and the safety, convenience, rapidness, high efficiency and simplicity of software upgrading are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electronic circuits, and more specifically, to an MCU bootstrap mode switching method, a switching circuit and a software upgrade method. Background Art

[0002] Microcontroller Unit (MCU), also known as single chip microcomputer or single chip microcomputer, such as the well-known ST series of STMicroelectronics, appropriately reduces the frequency and specifications of the central processing unit (CPU), and integrates peripheral interfaces such as memory, timer, USB, A / D conversion, UART, PLC, DMA, and even part of the driving circuit on a single chip to form a chip-level computer, which can perform different combination controls for different application scenarios.

[0003] MCU has the characteristics of high cost performance, complete development data and tool chain, and is widely used in civil and industrial automation control, energy storage, new energy vehicles and other fields, which involve the development of embedded systems or module applications based on MCU. In the process of embedded software application development and after-sales service, embedded software changes and upgrades are inevitable. Traditional debugging port programming upgrades and manual changes to the boot mode port configuration method require disassembly, which is cumbersome and has a long maintenance cycle. Precision components may even be difficult to restore. The method of connecting the debugging port to the maintenance interface for upgrading brings safety hazards to the system operation or the risk of system paralysis. Redevelopment with a fixed boot mode requires complex MCU storage space reallocation, boot program development, interrupt vector table redefinition, communication protocol and interaction strategy formulation, and host computer software redevelopment. After replacing the MCU, the MCU storage space reallocation, boot program development, and interrupt vector table redefinition still need to be redeveloped repeatedly, which requires a lot of human resources, and the safety and reliability of the entire programming upgrade system cannot be guaranteed in the early stage.

[0004] In order to ensure the convenience, speed, efficiency and simplicity of MCU software upgrade, it is necessary to study a software programming upgrade solution without disassembling the machine. Summary of the invention

[0005] The present invention aims at the technical problems existing in the prior art, and provides an MCU boot mode switching method, a switching circuit and a software upgrade method. When the MCU is operating normally, the mode switching control port (first IO port, second IO port) used to control the boot mode switching is configured as an input port to prevent the boot mode from switching by mistake; when software upgrade is required, the first IO port and the second IO port are converted into output ports and the state of the mode configuration port is controlled in an edge-triggered manner to switch the MCU boot mode. The solution of the present invention can switch and maintain the MCU boot mode through the boot mode switching circuit, and then realize the software upgrade without disassembling the machine, which improves the safety, convenience, speed, efficiency and simplicity of MCU software upgrade.

[0006] According to a first aspect of the present invention, a method for switching an MCU bootstrap mode is provided, characterized in that it comprises the following steps: Receive the target boot mode of the MCU, and determine whether the target boot mode type is the main Flash boot mode or the system memory boot mode; If the target operation mode is determined to be the main Flash boot mode, the mode switching control port of the MCU is configured as an input port; If it is determined that the target boot mode is the system memory boot mode, the mode switching control port of the MCU is configured as an output port, and the mode switching control port outputs an edge trigger signal; The bootstrap mode switching circuit of the MCU switches and maintains the bootstrap mode of the MCU as the system memory bootstrap mode according to the edge trigger signal.

[0007] According to a second aspect of the present invention, there is further provided an MCU bootstrap mode switching circuit, comprising a first controllable switch Q1 to a fourth controllable switch Q4 and a first resistor R1 to an eighth resistor R8, wherein the MCU is configured with a mode switching control port, a first mode configuration port Boot0, a second mode configuration port Boot1, a mode state detection pin and a serial port, wherein the mode switching control port comprises a first IO port and a second IO port; The second mode configuration port Boot1 is connected in series with a second resistor R2 and then grounded; The first IO port is connected to a first end of a switch channel of the first controllable switch Q1, the second IO port is connected in series with a third resistor R3 and then connected to a control end of the first controllable switch Q1, and a second end of a switch channel of the first controllable switch Q1 is connected in series with a fourth resistor R4 and a fifth resistor R5 in sequence and then grounded; The control end of the second controllable switch Q2 is connected in series with the sixth resistor R6 and the eighth resistor R8 in sequence and then connected to the working power supply; the common node of the sixth resistor R6 and the eighth resistor R8 is connected to the first end of the switch channel of the second controllable switch Q2; the other end of the switch channel of the second controllable switch Q2 is connected to the control end of the third controllable switch Q3 and the common node of the fourth resistor R4 and the fifth resistor R5; the first end of the switch channel of the third controllable switch Q3 is connected to the control end of the second controllable switch Q2 and the common node of the sixth resistor R6; the other end of the switch channel of the third controllable switch Q3 is grounded; The control end of the fourth controllable switch Q4 is connected to the common node of the sixth resistor R6 and the eighth resistor R8, the first end of the switch channel of the fourth controllable switch Q4 is connected to the working power supply, the other end of the switch channel of the fourth controllable switch Q4 is connected in series with the seventh resistor R7 and then grounded, the other end of the switch channel of the fourth controllable switch Q4 and the common node of the seventh resistor R7 are connected to the first mode configuration port Boot0, and the mode status detection pin is connected in series with the first resistor R1 and then connected to the first mode configuration port Boot0; When the first IO port and the second IO port do not output valid signals, the first controllable switch Q1 is turned off, and the first mode configuration port Boot0 is set to a low level; when the first IO port and the second IO port output valid edge-triggered signals, the first controllable switch Q1 to the fourth controllable switch Q4 are turned on, and the first mode configuration port Boot0 is switched and maintained at a high level; When the first mode configuration port Boot0 is set to a high level, the serial port is used as an online programming interface.

[0008] Based on the above technical solution, the present invention can also make the following improvements.

[0009] Optionally, the serial port is connected to a USB interface via a USB to UART tool, and the USB interface is used to connect an online programming peripheral.

[0010] According to a third aspect of the present invention, based on the above circuit, a method for upgrading MCU software is also provided, comprising: Receiving a programming instruction, and confirming a current boot mode of the MCU according to the programming instruction; If the current boot mode is the main Flash boot mode, then updating and configuring the first IO port and the second IO port from input ports to output ports; Control the first IO port and the second IO port to output a bootstrap mode switching signal, and switch and maintain the level of the first mode configuration port Boot0 in an edge-triggered manner; The level of the first mode configuration port Boot0 is detected. If the level of the first mode configuration port Boot0 is high, online programming is performed through the serial port to implement software upgrade of the MCU.

[0011] According to a fourth aspect of the present invention, based on the above-mentioned software upgrade method, there is also provided an MCU software upgrade system, comprising an MCU bootstrap mode switching module and a host computer that are communicatively connected to each other, wherein: MCU boot mode switching module, used to switch the MCU boot mode according to programming instructions; The host computer is used to issue programming instructions and perform online programming on the MCU when it is detected that the boot mode of the MCU is the system memory boot mode.

[0012] The present invention provides an MCU boot mode switching method, a switching circuit, and a software upgrade method. When the MCU is operating normally, the mode switching control port (first IO port, second IO port) used to control the boot mode switching is configured as an input port to prevent the boot mode from switching incorrectly; when software upgrade is required, the mode switching control port (first IO port, second IO port) is converted to an output port and the state of the mode configuration port is controlled in an edge-triggered manner to switch and maintain the MCU boot mode. Compared with the prior art, the solution of the present invention has the following beneficial effects: (1) MCU programming can be performed without disassembling the machine to manually switch the MCU mode, thus achieving software upgrades and updates. This ensures the efficiency, security, and system integrity of the software upgrade and update process, as well as the risk of additional failures caused by the disassembly process.

[0013] (2) Development is based on mature MCU software online programming system tools to avoid high investment and long verification time of development from scratch, reduce development costs and shorten development cycle, and avoid recurring problems and increased after-sales costs caused by initial immaturity.

[0014] (3) Applicable to the full range of MCUs (such as ST series) with boot mode switching based on port hardware configuration, built-in embedded bootloader and programming tool support, avoiding the need to redevelop self-developed online programming software after replacing the MCU.

[0015] (4) It does not rely on complex external hardware tools. The online programming environment can be built using simple and common hardware tools, which is low-cost.

[0016] (5) Use general software debugging tools to design short mode control codes for the MCU part, and combine them with mature online programming tools to perform online programming. There is no need to develop complex host computer programming software and embedded software, communication protocols and interaction strategies.

[0017] The solution of the present invention improves the safety, convenience, quickness, efficiency and simplicity of MCU software upgrade. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 This is a schematic diagram illustrating the MCU boot mode; Figure 2 This is a schematic diagram of the bootloader information of the MCU online programming port; FIG3 is a schematic diagram of the ST programming software interface, wherein FIG3 (a) is the new version of the ST programming software interface, and FIG3 (b) is the old version of the ST programming software interface; Figure 4 This is a schematic diagram of the software interface of the general serial port debugging tool; Figure 5 Update the hardware environment composition and link block diagram for the software programming provided by the present invention; Figure 6 A schematic diagram of the principle of a MCU bootstrap mode switching circuit provided by the present invention; Figure 7 The upper computer operation flow chart provided for the embodiment of the present invention; Figure 8 A flow chart of an embedded software bootstrap mode switching programming method provided by an embodiment of the present invention; Fig. 9 A schematic diagram of the application interaction process provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0019] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

[0020] The present invention mainly takes ST series MCU as the research object, and the subsequent embodiments are illustrated by using the model: STM32F407VGT6 MCU, and the serial port USART1-PA9, PA10 interface programming is used to specifically illustrate the implementation method.

[0021] like Figure 1 The following is a schematic diagram of the ST series MCU boot mode. Figure 2 The figure shows the bootloader information diagram of the ST series MCU online programming port. Figure 1 and Figure 2In the present invention, the MCU (STM32F407VGT6) needs to run various applications when it is powered on in the normal state, and it needs to be configured in the main Flash boot mode; when programming the MCU online, it needs to run in the system memory boot mode. In the main Flash boot mode, the first mode configuration port Boot0 needs to be configured to a low level, and at this time, the second mode configuration port Boot1 is configured regardless of the state. When programming the MCU online through the serial port USART1, the MCU needs to run in the system storage boot mode. In this mode, the mode configuration port Boot0 needs to be configured to a high level, and at this time, Boot1 needs to be configured to a low level. Combining the two modes, Boot1 can be fixedly configured to a low level, and Boot0 can be controlled to switch to a high level or a low level. This is one of the theoretical foundations of the present invention.

[0022] Figure 3 shows the startup interface of the ST online programming software, which is used to interact with the MCU through the serial communication port USART1 after the MCU enters the system memory boot mode. Figure 3 (a) is the new version interface of the ST online programming software, and Figure 3 (b) is the old version interface of the ST online programming software.

[0023] Figure 4 The figure shows the software interface of the universal serial port debugging tool, which is used to send the agreed specified programming instructions to the MCU when the MCU runs the application software. A dedicated simple tool can also be developed to send instructions and monitor the response and feedback status of the MCU. Figure 4 The following is an explanation of the universal serial port debugging tool software.

[0024] Figure 5 It is a hardware composition and link block diagram of the software programming update environment. The hardware environment includes a host computer and an embedded circuit board using the STM32F407VGT6 MCU, the embedded circuit board at least includes an MCU and an MCU boot mode switching module, and the host computer and the embedded circuit board are connected by a USB to UART tool in this embodiment. For example, the embedded circuit board also includes a USB interface, the serial port is connected to the USB interface through a USB to UART tool, and the USB interface is used to connect an online programming peripheral (host computer). UART can be used directly to connect to the MCU, but is not limited to TTL or RS232 physical signals.

[0025] based on Figure 5 As shown in the block diagram, this embodiment provides an MCU software upgrade system, including an MCU boot mode switching module and a host computer that are communicatively connected to each other, wherein: The host computer is used to issue programming instructions. MCU boot mode switching module, used to switch the MCU boot mode according to programming instructions; The host computer is also used to perform online programming on the MCU when it is detected that the boot mode of the MCU is the system memory boot mode.

[0026] Based on the above theoretical basis, this embodiment provides an MCU boot mode switching method, including the following steps: Receiving a target boot mode of the MCU, and determining whether the target boot mode type is a main Flash boot mode or a system memory boot mode; it can be understood that the target boot mode is a desired boot mode, which may be a main Flash boot mode or a system memory boot mode; If the target operation mode is determined to be the main Flash boot mode, in which case the MCU is expected to run the application program normally, the mode switching control port of the MCU is configured as an input port; If it is determined that the target boot mode is the system memory boot mode, in this state, the MCU is expected to perform online programming, then the mode switching control port of the MCU is configured as an output port, and the mode switching control port outputs an edge trigger signal; The bootstrap mode switching circuit of the MCU switches and maintains the bootstrap mode of the MCU as the system memory bootstrap mode according to the edge trigger signal, and the MCU can be programmed online in this state.

[0027] Figure 6 The schematic diagram of the MCU bootstrap mode switching circuit provided by the embodiment of the present invention is shown in FIG. The circuit is a rising edge triggered self-holding circuit, which is the key to online switching and holding of the MCU bootstrap mode.

[0028] exist Figure 6 In the circuit shown, the MCU boot mode switching circuit includes the first controllable switch Q1 to the fourth controllable switch Q4 and the first resistor R1 to the eighth resistor R8. The MCU is configured with a mode switching control port, a first mode configuration port Boot0, a second mode configuration port Boot1, a mode state detection pin PA11 and a serial port USART1 (IO port PA9 and IO port PA10), wherein the mode switching control port includes the first IO port PB8 and the second IO port PB9. The first IO port PB8 and the second IO port PB9 are GPIO (general input / output) ports, which can be configured as a general input mode or a general output mode. After power-on / reset in the normal state, the first IO port PB8 and the second IO port PB9 default to the input mode, and will not output an error signal or cause a malfunction to cause the system to enter other undesired boot modes. In this embodiment, the first controllable switch Q1, the second controllable switch Q2 and the fourth controllable switch Q4 use PNP transistors, and the third controllable switch Q3 uses NPN transistors.

[0029] The second mode configuration port Boot1 is connected in series with the second resistor R2 and then grounded. The second mode configuration port Boot1 is always set to a low level through the pull-down effect of the second resistor R2. On this basis, the MCU boot mode switching circuit only needs to switch the level of the first mode configuration port Boot0 to modify the boot mode required by the MCU.

[0030] In this embodiment, the first controllable switch Q1 is illustrated with a PNP transistor. The first IO port PB8 is connected to the first end (emitter E, pin 2) of the switch channel of the first controllable switch Q1, the second IO port PB9 is connected in series with the third resistor R3 and then connected to the control end (base B, pin 1) of the first controllable switch Q1, and the second end (collector C, pin 3) of the switch channel of the first controllable switch Q1 is connected in series with the fourth resistor R4 and the fifth resistor R5 in sequence and then grounded. When the first IO port PB8 outputs a high level to the emitter E (pin 2) of the first controllable switch Q1 and the second IO port PB9 outputs a low level to the base B (pin 1) of the first controllable switch Q1, as shown in FIG. Figure 6 As shown, the BE junction between the emitter E (pin 2) and the base B (pin 1) of the first controllable switch Q1 is turned on, so that the emitter E (pin 2) and the collector C (pin 3) of the first controllable switch Q1 are turned on, thereby generating a high level at the collector C (pin 3) of the first controllable switch Q1, and the fourth resistor R4 and the fifth resistor R5 form a group of voltage-dividing resistors, and the level at the common node of the fourth resistor R4 and the fifth resistor R5 provides a control signal source for the third controllable switch Q3.

[0031] The third controllable switch Q3 is an NPN transistor, and the second controllable switch Q2 is a PNP transistor. The control end (base B, pin 1) of the second controllable switch Q2 is connected in series with the sixth resistor R6 and the eighth resistor R8 in sequence and then connected to the working power supply, the common node of the sixth resistor R6 and the eighth resistor R8 is connected to the first end (emitter E, pin 2) of the switch channel of the second controllable switch Q2, and the other end (collector C, pin 3) of the switch channel of the second controllable switch Q2 is connected to the control end (base B, pin 1) of the third controllable switch Q3 and the common node of the fourth resistor R4 and the fifth resistor R5; the first end (collector C, pin 3) of the switch channel of the third controllable switch Q3 is connected to the common node of the control end (base B, pin 1) of the second controllable switch Q2 and the sixth resistor R6, and the other end (emitter E, pin 2) of the switch channel of the third controllable switch Q3 is grounded.

[0032] Since the high level of the C pole of the first controllable switch Q1 is applied to the control end (base B, pin 1) of the third controllable switch Q3 through the fourth resistor R4, it serves as the conduction control signal source of the third controllable switch Q3; at the same time, since the collector C (pin 3) of the third controllable switch Q3 is connected to the positive electrode of the working power supply through the sixth resistor R6 and the eighth resistor R8 connected in series, the third controllable switch Q3 meets the conduction condition. When the third controllable switch Q3 is turned on, the voltage of the B pole (pin 1) of the second controllable switch Q2 is pulled down, and since the emitter E (pin 2) of the second controllable switch Q2 is connected to the positive electrode of the working power supply through the eighth resistor R8, the second controllable switch Q2 meets the conduction condition. In this state, since the second controllable switch Q2 provides a conduction control signal source for the B pole (pin 1) of the third controllable switch Q3 when it is turned on, the second controllable switch Q2 and the third controllable switch Q3 form an interlocking self-holding circuit. This is equivalent to the first controllable switch Q1 being turned on causing the third controllable switch Q3 to be turned on, which in turn causes the second controllable switch Q2 to be turned on, and after the second controllable switch Q2 is turned on, it is interlocked with the third controllable switch Q3, so that the second controllable switch Q2 and the third controllable switch Q3 remain in the turned-on state.

[0033] exist Figure 6 In the illustrated embodiment, the fourth controllable switch Q4 is a PNP transistor. The control end (base B, pin 1) of the fourth controllable switch Q4 is connected to the common node of the sixth resistor R6 and the eighth resistor R8, and is also connected to the emitter E (pin 2) of the second controllable switch Q2; the first end (emitter E, pin 2) of the switch channel of the fourth controllable switch Q4 is connected to the working power supply, and the other end (collector C, pin 3) of the switch channel of the fourth controllable switch Q4 is connected in series with the seventh resistor R7 and then grounded. When the second controllable switch Q2 is turned on, the control end (base B, pin 1) level of the fourth controllable switch Q4 is pulled down, so that the fourth controllable switch Q4 meets the turn-on condition. Therefore, under the action of the interlocking self-holding circuit formed by the second controllable switch Q2 and the third controllable switch Q3, the fourth controllable switch Q4 remains in the on state. When the fourth controllable switch Q4 is turned on, the level of the common node between the collector C (pin 3) of the fourth controllable switch Q4 and the seventh resistor R7 is pulled high. Since the other end of the switch channel of the fourth controllable switch Q4 (collector C, pin 3) and the common node of the seventh resistor R7 are connected to the first mode configuration port Boot0, when the fourth controllable switch Q4 is turned on, the level of the first mode configuration port Boot0 is pulled high. The mode state detection pin PA11 is connected in series with the first resistor R1 and then connected to the first mode configuration port Boot0 to detect the level state of the first mode configuration port Boot0.

[0034] When the first IO port PB8 and the second IO port PB9 do not output a valid signal (for example, they are configured as a general input mode), the first controllable switch Q1 is turned off, and the first mode configuration port Boot0 is set to a low level; when the first IO port PB8 and the second IO port PB9 output a valid edge-triggered signal, based on the above expression, the first controllable switch Q1 to the fourth controllable switch Q4 are turned on, and the first mode configuration port Boot0 is switched and maintained at a high level.

[0035] When the first mode configuration port Boot0 is set to a high level, combined with the fixed low level state of the second mode configuration port Boot1, it corresponds to Figure 1 In the boot mode table of the ST series MCU shown, the corresponding boot mode is the system memory boot mode. In this mode, the system memory can be selected as the boot space and remain in the system memory boot mode until power is re-enabled. The MCU detects the state of the first mode configuration port Boot0 through the mode state detection pin PA11, and confirms that the boot mode port of the MCU is configured as the system memory boot mode state. After confirmation, the software reset operation is started, so that the MCU enters the system memory boot mode to run the embedded boot code and prepare to perform the online programming operation. The serial port USART1 is used as an online programming interface.

[0036] Figure 6 In the bootstrap mode switching circuit shown, the first IO port PB8 and the second IO port PB9 are used as mode switching control ports for control, and the mode state detection pin PA11 is used for state confirmation. In practice, it is not limited to the three ports for control and detection. This embodiment adopts a rising edge triggering mode as the triggering condition of the edge-triggered self-holding circuit, and in practice it is not limited to the rising edge triggering mode. This embodiment uses transistors to form a switching self-holding circuit, and in practice it is not limited to the use of transistors.

[0037] based on Figure 5 The block diagram shown and Figure 6 The bootstrap mode switching circuit shown in the figure, this embodiment provides an MCU software upgrade method, comprising the following steps: Receiving a programming instruction, and confirming a current boot mode of the MCU according to the programming instruction; If the current boot mode is the main Flash boot mode, then updating and configuring the first IO port and the second IO port from input ports to output ports; Control the first IO port and the second IO port to output a bootstrap mode switching signal, and switch and maintain the level of the first mode configuration port Boot0 in an edge-triggered manner; The level of the first mode configuration port Boot0 is detected. If the level of the first mode configuration port Boot0 is high, online programming is performed through the serial port to implement software upgrade of the MCU.

[0038] based on Figure 5 As shown in the block diagram, Figure 7 The upper computer operation flow chart provided for a certain embodiment of the present invention. The upper computer may be equipped with Figure 4 The host computer of the universal serial port debugging tool software shown can also be a dedicated host computer developed according to the present invention. The dedicated host computer can integrate multiple communication modes such as USB, UART, SPI, CAN or I2C. When the MCU software needs to be upgraded or updated, the host computer sends programming instructions to the MCU, and then waits for the MCU to respond and send reset status information. After receiving the MCU startup reset information, the ST programming software Flash Loader Demonstrator or STM32CubeProgrammer (as shown in Figure 3) is started to start programming.

[0039] For example: (1) Start the process; (2) The host computer sends programming instructions to the MCU; (3) Confirm whether the response command from the MCU is received: If it is not received and it has not timed out, continue to confirm whether a response command is received from the MCU; If it is not received and the timeout period has expired, the process ends; If a response command is received, the timeout will be reset; (4) Confirm whether feedback is received that the bootstrap mode switch is complete: If it is not received and it has not timed out, continue to confirm whether the feedback bootstrap mode switching is completed; If it is not received and the timeout period has expired, the process ends; If feedback is received that the bootstrap mode switching is completed, the reset timeout is performed; (5) Start editing with ST programming software until it is completed; (6) End the process.

[0040] based on Figure 5 As shown in the block diagram, Figure 8 1 is a flowchart of the embedded software bootstrap mode switching programming provided by an embodiment of the present invention. Figure 8 As shown, it includes the following processes: (1) After the MCU receives the programming instruction from the host computer and verifies that it is valid, it runs the boot mode switching function software module; (2) Sending a response message for receiving a programming instruction; (3) Sending status information during bootstrap mode switching; (4) Turn off or disable the initialization state of irrelevant peripherals, and initialize the boot mode switch control IO ports PB8 (BootEnH) and PB9 (BootEnL) used to be in output mode, and the mode status detection pin / feedback port PA11 (Boot0StFb) to be in input mode; (5) Switch to bootstrap mode and control Figure 6 The output of the first IO port PB8 (BootEnH) is high, and the output of the second IO port PB9 (BootEnL) is low; (6) Read the port status of the mode configuration port Boot0 through the mode status detection pin / feedback port PA11 (Boot0StFb). If it is high level, the switch is successful and go to the next step. If it is still low level, exit.

[0041] (7) If the switch is successful, send the bootstrap mode switch success message; (8) Sending information to prepare to execute software reset instruction operation; (9) Waiting for programming operation from the host computer; After the programming operation is completed, according to the prompt information of the ST host computer programming software, power on the embedded circuit board again.

[0042] The present invention is further described in detail below in conjunction with a specific implementation scenario, but the implementation methods of the present invention are not limited to this. For example, connection confirmation, strict dynamic verification and other contents can be added according to actual applications to increase security and reliability. Here, only the core part of the implementation method of the present invention is explained with examples.

[0043] Fig. 9 The figure shows an application interaction flow chart of a typical embodiment of the present invention. This embodiment takes ST's MCU (model STM32F407VGT6) as an example to use USART0 port programming, and the complete programming operation process is as follows: (1) First press Figure 5 As shown in the block diagram, connect the host computer and the embedded circuit board (including the MCU boot mode switching module) through the USB to serial port debugging tool, and power on the circuit board; Note: When using the circuit board for the first time, you need to use the ST IDE (Integrated Development Environment) software that supports STM32F407VGT6 development on the host computer, and write and run the firmware code or application code with boot mode switching through ST-Link or J-Link.

[0044] (2) Start the universal serial port debugging tool software - Window Debug Assistant in the host computer, set the serial port to COM4, ​​the baud rate to 57600 (bps), the check bit to EVEN (even check), the data bit to 8, and the stop bit to 1. Click the "Open Serial Port" button to open the serial port, set the receiving display to hexadecimal display, the sending to hexadecimal sending, and the automatic sending cycle to 1000ms. Enter "EB 91 01 13 F3 07" in the sending window, where "EB 91" is the programming instruction data packet prefix start identifier, "01" is the data length, "13" is the instruction code, and "F3 07" is the check code. Click the "Auto Send" button to send the programming instruction to the embedded circuit board.

[0045] (3) After receiving the data packet, the MCU embedded software determines the validity of the data packet. If it is invalid, it sends a response message indicating that the programming instruction is invalid, and then continues to run the application. If it is valid, it sends a response message indicating that the programming instruction is valid, and then sends the status information of the boot mode switching. At the same time, it performs the boot mode status switching operation and reads back for confirmation, including the disabling initialization of irrelevant peripherals (if used). After confirming that the boot mode switching is completed and successful, it sends the boot mode switching completion status information to the host computer. Then it sends the start soft reset operation status.

[0046] (4) After the host computer receives the reset operation information of the embedded software, it confirms that the programming operation can be started. Start the ST programming software, import the programming code to be written into the MCU, and start the programming until it is completed.

[0047] (5) After the programming is completed, since the embedded circuit board is still in the system memory boot mode, power it on again to restore it to the main Flash boot mode, and run the application to complete the online programming.

[0048] An MCU boot mode switching method, a switching circuit and a software upgrade method provided by an embodiment of the present invention relate to an MCU embedded minimum system with an on-chip boot program based on ST, an edge-triggered self-holding circuit (boot mode switching circuit), ST series MCU online programming software Flash Loader Demonstrator or STM32CubeProgrammer, general host computer debugging software or host computer simple support tool software and hardware communication tools, and embedded boot mode switching control software. When the MCU software upgrade and change programming is required, the agreed special instructions are sent by using the serial port or CAN host computer debugging software or the self-developed host computer simple support tool software. After the MCU receives the instruction and confirms that it is valid, the mode switching control port is controlled to output a corresponding level signal, and the boot mode switching circuit action is controlled in an edge-triggered manner, and the MCU is reset to switch the boot mode to enter the system memory boot mode, and then programming is performed through the ST series MCU online programming software. After the programming is completed, the online upgrade of the MCU software is completed by re-powering on. The MCU boot mode can be controlled and maintained by its own IO port in an edge-triggered manner. When a software upgrade is required, the mode switching software module generates a corresponding trigger edge to trigger the boot mode switching circuit by controlling the output state of the mode switching control port (such as IO port PB8 / PB9), so that the MCU remains in the system memory boot configuration mode until it is powered on again and enters the waiting state again.

[0049] The present invention is applicable to a full range of MCUs with bootstrap mode switching based on port hardware configuration, built-in embedded bootstrap program and ST programming tool support, avoiding the need to redevelop the online programming software after replacing the MCU. The MCU bootstrap mode switching only needs to develop simple bootstrap mode switching software, which is controlled by a simple embedded program and combined with general host computer debugging software or host computer simple support tool software to send control instructions to achieve bootstrap mode switching. It does not rely on complex external hardware tools, and can build an online programming environment using simple and general hardware tools, with low cost.

[0050] Secondary development is carried out based on ST's existing mature software online upgrade programming system, involving ST series MCU online programming software Flash Loader Demonstrator or STM32CubeProgrammer, ST series MCU on-chip inherent system memory boot software and communication interfaces that support system memory boot programming - USB, UART, SPI, CAN or I2C, ST series MCU boot mode selection port, etc., to avoid high investment and long verification from scratch, reduce development costs and shorten development cycles, and avoid recurring problems and increased after-sales costs caused by immaturity in the early stages of product development.

[0051] The present invention can perform MCU programming without disassembling the machine to manually switch the MCU mode, thereby realizing software upgrade and update, thereby ensuring the efficiency, security and system integrity of the software upgrade and update process, and eliminating the risk of additional failures caused by the disassembly process.

[0052] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0053] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0054] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0055] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0056] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1The steps for the functions specified in one or more boxes.

[0057] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0058] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for switching MCU boot mode, characterized in that: The following steps are involved: Receive the target boot mode of the MCU, and determine whether the target boot mode type is the main Flash boot mode or the system memory boot mode; If the target operation mode is determined to be the main Flash boot mode, the mode switching control port of the MCU is configured as an input port; If it is determined that the target boot mode is the system memory boot mode, the mode switching control port of the MCU is configured as an output port, and the mode switching control port outputs an edge trigger signal; The bootstrap mode switching circuit of the MCU switches and maintains the bootstrap mode of the MCU as the system memory bootstrap mode according to the edge trigger signal.

2. An MCU bootstrap mode switching circuit, characterized in that: The MCU comprises a first controllable switch Q1 to a fourth controllable switch Q4 and a first resistor R1 to an eighth resistor R8, and the MCU is configured with a mode switching control port, a first mode configuration port Boot0, a second mode configuration port Boot1, a mode state detection pin and a serial port, wherein the mode switching control port comprises a first IO port and a second IO port; The second mode configuration port Boot1 is connected in series with a second resistor R2 and then grounded; The first IO port is connected to a first end of a switch channel of the first controllable switch Q1, the second IO port is connected in series with a third resistor R3 and then connected to a control end of the first controllable switch Q1, and a second end of a switch channel of the first controllable switch Q1 is connected in series with a fourth resistor R4 and a fifth resistor R5 in sequence and then grounded; The control end of the second controllable switch Q2 is connected in series with the sixth resistor R6 and the eighth resistor R8 in sequence and then connected to the working power supply; the common node of the sixth resistor R6 and the eighth resistor R8 is connected to the first end of the switch channel of the second controllable switch Q2; the other end of the switch channel of the second controllable switch Q2 is connected to the control end of the third controllable switch Q3 and the common node of the fourth resistor R4 and the fifth resistor R5; the first end of the switch channel of the third controllable switch Q3 is connected to the control end of the second controllable switch Q2 and the common node of the sixth resistor R6; the other end of the switch channel of the third controllable switch Q3 is grounded; The control end of the fourth controllable switch Q4 is connected to the common node of the sixth resistor R6 and the eighth resistor R8, the first end of the switch channel of the fourth controllable switch Q4 is connected to the working power supply, the other end of the switch channel of the fourth controllable switch Q4 is connected in series with the seventh resistor R7 and then grounded, the other end of the switch channel of the fourth controllable switch Q4 and the common node of the seventh resistor R7 are connected to the first mode configuration port Boot0, and the mode status detection pin is connected in series with the first resistor R1 and then connected to the first mode configuration port Boot0; When the first IO port and the second IO port do not output valid signals, the first controllable switch Q1 is turned off, and the first mode configuration port Boot0 is set to a low level; when the first IO port and the second IO port output valid edge-triggered signals, the first controllable switch Q1 to the fourth controllable switch Q4 are turned on, and the first mode configuration port Boot0 is switched and maintained at a high level; When the first mode configuration port Boot0 is set to a high level, the serial port is used as an online programming interface.

3. The circuit according to claim 2, characterized in that It also includes a USB interface, the serial port is connected to the USB interface through a USB to UART tool, and the USB interface is used to connect an online programming peripheral.

4. A method for upgrading MCU software, characterized in that: The circuit according to claim 2 or 3 comprises the following steps: Receiving a programming instruction, and confirming a current boot mode of the MCU according to the programming instruction; If the current boot mode is the main Flash boot mode, then updating and configuring the first IO port and the second IO port from input ports to output ports; Control the first IO port and the second IO port to output a bootstrap mode switching signal, and switch and maintain the level of the first mode configuration port Boot0 in an edge-triggered manner; The level of the first mode configuration port Boot0 is detected. If the level of the first mode configuration port Boot0 is high, online programming is performed through the serial port to implement software upgrade of the MCU.

5. An MCU software upgrade system, characterized in that: The software upgrade method according to claim 4 comprises an MCU bootstrap mode switching module and a host computer that are communicatively connected to each other, wherein: MCU boot mode switching module, used to switch the MCU boot mode according to programming instructions; The host computer is used to issue programming instructions and perform online programming on the MCU when it is detected that the boot mode of the MCU is the system memory boot mode.