Starting mode switching circuit of MCU (Microprogrammed Control Unit), MCU debugging system and switching method

By designing the startup mode switching circuit of the MCU and using the switch module and reset module to control the mode switching pin and hardware reset pin of the MCU, the problems of DIP switch failure and high cost are solved, and accurate and convenient switching of the MCU startup mode is achieved. operate.

CN118550593APending Publication Date: 2024-08-27SHENZHEN LICHI SEMICONDUCTOR TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410645810.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-23
Publication Date
2024-08-27

AI Technical Summary

Technical Problem

The startup mode switching of existing MCUs usually relies on DIP switches, which are prone to failure, high cost, and inconvenient to operate. Especially in high and low temperature experiments or hot and cold shock experiments, non-automotive grade materials may cause poor contact of the switch shrapnel, increasing the number of experiments. complexity and cost.

Method used

A startup mode switching circuit for MCU is designed, including a switch module, a reset module and a switching module. By controlling the mode switching pin and hardware reset pin of the MCU, the Jlink instruction is used to output a low level signal in JTAG mode to switch the MCU. The startup mode avoids the use of DIP switches.

Benefits of technology

It achieves accurate switching of the MCU startup mode, reduces the cost and difficulty of operation, improves the reliability and convenience of mode switching, and avoids the failure problem of the DIP switch.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118550593A
    Figure CN118550593A
Patent Text Reader

Abstract

The invention discloses a starting mode switching circuit of an MCU, an MCU debugging system and a switching method, and belongs to the technical field of chips. A switch module in the starting mode switching circuit is connected with a reset module and a switching module; the switching module is connected with three mode switching pins of the MCU, and the other mode switching pin is grounded; the reset module is connected with a hardware reset pin of the MCU, and the hardware reset pin is also connected with a system reset pin in the JTAG seat; when the switch module is closed, the switching module outputs a high level to the three mode switching pins, and the system reset pin outputs a low level to the hardware reset pin under the control of a Jlink instruction, so that the MCU is reset and restarted and is switched to a JTAG mode; and when the switch module is switched off, the reset module outputs a low level to the hardware reset pin, so that the MCU is reset, restarted and switched to a Flash mode. The switching accuracy can be improved, and the cost and the operation difficulty can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of chip technology, and in particular to a startup mode switching circuit of an MCU, an MCU debugging system and a switching method. Background Art

[0002] MCU (Microcontroller Unit) needs to switch different startup modes when debugging, downloading programs and running normally. For example, starting from NOR flash (non-volatile flash technology) requires switching to Flash mode. Flash mode means that after startup, the MCU automatically reads the program stored in Flash and runs the program. For another example, Jlink debugging requires switching to JTAG (Joint Test Action Group) mode. JTAG mode means that after startup, the program stored in Flash is not run, but the program code is downloaded to iRAM (Internal Random Access Memory) through the Jlink debugger for running and debugging. The Jlink debugger is a high-performance debugger developed by Segger. It is widely used in the development and debugging of embedded systems, supports a variety of microprocessor architectures and development tool chains, and realizes debugging, simulation, burning and other functions of the target system.

[0003] The MCU itself has a mode switching pin, which can control the switching of the boot mode through 4 GPIO (General Purpose Input / Output Port) pins (i.e. GPIO_A3~GPIO_A0). Among them, the GPIO_A3~GPIO_A0 value of 0000 corresponds to the Flash mode, and the GPIO_A3~GPIO_A0 value of 1110 corresponds to the JTAG mode. Set the values ​​of the 4 GPIO pins and input them to the MCU. After the MCU is restarted, it can switch to the corresponding working mode.

[0004] In the related technology, a 4-channel DIP switch can be set on the MCU development board, and the 4-channel button can be manually turned to the ON / OFF position to select the desired mode. However, there are no suitable automotive-grade DIP switches on the market. During high and low temperature experiments or hot and cold shock experiments, non-automotive-grade materials may cause poor contact or failure of the switch springs after the experiment; adding a DIP switch will increase costs; even if a DIP switch is set on the MCU development board, it needs to be installed with a plastic shell, so it is not convenient to perform the DIP operation after the finished product is installed on the actual vehicle. Summary of the invention

[0005] The present application provides an MCU startup mode switching circuit, an MCU debugging system and a switching method, which are used to solve the problem that when setting the startup mode of the MCU through a dip switch, the dip switch is prone to failure, the cost is high and the operation is inconvenient. The technical solution is as follows:

[0006] According to a first aspect of the present application, a startup mode switching circuit of an MCU is provided, the startup mode switching circuit comprising: a switch module, a reset module and a switching module;

[0007] The switch module is connected to the reset module and the switching module respectively;

[0008] The switching module is connected to three mode switching pins of the MCU, and another mode switching pin of the MCU is grounded;

[0009] The reset module is connected to the hardware reset pin of the MCU, and the hardware reset pin is also connected to the system reset pin in the JTAG socket;

[0010] When the switch module is closed, the switch module is used to output three high-level signals to the three mode switch pins, and the system reset pin is used to output a low-level signal to the hardware reset pin under the control of a preset Jlink instruction, so that the MCU is reset and restarted and the boot mode is switched to the JTAG mode;

[0011] When the switch module is disconnected, the reset module is used to output a low level signal to the hardware reset pin, so that the MCU is reset and restarted and the startup mode is switched to the Flash mode.

[0012] In a possible implementation, the switching module includes first to third resistors, a first switch tube and a first capacitor;

[0013] The source of the first switch tube is connected to a power supply, the gate of the first switch tube is connected to one end of a first resistor, the other end of the first resistor is connected to one end of the second resistor, the other end of the second resistor is connected to a power supply, the drain of the first switch tube is respectively connected to one end of a third resistor, one end of the first capacitor and the three mode switching pins, the other end of the third resistor is connected to the other end of the first capacitor and then grounded.

[0014] In a possible implementation, the reset module includes a second resistor, fourth to eighth resistors, a second switch tube, a triode, a diode, a second capacitor and a third capacitor;

[0015] The source of the second switch tube is connected to a power supply, the gate of the second switch tube is connected to one end of a fourth resistor, the other end of the fourth resistor is respectively connected to one end of the second resistor, the cathode of the diode and the switch module, the other end of the second resistor is connected to a power supply, the drain of the second switch tube is connected to one end of a fifth resistor, the other end of the fifth resistor is respectively connected to one end of a second capacitor, a sixth resistor and a seventh resistor, the sixth resistor is connected to the other end of the second capacitor and then grounded;

[0016] The other end of the seventh resistor is respectively connected to the anode of the diode, one end of the third capacitor and the base of the transistor, the collector of the transistor is respectively connected to one end of the eighth resistor and the hardware reset pin, the emitter of the transistor is connected to the other end of the third capacitor and then grounded, and the other end of the eighth resistor is connected to the power supply.

[0017] In a possible implementation, the switch module includes a switch;

[0018] One end of the switch is respectively connected to one end of the second resistor, one end of the first resistor, the other end of the fourth resistor and the cathode of the diode, and the other end of the switch is grounded.

[0019] According to a second aspect of the present application, there is provided an MCU debugging system, the MCU debugging system comprising an MCU, a JTAG socket and the startup mode switching circuit as described above;

[0020] Three mode switching pins of the MCU are connected to the switching module, and another mode switching pin is grounded;

[0021] The hardware reset pin of the MCU is connected to the reset module and the system reset pin in the JTAG socket respectively;

[0022] The switch module is connected to a ground pin in the JTAG socket.

[0023] In a possible implementation, the MCU debugging system further includes a Jlink debugger;

[0024] When the Jlink debugger is inserted into the JTAG socket, the switch module is closed;

[0025] When the Jlink debugger is pulled out from the JTAG socket, the switch module is disconnected.

[0026] In a possible implementation, a system reset pin in the Jlink debugger is connected to a system reset pin in the JTAG socket;

[0027] When the Jlink debugger receives a preset Jlink instruction, the system reset pin in the Jlink debugger is used to output a low level signal to the system reset pin in the JTAG socket under the control of the Jlink instruction;

[0028] The system reset pin in the JTAG socket is used to output a low level signal to the hardware reset pin to reset and restart the MCU.

[0029] According to a third aspect of the present application, a method for switching a startup mode of an MCU is provided, which is used in the MCU debugging system as described above, and the method includes:

[0030] Determine the startup mode required by the MCU;

[0031] When the startup mode is the JTAG mode, the switch module is controlled to be closed, three high-level signals are output to the three mode switching pins through the switching module, and the system reset pin is controlled to output a low-level signal to the hardware reset pin through a preset Jink instruction, so that the MCU is reset and restarted and the startup mode is switched to the JTAG mode;

[0032] When the startup mode is the Flash mode, the switch module is controlled to be disconnected, and a low level signal is output to the reset pin through the reset module, so that the MCU is reset and restarted and the startup mode is switched to the Flash mode.

[0033] In a possible implementation, the MCU debugging system further includes a Jlink debugger;

[0034] The controlling the switch module to close includes: controlling the Jlink debugger to connect to the JTAG socket;

[0035] The controlling the switch module to disconnect includes: controlling the Jlink debugger to separate from the JTAG socket.

[0036] In a possible implementation, the system reset pin in the Jlink debugger is connected to the system reset pin in the JTAG socket, and the method further includes:

[0037] When the Jlink debugger receives a preset Jlink instruction, the system reset pin in the Jlink debugger outputs a low level signal to the system reset pin in the JTAG socket under the control of the Jlink instruction;

[0038] The system reset pin in the JTAG socket outputs a low level signal to the hardware reset pin, so that the MCU is reset and restarted.

[0039] The beneficial effects of the technical solution provided by this application include at least:

[0040] When the switch module is closed, three high-level signals are output to the three mode switching pins of the MCU through the switching module, and another mode switching pin of the MCU is grounded, so that the values ​​of the four mode switching pins of the MCU are 1110, and then a low-level signal is output to the hardware reset pin through the system reset pin to reset and restart the MCU and switch the startup mode to the JTAG mode; when the switch module is disconnected, the reset module outputs a low-level signal to the hardware reset pin to reset and restart the MCU and switch the startup mode to the Flash mode. In this way, the startup mode of the MCU can be switched by controlling the switch module, avoiding the use of a dip switch to switch the startup mode of the MCU, which can not only improve the switching accuracy but also reduce the cost and operation difficulty. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0042] Figure 1 It is a schematic diagram of a startup mode switching circuit of an MCU provided by an embodiment of the present application;

[0043] Figure 2 is a schematic diagram of simulation results and signal waveforms provided by an embodiment of the present application;

[0044] Figure 3 is a schematic diagram of an MCU debugging system provided by an embodiment of the present application;

[0045] Figure 4 It is an operation diagram of the Jlink commander interface provided by an embodiment of the present application;

[0046] Figure 5 It is an operation diagram of the Jlink commander interface provided by an embodiment of the present application;

[0047] Figure 6 This is a flowchart of a method for switching the startup mode of an MCU provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0049] MCU has 4 mode switching pins, which can be used to switch the boot mode of MCU. Taking the mode switching pin as GPIO pin as an example, the 4 mode switching pins can be recorded as GPIO_A3~GPIO_A0. Among them, the value of GPIO_A3~GPIO_A0 is 0000, which corresponds to Flash mode, and the value of GPIO_A3~GPIO_A0 is 1110, which corresponds to JTAG mode. After setting the values ​​of the 4 GPIO pins and inputting them into the MCU, you need to restart the MCU to switch the MCU to the corresponding working mode.

[0050] like Figure 1 As shown, it shows a startup mode switching circuit of an MCU provided by an embodiment of the present application, and the startup mode switching circuit includes a switch module 110, a reset module 120 and a switch module 130, and the switch module 110 is respectively connected to the reset module 120 and the switch module 130. Among them, the switch module 110 is used to trigger the switch module 130 to control the values ​​of the three mode switching pins in the MCU, and the reset module 120 is used to reset and restart the MCU.

[0051] The switching module 130 is connected to three mode switching pins of the MCU, and another mode switching pin of the MCU is grounded. Figure 1 As shown, when the four mode switching pins are GPIO_A3 to GPIO_A0, the output end of the switching module 130 is connected to GPIO_A3 to GPIO_A1 respectively, and GPIO_A0 is grounded.

[0052] The reset module 120 is connected to the hardware reset pin of the MCU, and the hardware reset pin is also connected to the system reset pin in the JTAG socket. In this embodiment, the hardware reset pin is recorded as SYS_POR_B, and the output end of the reset module 120 is connected to SYS_POR_B, so that the reset module 120 can control the MCU to reset and restart.

[0053] The hardware reset pin of the MCU can also be connected to the system reset pin in the JTAG socket. Taking the JTAG socket as an example, the system reset pin can be the 15th pin, recorded as SRST_N, and SYS_POR_B is also connected to SRST_N, so that the MCU reset and restart can be controlled through SRST_N.

[0054] The working principle of the startup mode switching circuit is briefly described below:

[0055] (1) Switch the MCU boot mode to JTAG mode;

[0056] When the switch module 110 is closed, the switching module 130 is used to output three high-level signals to the three mode switching pins, and the system reset pin is used to output a low-level signal to the hardware reset pin under the control of a preset Jlink instruction to reset and restart the MCU and switch the startup mode to JTAG mode.

[0057] When the switch module 110 is closed, three mode switching pins (GPIO_A3 to GPIO_A1) receive high-level signals output by the switch module 130, and one mode switching pin (GPIO_A0) is grounded as a low-level signal. Therefore, the values ​​of the four mode switching pins (GPIO_A3 to GPIO_A0) are 1110, which corresponds to the JTAG mode.

[0058] The external input Jlink instruction can control the system reset pin (SRST_N) in the JTAG socket to output a low level signal to the hardware reset pin (SYS_POR_B) to control the MCU reset and restart. The Jlink instruction can be a pre-set instruction, which will not be described here.

[0059] When the values ​​of the four mode switching pins (GPIO_A3 to GPIO_A0) are 1110 and the MCU is reset and restarted, the boot mode of the MCU is switched to JTAG mode.

[0060] (2) Switch the MCU boot module to Flash mode;

[0061] When the switch module 110 is disconnected, the reset module 120 is used to output a low level signal to the hardware reset pin, so as to reset and restart the MCU and switch the boot mode to the Flash mode.

[0062] At the moment when the switch module 110 is disconnected, the four mode switching pins (GPIO_A3 ˜ GPIO_A0 ) all receive low-level signals, so the values ​​of the four mode switching pins (GPIO_A3 ˜ GPIO_A0 ) are 0000, which corresponds to the Flash mode.

[0063] The reset module 120 outputs a low level signal to the hardware reset pin (SYS_POR_B) to control the MCU to reset and restart.

[0064] When the values ​​of the four mode switching pins (GPIO_A3 to GPIO_A0) are 0000 and the MCU is reset and restarted, the boot mode of the MCU is switched to Flash mode.

[0065] The structure of the switching module 130 is described below:

[0066] like Figure 1As shown, the switching module 130 includes a first resistor (R1), a second resistor (R3), a third resistor (R7), a first switch tube (Q5) and a first capacitor (C2); wherein the source of the first switch tube (Q5) is connected to a power supply (VCC), the gate of the first switch tube (Q5) is connected to one end of the first resistor (R1), the other end of the first resistor (R1) is connected to one end of the second resistor (R3), the other end of the second resistor (R3) is connected to the power supply (VCC), the drain of the first switch tube (Q5) is respectively connected to one end of the third resistor (R7), one end of the first capacitor (C2) and three mode switching pins, and the other end of the third resistor (R7) is connected to the other end of the first capacitor (C2) and then grounded.

[0067] Each mode switching pin is connected to the switching module 130 via a resistor. Figure 1 As shown, three mode switching pins (GPIO_A3 to GPIO_A1) are respectively connected to the drain of the first switch tube (Q5) through a series resistor, that is, the mode switching pin (GPIO_A3) is connected to one end of the resistor (R15), and the other end of the resistor (R15) is connected to the drain of the first switch tube (Q5); the mode switching pin (GPIO_A2) is connected to one end of the resistor (R14), and the other end of the resistor (R14) is connected to the drain of the first switch tube (Q5); the mode switching pin (GPIO_A1) is connected to one end of the resistor (R13), and the other end of the resistor (R13) is connected to the drain of the first switch tube (Q5). The four mode switching pins are respectively connected to a connection point between a third resistor (R7) and a first capacitor (C2) through a series resistor, that is, the mode switching pin (GPIO_A3) is connected to one end of the resistor (R2), and the other end of the resistor (R2) is connected to the connection point; the mode switching pin (GPIO_A2) is connected to one end of the resistor (R10), and the other end of the resistor (R10) is connected to the connection point; the mode switching pin (GPIO_A1) is connected to one end of the resistor (R11), and the other end of the resistor (R11) is connected to the connection point; the mode switching pin (GPIO_A0) is connected to one end of the resistor (R12), and the other end of the resistor (R12) is connected to the connection point.

[0068] Figure 1 The resistance value of the resistor and the capacitance value of the capacitor marked in are only examples. In different application scenarios, the resistance value and the capacitance value can be other values.

[0069] The structure of the reset module 120 is described below:

[0070] like Figure 1As shown, the reset module 120 includes a second resistor (R3), a fourth resistor (R5), a fifth resistor (R4), a sixth resistor (R6), a seventh resistor (R8), an eighth resistor (R9), a second switch tube (Q6), a transistor (Q1), a diode (D1), a second capacitor (C1) and a third capacitor (C4); wherein the source of the second switch tube (Q6) is connected to a power supply (VCC), the gate of the second switch tube (Q6) is connected to one end of the fourth resistor (R5), the other end of the fourth resistor (R5) is respectively connected to one end of the second resistor (R3), the cathode of the diode (D1) and the switch module 110, the other end of the second resistor (R3) is connected to the power supply (VCC), the second switch tube (Q6) The drain of the transistor (Q1) is connected to one end of a fifth resistor (R4), the other end of the fifth resistor (R4) is respectively connected to one end of a second capacitor (C1), a sixth resistor (R6) and a seventh resistor (R8), the sixth resistor (R6) is connected to the other end of the second capacitor (C1) and then is grounded; the other end of the seventh resistor (R8) is respectively connected to the anode of a diode (D1), one end of a third capacitor (C4) and a base of a transistor (Q1), the collector of the transistor (Q1) is respectively connected to one end of an eighth resistor (R9) and a hardware reset pin (SYS_POR_B), the emitter of the transistor (Q1) is connected to the other end of the third capacitor (C4) and then is grounded, and the other end of the eighth resistor (R9) is connected to a power supply (VCC).

[0071] In one example, the switching module 130 and the reset module 120 may share the second resistor (R3). Of course, in other examples, the switching module 130 and the reset module 120 may not share the second resistor (R3), but each may be connected to a resistor, which will not be described in detail here.

[0072] The diode (D1) in this embodiment needs to meet the requirement of having a very low forward conduction voltage drop Vf, and can be a common diode or a double diode. When the diode (D1) is a double diode, the cathode of the diode (D1) in the above text refers to the connection point of two common diodes connected in series. Figure 1 As shown, the diode (D1) has 3 pins, namely pin1, pin2 and pin3. Pin1 is the anode of the ordinary diode on the left, pin2 is the cathode of the ordinary diode on the right, and pin3 is the connection point between the cathode of the ordinary diode on the left and the anode of the ordinary diode on the right. So, the cathode of the diode (D1) mentioned above refers to Figure 1 pin3 in the .

[0073] The structure of the switch module 110 is described below:

[0074] like Figure 1As shown, the switch module 110 includes a switch (J1); one end of the switch (J1) is respectively connected to one end of the second resistor (R3), one end of the first resistor (R1), the other end of the fourth resistor (R5) and the cathode of the diode (D1), and the other end of the switch (J1) is grounded.

[0075] The working principle of the startup mode switching circuit is described below in combination with the specific structures of the switch module 110, the switching module 120 and the reset module 130:

[0076] When the switch (J1) is closed, the first switch tube (Q5) and the second switch tube (Q6) are turned on at the same time. As a result of the first switch tube (Q5) being turned on, the upper end of the third resistor (R7) has a 3.3V level, and the three mode switching pins (GPIO_A3 to GPIO_A1) are all pulled up to a 3.3V level, i.e., a logic high level "1". The other mode switching pin (GPIO_A0) is grounded by a 51K resistor by default, which is a logic low level "0", so the bootmode is switched to the JTAG mode (1110). As a result of the second switch tube (Q6) being turned on, the power supply (VCC3.3V) charges the second capacitor (C1). However, at this time, the role of the diode (D1) is to clamp the base voltage of the transistor (Q1) at 0.2V to 0.3V, ensuring that the transistor (Q1) will not be turned on. Even if the second capacitor (C1) is fully charged, the transistor (Q1) will not be turned on, so the hardware reset pin (SYS_POR_B) of the MCU will not be pulled down. Therefore, the MCU is not reset at this time and is still in the Flash mode at the last startup. If you need to switch the startup mode of the MCU, you need to reset and restart the MCU.

[0077] When the switch (J1) is disconnected, the first switch tube (Q5) and the second switch tube (Q6) are turned on and off, the upper end of the third resistor (R7) returns to a low level, and the bootmode is switched to the Flash mode (0000). At the same time, the diode (D1) no longer plays a clamping role, and the second capacitor (C1) starts to discharge, which will turn on the transistor (Q1). As a result of the transistor (Q1) being turned on, the hardware reset pin (SYS_POR_B) is pulled low, the MCU is reset, and it is started from the Flash mode (0000), so as to achieve the purpose of making the MCU enter a normal working mode.

[0078] In this embodiment, by adjusting the capacitance of the second capacitor (C1), the reset low time can be extended or shortened accordingly. For details of the simulation results and signal waveforms, see the Multisim simulation results as shown in Figure 2As shown in the figure, when the control switch (J1) is closed or opened, the output level can be seen to change synchronously between high and low. The red color is the bootmode level and the green color is the SYS_POR_B signal level. The simulation results are in line with the design expectations.

[0079] To summarize, the startup mode switching circuit provided in the embodiment of the present application, when the switch module is closed, outputs three high-level signals to the three mode switching pins of the MCU through the switching module, and another mode switching pin of the MCU is grounded, so that the values ​​of the four mode switching pins of the MCU are 1110, and then outputs a low-level signal to the hardware reset pin through the system reset pin to reset and restart the MCU and switch the startup mode to JTAG mode; when the switch module is disconnected, the reset module outputs a low-level signal to the hardware reset pin to reset and restart the MCU and switch the startup mode to Flash mode. In this way, the startup mode of the MCU can be switched by controlling the switch module, avoiding the use of a dip switch to switch the startup mode of the MCU, which can not only improve the switching accuracy but also reduce the cost and operation difficulty.

[0080] like Figure 3 As shown, it shows an MCU debugging system provided by an embodiment of the present application, and the MCU debugging system includes an MCU, a JTAG socket and the startup mode switching circuit as described above.

[0081] Among them, three mode switching pins of the MCU are connected to the switching module, and another mode switching pin is grounded. That is, when the four mode switching pins are GPIO_A3 to GPIO_A0, the output end of the switching module 130 is connected to GPIO_A3 to GPIO_A1, and GPIO_A0 is grounded.

[0082] The hardware reset pin of the MCU is connected to the reset module and the system reset pin in the JTAG socket, respectively. That is, the hardware reset pin (SYS_POR_B) is connected to the reset module and the system reset pin (SRST_N) in the JTAG socket, respectively.

[0083] The switch module is connected to a ground pin in the JTAG socket.

[0084] We can select a GND pin on the JTAG socket. Assuming pin12 is selected, do not connect pin12 to GND during design. Instead, connect pin12 to the left end of the switch (J1).

[0085] In this embodiment, the MCU debugging system also includes a Jlink debugger; when the Jlink debugger is inserted into the JTAG socket, the switch module is closed; when the Jlink debugger is pulled out of the JTAG socket, the switch module is disconnected.

[0086] Since pin4 / 6 / 8 / 10 / 12 / 14 / 16 / 18 / 20 on the Jlink debugger are all connected GND signals by default, plugging the Jlink debugger cable into the JTAG socket is equivalent to connecting pin12 of the JTAG socket to the GND of the adjacent pin, which means that the switch (J1) is closed to ground.

[0087] In this embodiment, the system reset pin (SRST_N) in the Jlink debugger is connected to the system reset pin (SRST_N) in the JTAG socket; when the Jlink debugger receives a preset Jlink instruction, the system reset pin (SRST_N) in the Jlink debugger is used to output a low-level signal to the system reset pin (SRST_N) in the JTAG socket under the control of the Jlink instruction; the system reset pin (SRST_N) in the JTAG socket is used to output a low-level signal to the hardware reset pin (SYS_POR_B) to reset and restart the MCU.

[0088] Specifically, we can connect the Jlink debugger to the JTAG socket on the MCU board, and then reset the MCU through the pin control command of the Jlinkcommander, so that the MCU resets and restarts, and then successfully enters the JTAG mode.

[0089] The following is an example of resetting the MCU through the Jlink command:

[0090] In the Jlink commander interface, enter the question mark "?" and press Enter. The Jlink pincontrol instructions will pop up, such as Figure 4 Then, input "r0" and press Enter --- the reset state will be cleared, then input "r1" and press Enter --- the reset MCU action will take effect, as shown in the following figure. Figure 5 As shown in the figure, at this time, pin15 (system reset pin SRST_N) on the JTAG socket will output a low level, pulling down the hardware reset pin (SYS_POR_B) of the MCU to reset and restart the MCU. After reset and restart, the MCU can smoothly enter the JTAG mode (1110). At this time, the Jlink debugger can attach to the MCU and debug and download programs to the MCU.

[0091] In summary, the MCU debugging system provided in the embodiment of the present application can realize the plug-and-play of the Jlink debugger without adding DIP switch materials and manual dialing, which is convenient for software debugging and program burning.

[0092] like Figure 6As shown, it shows a startup mode switching method of an MCU provided by an embodiment of the present application, which is used in the MCU debugging system as described above, and the method includes:

[0093] Step 601, determine the startup mode required by the MCU.

[0094] The boot modes include Flash mode and JTAG mode. You can select the required boot mode according to actual needs.

[0095] Step 602, when the startup mode is JTAG mode, the control switch module is closed, and three high-level signals are output to the three mode switching pins through the switching module. The system reset pin is controlled by the preset Jink instruction to output a low-level signal to the hardware reset pin, so that the MCU is reset and restarted and the startup mode is switched to JTAG mode.

[0096] When the boot mode is JTAG mode, control the Jlink debugger to connect to the JTAG socket, that is, insert the Jlink debugger into the JTAG socket. At this time, the first switch tube (Q5) and the second switch tube (Q6) are turned on at the same time. The result of the first switch tube (Q5) being turned on is that the upper end of the third resistor (R7) has a 3.3V level, and the three mode switching pins (GPIO_A3~GPIO_A1) will be pulled up to 3.3V level, that is, the logic high level "1", and the other mode switching pin (GPIO_A0) is 51K resistor grounded by default, which is a logic low level "0", so the bootmode is switched to JTAG mode (1110). The result of the second switch tube (Q6) being turned on is that the power supply (VCC3.3V) charges the second capacitor (C1). However, at this time, the role of the diode (D1) is to clamp the base voltage of the transistor (Q1) at 0.2V~0.3V to ensure that the transistor (Q1) will not be turned on. Even if the second capacitor (C1) is fully charged, the transistor (Q1) will not be turned on, so the hardware reset pin (SYS_POR_B) of the MCU will not be pulled down. Therefore, the MCU is not reset at this time and is still in the Flash mode at the last startup. If you need to switch the startup mode of the MCU, you need to reset and restart the MCU through the Jlink command.

[0097] Specifically, the system reset pin in the Jlink debugger is connected to the system reset pin in the JTAG socket, and the method also includes: when the Jlink debugger receives a preset Jlink instruction, the system reset pin in the Jlink debugger outputs a low-level signal to the system reset pin in the JTAG socket under the control of the Jlink instruction; the system reset pin in the JTAG socket outputs a low-level signal to the hardware reset pin to reset and restart the MCU.

[0098] In the Jlink commander interface, enter the question mark "?" and press Enter. The Jlink pincontrol instructions will pop up, such as Figure 4 Then, input "r0" and press Enter --- the reset state will be cleared, then input "r1" and press Enter --- the reset MCU action will take effect, as shown in the following figure. Figure 5 As shown in the figure, at this time, pin15 (system reset pin SRST_N) on the JTAG socket will output a low level, pulling down the hardware reset pin (SYS_POR_B) of the MCU to reset and restart the MCU. After reset and restart, the MCU can smoothly enter the JTAG mode (1110). At this time, the Jlink debugger can attach to the MCU and debug and download programs to the MCU.

[0099] Step 603: When the startup mode is the Flash mode, the switch module is controlled to be disconnected, and a low level signal is output to the reset pin through the reset module, so that the MCU is reset and restarted and the startup mode is switched to the Flash mode.

[0100] When the boot mode is Flash mode, the Jlink debugger is controlled to be separated from the JTAG socket, that is, the Jlink debugger is pulled out of the JTAG socket. At this time, the first switch tube (Q5) and the second switch tube (Q6) are turned on and off, the upper end of the third resistor (R7) returns to a low level, and the bootmode is switched to Flash mode (0000). At the same time, the diode (D1) no longer acts as a clamp, and the second capacitor (C1) begins to discharge, which will turn on the transistor (Q1). As a result of the transistor (Q1) being turned on, the hardware reset pin (SYS_POR_B) is pulled low, the MCU is reset, and it is started from Flash mode (0000), so as to achieve the purpose of making the MCU enter the normal working mode.

[0101] In summary, the MCU startup mode switching method provided in the embodiment of the present application can realize the plug-and-play of the Jlink debugger without adding DIP switch materials and manual dialing, which is convenient for software debugging and program burning.

[0102] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0103] The above description is not intended to limit the embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present application should be included in the protection scope of the embodiments of the present application.

Claims

1. A startup mode switching circuit for an MCU, It is characterized in that The startup mode switching circuit includes: a switch module, a reset module and a switching module; The switch module is connected to the reset module and the switching module respectively; The switching module is connected to three mode switching pins of the MCU, and another mode switching pin of the MCU is grounded; The reset module is connected to the hardware reset pin of the MCU, and the hardware reset pin is also connected to the system reset pin in the JTAG socket; When the switch module is closed, the switch module is used to output three high-level signals to the three mode switch pins, and the system reset pin is used to output a low-level signal to the hardware reset pin under the control of a preset Jlink instruction, so that the MCU is reset and restarted and the boot mode is switched to the JTAG mode; When the switch module is disconnected, the reset module is used to output a low level signal to the hardware reset pin, so that the MCU is reset and restarted and the startup mode is switched to the Flash mode.

2. The startup mode switching circuit of the MCU according to claim 1, It is characterized in that The switching module includes first to third resistors, a first switch tube and a first capacitor; The source of the first switch tube is connected to a power supply, the gate of the first switch tube is connected to one end of a first resistor, the other end of the first resistor is connected to one end of the second resistor, the other end of the second resistor is connected to a power supply, the drain of the first switch tube is respectively connected to one end of a third resistor, one end of the first capacitor and the three mode switching pins, the other end of the third resistor is connected to the other end of the first capacitor and then grounded.

3. The startup mode switching circuit of the MCU according to claim 1, It is characterized in that The reset module includes a second resistor, fourth to eighth resistors, a second switch tube, a triode, a diode, a second capacitor and a third capacitor; The source of the second switch tube is connected to a power supply, the gate of the second switch tube is connected to one end of a fourth resistor, the other end of the fourth resistor is respectively connected to one end of the second resistor, the cathode of the diode and the switch module, the other end of the second resistor is connected to a power supply, the drain of the second switch tube is connected to one end of a fifth resistor, the other end of the fifth resistor is respectively connected to one end of a second capacitor, a sixth resistor and a seventh resistor, the sixth resistor is connected to the other end of the second capacitor and then grounded; The other end of the seventh resistor is respectively connected to the anode of the diode, one end of the third capacitor and the base of the transistor, the collector of the transistor is respectively connected to one end of the eighth resistor and the hardware reset pin, the emitter of the transistor is connected to the other end of the third capacitor and then grounded, and the other end of the eighth resistor is connected to the power supply.

4. The startup mode switching circuit of the MCU according to claim 3, It is characterized in that The switch module includes a switch; One end of the switch is respectively connected to one end of the second resistor, one end of the first resistor, the other end of the fourth resistor and the cathode of the diode, and the other end of the switch is grounded.

5. An MCU debugging system, It is characterized in that The MCU debugging system comprises an MCU, a JTAG socket and a startup mode switching circuit as described in any one of claims 1 to 4; Three mode switching pins of the MCU are connected to the switching module, and another mode switching pin is grounded; The hardware reset pin of the MCU is connected to the reset module and the system reset pin in the JTAG socket respectively; The switch module is connected to a ground pin in the JTAG socket.

6. The MCU debugging system according to claim 5, It is characterized in that The MCU debugging system also includes a Jlink debugger; When the Jlink debugger is inserted into the JTAG socket, the switch module is closed; When the Jlink debugger is pulled out from the JTAG socket, the switch module is disconnected.

7. The MCU debugging system according to claim 5, It is characterized in that The system reset pin in the Jlink debugger is connected to the system reset pin in the JTAG socket; When the Jlink debugger receives a preset Jlink instruction, the system reset pin in the Jlink debugger is used to output a low level signal to the system reset pin in the JTAG socket under the control of the Jlink instruction; The system reset pin in the JTAG socket is used to output a low level signal to the hardware reset pin to reset and restart the MCU.

8. A method for switching the startup mode of an MCU, It is characterized in that Used in the MCU debugging system according to any one of claims 5 to 7, the method comprises: Determine the startup mode required by the MCU; When the startup mode is the JTAG mode, the switch module is controlled to be closed, three high-level signals are output to the three mode switching pins through the switching module, and the system reset pin is controlled to output a low-level signal to the hardware reset pin through a preset Jink instruction, so that the MCU is reset and restarted and the startup mode is switched to the JTAG mode; When the startup mode is the Flash mode, the switch module is controlled to be disconnected, and a low level signal is output to the reset pin through the reset module, so that the MCU is reset and restarted and the startup mode is switched to the Flash mode.

9. The method for switching the startup mode of the MCU according to claim 7, It is characterized in that The MCU debugging system also includes a Jlink debugger; The controlling the switch module to close includes: controlling the Jlink debugger to connect to the JTAG socket; The controlling the switch module to disconnect includes: controlling the Jlink debugger to separate from the JTAG socket.

10. The method for switching the startup mode of the MCU according to claim 8, It is characterized in that The system reset pin in the Jlink debugger is connected to the system reset pin in the JTAG socket, and the method further includes: When the Jlink debugger receives a preset Jlink instruction, the system reset pin in the Jlink debugger outputs a low level signal to the system reset pin in the JTAG socket under the control of the Jlink instruction; The system reset pin in the JTAG socket outputs a low level signal to the hardware reset pin, so that the MCU is reset and restarted.