Stack detection system, stack detection method and stack detection device
Through the stack detection system, the stack pointer value and maximum available space value of the MCU chip are compared in real time, which solves the stack overflow problem, improves program stability and developer debugging efficiency, and achieves precise control of stack space.
Patent Information
- Application Number
- CN202411135869.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-13
AI Technical Summary
In multi-threaded and highly concurrency application scenarios, the stability of the program is critically affected by stack management, and improper stack use often leads to stack overflow, resulting in program crashes or security vulnerabilities, and it is difficult for the existing technology to effectively detect and prevent stack overflow.
Provides a stack detection system, which can access the MAP file of the MCU chip through the terminal device to obtain the stack bottom address and the maximum free space value, compare the current stack pointer value with the maximum stack pointer value in real time, display the percentage of stack usage and issue a warning when overflowing, Prevent stack overflow.
Real-time detection of MCU chip stack overflow is achieved, program crashes and data corruption are avoided, program stability and developer debugging efficiency are improved, stack space is precisely controlled, and RAM waste and overflow risks are prevented.
Smart Images

Figure CN119127736A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of embedded system testing, and in particular to a stack detection system, a stack detection method and a stack detection device. Background Art
[0002] As computer systems become increasingly complex, the size of software programs is also expanding. In multi-threaded, high-concurrency application scenarios, program stability is particularly important. Stack management is one of the key factors to ensure stable program operation. However, in the process of program design and implementation, improper stack usage often leads to stack overflow problems, which not only cause program crashes, but can also be maliciously exploited to cause security vulnerabilities. Therefore, it is particularly important to detect whether the program has stack overflows and to feedback the actual stack usage to the developer for the stable operation of the program. Summary of the invention
[0003] The purpose of the present invention is to provide a stack detection system, a stack detection method and a stack detection device, which can realize real-time detection of whether a stack overflows and provide real-time feedback when a program is running, so as to help developers quickly locate problems and improve the stability and security of the software.
[0004] The technical solution provided by the present invention is as follows:
[0005] In a first aspect, the present invention provides a stack detection system, comprising:
[0006] The terminal device is used to access the MAP file of the MCU chip program to be tested, and obtain the stack bottom address and the stack maximum available space value set by the software in the MCU chip program to be tested by parsing the MAP file;
[0007] A stack detection device, connected to the terminal device for receiving the maximum available space value of the stack and the stack bottom address;
[0008] The stack detection device is also used to obtain the current stack pointer value of the software in the MCU chip program to be tested in real time, and when the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, display the actual usage percentage of the current stack, and when the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, save and display the current stack pointer value as the new maximum stack pointer value;
[0009] The stack detection device is also used to compare the maximum stack pointer value with the maximum available stack space value, and display a warning when the maximum stack pointer value is greater than the maximum available stack space value.
[0010] The above stack detection system compares the maximum stack pointer value and the maximum available stack space value of the MCU chip to be tested in real time through the stack detection device, thereby realizing stack overflow detection of the MCU chip to be tested, effectively avoiding the problem of program crash and data corruption caused by stack overflow, and improving the stability of the program.
[0011] In some embodiments, the stack detection device further comprises:
[0012] A USB interface or a UART interface, wherein the stack detection device is connected to the terminal device via the USB interface or the UART interface, and is used to receive the maximum available space value of the stack and the bottom address of the stack sent by the terminal device.
[0013] In some embodiments, the stack detection device further comprises:
[0014] SWD interface, the stack detection device is connected to the MCU chip to be tested through the SWD interface, and is used to obtain the current stack pointer value of the MCU chip to be tested in real time.
[0015] In some embodiments, the stack detection system further comprises:
[0016] A display screen is connected to the stack detection device and is used to display the actual usage percentage of the current stack and / or the maximum stack pointer value.
[0017] The above stack detection system is connected to the display screen through the stack detection device, and displays the actual usage percentage of the current stack and / or the maximum stack pointer value on the display screen, thereby realizing real-time monitoring and intuitive feedback of stack usage, improving the developer's debugging efficiency and program stability.
[0018] In some embodiments, the stack detection device further comprises:
[0019] The alarm module is used to give an alarm when the maximum stack pointer value is greater than the maximum available space value of the stack.
[0020] In some embodiments, the alarm module includes:
[0021] A first capacitor, a first resistor, a second resistor, a third resistor, a triode, a diode and a speaker;
[0022] The base of the transistor is connected to the processor of the stack detection device through a first resistor and a first capacitor connected in series, the emitter of the transistor is grounded, and the second resistor is connected between the emitter and the base of the transistor, the collector of the transistor is connected to the negative electrode of the speaker, and the positive electrode of the speaker is connected to the power supply through the third resistor, the diode is connected in parallel at both ends of the speaker, and the positive electrode of the diode is connected to the negative electrode of the speaker.
[0023] In some implementations, the stack detection device is further configured to store the actual usage percentage, calculate a maximum stack usage depth based on the actual usage percentage, and set a stack space value based on the maximum stack usage depth.
[0024] This solution calculates the maximum depth of stack usage through actual usage percentage, and further sets the size of the stack space, thereby achieving precise control of the stack space and preventing RAM waste caused by overly large stack settings and overflow risks caused by underlying stack settings.
[0025] In a second aspect, the present invention further provides a stack detection method, applied to a stack detection device, comprising:
[0026] Receiving a stack maximum available space value and a stack bottom address sent by a terminal device, wherein the stack maximum available space value and the stack bottom address are obtained by the terminal device accessing and parsing a MAP file;
[0027] Get the current stack pointer value and stack bottom address of the MCU chip under test in real time;
[0028] When the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, display the actual usage percentage of the current stack; when the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, save and display the current stack pointer value as the new maximum stack pointer value;
[0029] The maximum stack pointer value is compared with the maximum available stack space value, and a warning is displayed when the maximum stack pointer value is greater than the maximum available stack space value.
[0030] In some embodiments, a stack detection method provided by the present invention further includes: storing or recording the actual usage percentage, calculating the maximum depth of stack usage according to the actual usage percentage, and setting the stack space value according to the maximum depth of stack usage.
[0031] In a third aspect, the present invention further provides a stack detection device, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any of the above-mentioned stack detection methods.
[0032] Compared with the prior art, the present invention has at least one of the following beneficial effects:
[0033] 1. The stack detection device compares the maximum stack pointer value and the maximum available stack space value of the MCU chip to be tested, thereby realizing the stack overflow detection of the MCU chip to be tested, effectively avoiding the problem of program crash and data corruption caused by stack overflow, and improving the stability of the program and the debugging efficiency of developers.
[0034] 2. The stack detection device is connected to the display screen, and the actual usage percentage of the current stack and / or the maximum stack pointer value are displayed on the display screen, which realizes real-time monitoring and intuitive feedback of stack usage and improves the debugging efficiency of developers.
[0035] 3. The maximum depth of stack usage is calculated through the actual usage percentage, and the size of the stack space is further set to achieve precise control of the stack space, preventing RAM waste caused by excessive stack settings and overflow risks caused by excessive stack settings. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The preferred implementation scheme will be described below in a clear and understandable manner with reference to the accompanying drawings to further illustrate the above-mentioned characteristics, technical features, advantages and implementation methods of the present solution.
[0037] Figure 1 An application block diagram of a stack detection system provided in an embodiment of the present application;
[0038] Figure 2 A schematic diagram of the circuit structure of a stack detection device provided in an embodiment of the present application;
[0039] Figure 3 A flowchart of a stack detection method provided in an embodiment of the present application.
[0040] Figure numbers: terminal device-100, stack detection device-200, MCU chip to be tested-300, display screen-400, USB interface-210, SWD interface-220 and alarm module-230. DETAILED DESCRIPTION
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work.
[0042] In order to simplify the drawings, only the parts related to the present invention are schematically shown in each figure, and they do not represent the actual structure of the product. In addition, in order to simplify the drawings and facilitate understanding, in some figures, only one of the parts with the same structure or function is schematically drawn or marked. In this article, "one" not only means "only one", but also means "more than one".
[0043] As computer systems become increasingly complex, the size of software programs is also expanding. In multi-threaded, high-concurrency application scenarios, program stability is particularly important. Stack management is one of the key factors to ensure stable program operation. Among them, the stack is a data structure that follows the last-in, first-out principle and is mainly used to store information during function calls, such as local variables, function parameters, and return addresses. The stack usually grows from high addresses to low addresses (downward growth). Whenever a function is called, new data is pushed to the top of the stack; when the function is executed, the data is popped from the stack. However, in the process of program design and implementation, improper stack use often leads to stack overflow problems. Stack overflow not only causes program crashes, but can also be maliciously exploited to cause security vulnerabilities.
[0044] Therefore, there is an urgent need on the market for a device that can detect stack overflow and feed back the actual usage of the stack.
[0045] The stack detection device designed in this application stores stack data in an upward growth manner, detects the stack pointer value of the software in the MCU chip program in real time, and compares the current stack pointer value with the maximum stack pointer value saved at the last moment. When the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, the actual usage percentage of the current stack is displayed, so that developers can clearly view the stack usage, and when the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, the current stack pointer value is saved and displayed as the new maximum stack pointer value, so that developers can see the maximum usage value of the stack, and the maximum usage value of the stack can be adjusted in time to prevent stack overflow. This application also compares the maximum stack pointer value and the maximum available space value of the stack. When the maximum stack pointer value is greater than the maximum available space value of the stack, a stack overflow display warning is issued, so that developers can promptly handle the stack overflow problem through warning information. The following will describe the scheme in detail in conjunction with the accompanying drawings:
[0046] In one embodiment, Figure 1As shown, the present disclosure provides a stack detection system, including a terminal device 100, a stack detection device 200, and an MCU chip 300 to be tested. The terminal device 100 is used to access the MAP file of the program of the MCU chip 300 to be tested, and obtain the stack bottom address, the maximum available space value of the stack, and the occupied RAM space position of the software set in the program of the MCU chip 300 to be tested by parsing the MAP file. The terminal device 100 is also used to send the parsing result to the stack detection device 200; the stack detection device 200 is connected to the terminal device 100 for communication, and is used to receive the maximum available space value of the stack and the occupied RAM space position. The stack detection device 200 is also used to obtain the current stack pointer value of the software in the program of the MCU chip 300 to be tested in real time, and when the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, the actual usage percentage of the current stack is displayed. When the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, the current stack pointer value is saved and displayed as the new maximum stack pointer value; the stack detection device 200 is also used to compare the maximum stack pointer value and the maximum available space value of the stack, and display a warning when the maximum stack pointer value is greater than the maximum available space value of the stack. In this process, the stack detection device stores the stack pointer in an upward growth manner.
[0047] In another embodiment of the present application, based on any one of the above-mentioned embodiments, the stack detection device uses a downward-growing manner to store the stack pointer to achieve the effect of detecting stack overflow, and the stack detection device 200 receives the maximum available space value of the stack; the stack detection device 200 also obtains the current stack pointer value of the software in the program of the MCU chip 300 to be tested in real time, and when the current stack pointer value is greater than the maximum stack pointer value saved at the previous moment, displays the actual usage percentage of the current stack, and when the current stack pointer value is not greater than the maximum stack pointer value saved at the previous moment, saves and displays the current stack pointer value as the new maximum stack pointer value; the stack detection device 200 is also used to compare the maximum stack pointer value and the maximum available space value of the stack, and display a warning when the maximum stack pointer value is greater than the maximum available space value of the stack.
[0048] This solution uses the terminal device 100 to access and parse the MAP file of the software in the program of the MCU chip 300 to be tested, and obtains the maximum available space value and the stack bottom address of the stack of the MCU chip 300 to be tested, so as to obtain the threshold value of the software stack overflow in the program of the MCU chip 300 to be tested. The stack detection device 200 receives the threshold value, and obtains and compares the current stack pointer value of the software in the program of the MCU chip 300 to be tested and the maximum stack pointer value saved at the last moment in real time. When the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, the actual usage percentage of the current stack is displayed, so as to realize the practical situation of the stack. Real-time monitoring of the status of the stack pointer. When the current stack pointer value is greater than the maximum stack pointer value saved at the previous moment, the current stack pointer value is saved and displayed as the new maximum stack pointer value; thereby, the developer can observe the maximum value of the stack usage in real time and further adjust the stack usage. The stack monitoring device is also used to compare the maximum stack pointer value and the maximum available stack space value. When the maximum stack pointer value exceeds the maximum available stack space value, a warning is issued, that is, when the maximum usage value of the stack exceeds the threshold, the stack overflows, and the stack device displays a warning, so that the developer can promptly notice the problem of stack overflow to avoid problems such as system crashes.
[0049] In one embodiment, Figure 2 As shown, the stack detection device 200 also includes a USB interface 210 or a UART interface, which is used for connecting the stack detection device 200 to the terminal device 100 through the USB interface 210 or the UART interface, and is also used to receive the stack maximum available space value and the stack bottom address sent by the terminal device 100.
[0050] This solution specifically introduces the USB interface 210, specifically, Figure 2 As shown, the USB interface corresponds to the USB1 interface in this solution, the V+ signal line of the USB1 interface is grounded through a capacitor C1, and the other end of the capacitor C1 is connected to a 5V power supply. The capacitor C1 is used to filter out ripples in the circuit, and the V- signal line of the USB1 interface is grounded. The function of the V+ signal line and the V- signal line of the USB1 interface is to power the stack detection device 200. The D+ signal line of the USB1 interface is connected to the USB_DP-PA12 pin of the processor of the stack detection device 200 through a series resistor R3, and the D- signal line of the USB1 interface is connected to the USB_DM-PA11 pin of the processor of the stack detection device 200 through a series resistor R2. Resistors R2 and R3 are used to improve signal integrity and reduce reflections and other signal distortion problems. The D+ signal line and the D- signal line constitute a pair of differential signal lines, and the stack space value is transmitted according to the voltage difference between the two signal lines. This differential signal method helps to reduce the impact of electromagnetic interference and improve the reliability and stability of the signal.
[0051] Using a USB interface to connect the terminal device 100 and the stack detection device 200 can achieve stable data transmission, and the USB interface can provide power for the stack detection device, which means that no additional power adapter or battery is required, making the stack detection device 200 a practical and efficient tool.
[0052] In one embodiment, Figure 2 As shown, the stack detection device 200 also includes a SWD interface 220. The stack detection device 200 is connected to the terminal device 100 via the SWD interface 220 to obtain the current stack pointer value of the MCU chip to be tested in real time.
[0053] Specifically, pin 1 of the SWD interface 220 is connected to VCC, pin 2 of the SWD interface 220 is grounded, pin 3 of the SWD interface 220, namely the SWDIO pin, is connected to pins PA6 and PA7 of the processor of the stack detection device through a resistor R10, and is used for the processor to receive the stack pointer data of the MCU chip 300 to be tested, and is also used for the MCU chip 300 to be tested to send the stack pointer data to the processor, and pin 4 of the SWD interface, namely the SWCLK pin, is connected to pin PA5 of the processor through a resistor R11, and is used to synchronize the stack pointer data. The processor sends commands to the MCU chip to be tested through the SWDIO pin, and the MCU chip to be tested receives commands through the SWDIO pin, and sends the stack pointer data to the processor through the SWDIO pin, and the processor reads the stack pointer data through the SWDIO pin, and the SWCLK pin provides a clock signal to synchronize the data transmission on the SWDIO line.
[0054] The SWD interface 220 only needs two signal lines to efficiently realize data transmission between the stack detection device 200 and the MCU chip to be tested, and the two signal lines reduce the complexity of wiring, so that the stack detection device 200 can be easily connected to various MCU chips to be tested.
[0055] In one embodiment, Figure 1 As shown, the stack detection system further includes a display screen 400, which is connected to the stack detection device 200 and is used to display the actual usage percentage of the current stack and / or the maximum stack pointer value.
[0056] Specifically, Figure 2As shown, the display screen 400 includes an OLED display module, the D0 (SCL) pin of the OLED display module is connected to the PB13 pin of the processor through a resistor R8, the D1 (SDA) pin of the OLED display module is connected to the WKUP5-PB15 pin of the processor through a resistor R9, the resistors R8 and R9 are used to ensure signal quality and protect the circuit, the RES# pin of the OLED display module is connected to the PA8 pin of the processor, the D / C# pin of the OLED display module is connected to the PB14 pin of the processor, the CS# pin of the OLED display module is connected to the PB12 pin of the processor, the VCC pin of the OLED display module is connected to the power supply through parallel capacitors C13 and C14, the capacitors C13 and C14 constitute a filter circuit for filtering out noise in the circuit, and the GND pin of the OLED display module is grounded.
[0057] The processor pulls the PA8 pin (RES pin) low for a period of time, and then pulls it high to ensure that the display screen 400 is reset to initialize the display screen. After that, the processor pulls the PB12 pin (CS pin) low to select the display screen 400. The processor pulls the PB14 pin (DC pin) low to indicate that data is to be sent next. The processor sends the actual usage percentage data and / or the maximum stack pointer value of the current stack through the WKUP5-PB15 pin (MOSI pin), and sends a clock signal through the PB18 pin (SCK pin) to synchronize data transmission. After sending all the data, the processor pulls the PB12 pin (CS pin) high to release the display screen 400. In this way, the processor can effectively communicate with the display screen 400 and control the display screen 400 to display the required content, such as the actual usage percentage of the current stack and the maximum stack pointer value, so as to realize real-time monitoring and visualization of stack usage and effectively improve the debugging efficiency of developers.
[0058] In one embodiment, Figure 2 As shown, the stack detection device 200 also includes an alarm module 230, which is used to alarm when the maximum stack pointer value is greater than the maximum available stack space value. The alarm module 230 can promptly detect stack overflow and issue a sound warning when the stack exceeds the critical value. It is also used to alarm when the stack detection device 200 is successfully connected to the terminal device 100, which helps to ensure the accuracy of stack detection and prevent misdiagnosis due to connection problems.
[0059] In one embodiment, Figure 2 As shown, the alarm module 230 includes: a first capacitor C12, a first resistor R6, a second resistor R7, a third resistor R4, a transistor Q1, a diode D1 and a speaker U3;
[0060] The base of the transistor Q1 is connected to the processor of the stack detection device 200 through a first resistor R6 and a first capacitor C12 connected in series. The first capacitor C12 is used to couple the processor output signal to the base of the transistor Q1 and isolate direct current. The first resistor R6 is used to limit the current from the processor to the base of the transistor Q1. The emitter of the transistor Q1 is grounded, and a second resistor R7 is connected between the emitter and the base of the transistor Q1. The second resistor R7 is used to provide a pull-down effect to help stabilize the working state of the transistor Q1. The collector of the transistor Q1 is connected to the negative electrode of the speaker, and the positive electrode of the speaker is connected to the power supply through a third resistor R4. The third resistor R4 is used to limit the current in the speaker to prevent overload. The diode D1 is connected in parallel at both ends of the speaker to protect the speaker from damage caused by reverse voltage, and the positive electrode of the diode D1 is connected to the negative electrode of the speaker.
[0061] Specifically, when there is no signal input, the processor outputs a low level, almost no current flows into the base of transistor Q1, transistor Q1 is in a cut-off state, and the speaker does not work. When the processor outputs a high level, the signal is coupled to the base of transistor Q1 through the first resistor R6 and the first capacitor C12, and the base current of transistor Q1 increases, so that transistor Q1 enters a saturation state, and a low impedance channel is formed between the collector and emitter of transistor Q1. Current flows through the speaker, causing it to make a sound. This circuit implements a simple alarm system that can drive the speaker to sound a prompt when the processor outputs a specific signal. It can provide instant feedback to inform the user of changes in system status, such as stack overflow or confirmation of connection status.
[0062] Another embodiment of a stack detection device 200 of the present application, based on any of the above embodiments, an N-channel MOS tube used as a triode can also achieve the effect of driving a speaker, the source of the MOS tube is grounded, the drain is connected to the speaker, and the gate is connected to the processor through a resistor, which is not limited in the present application.
[0063] In one embodiment, the stack detection device 200 is also used to store the actual usage percentage, count the maximum depth of stack usage according to the actual usage percentage, and set the stack space value according to the maximum depth of stack usage. By counting the maximum depth of stack usage, developers can evaluate the size of stack space settings, prevent RAM waste caused by stack settings that are too large, and prevent overflow risks caused by stack settings that are too small, thereby improving the utilization of stack space.
[0064] In one embodiment, Figure 3As shown, the entire stack detection system includes a terminal device, a stack detection device, and an MCU chip to be tested. The terminal device obtains the maximum available space value and the stack bottom address of the software in the MCU chip program to be tested by accessing and parsing the MAP file. The stack detection device obtains the current stack pointer value of the software in the MCU chip program to be tested in real time and saves the maximum pointer value at the last moment. At the same time, the stack detection device also compares the current stack pointer value with the maximum stack pointer value saved at the last moment. When the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, the stack detection device displays the current stack usage percentage. When the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, the stack detection device saves and displays the current stack pointer value as the new maximum stack pointer value. After obtaining the maximum stack pointer value, the stack detection device continues to compare the maximum stack pointer value with the maximum available space value of the stack. When the maximum stack pointer value is greater than the maximum available space value of the stack, the stack overflows. The stack detection device issues a warning to prompt the developer, thereby realizing the detection of stack overflow problems and improving debugging efficiency and program stability.
[0065] In one embodiment, the present application provides a stack detection method, applied to a stack detection device, comprising:
[0066] S100, receiving a stack maximum available space value and a stack bottom address sent by a terminal device, where the stack maximum available space value and the stack bottom address are obtained by the terminal device accessing and parsing a MAP file;
[0067] S200, obtaining the current stack pointer value and stack bottom address of the MCU chip to be tested in real time;
[0068] S300, when the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, the actual usage percentage of the current stack is calculated according to the current stack pointer value and the maximum available space value of the stack, and the actual usage percentage of the current stack is displayed; when the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, the current stack pointer value is saved and displayed as the new maximum stack pointer value;
[0069] S400, comparing the maximum stack pointer value and the maximum available stack space value, and displaying a warning when the maximum stack pointer value is greater than the maximum available stack space value.
[0070] In one embodiment, the stack detection method further includes: storing or recording the actual usage percentage, calculating the maximum depth of stack usage according to the actual usage percentage, and setting the stack space value according to the maximum depth of stack usage.
[0071] In one embodiment, the present application provides a stack detection device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any of the above-mentioned stack detection methods.
[0072] It should be noted that the above embodiments can be freely combined as needed. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered as the protection scope of the present invention.
Claims
1. A stack detection system, It is characterized in that include: The terminal device is used to access the MAP file of the MCU chip program to be tested, and obtain the stack bottom address and the stack maximum available space value set by the software in the MCU chip program to be tested by parsing the MAP file; A stack detection device, connected to the terminal device for receiving the maximum available space value of the stack and the stack bottom address; The stack detection device is also used to obtain the current stack pointer value of the software in the MCU chip program to be tested in real time, and when the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, display the actual usage percentage of the current stack, and when the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, save and display the current stack pointer value as the new maximum stack pointer value; The stack detection device is also used to compare the maximum stack pointer value with the maximum available stack space value, and display a warning when the maximum stack pointer value is greater than the maximum available stack space value.
2. The stack detection system according to claim 1, It is characterized in that The stack detection device also includes: A USB interface or a UART interface, wherein the stack detection device is connected to the terminal device via the USB interface or the UART interface, and is used to receive the maximum available space value of the stack sent by the terminal device.
3. The stack detection system according to claim 1, It is characterized in that The stack detection device also includes: SWD interface, the stack detection device is connected to the MCU chip to be tested through the SWD interface, and is used to obtain the current stack pointer value of the MCU chip to be tested in real time.
4. The stack detection system according to claim 1, It is characterized in that Also includes: A display screen is connected to the stack detection device and is used to display the actual usage percentage of the current stack and / or the maximum stack pointer value.
5. The stack detection system according to claim 1, It is characterized in that The stack detection device also includes: The alarm module is used to give an alarm when the maximum stack pointer value is greater than the maximum available space value of the stack.
6. The stack detection system according to claim 5, It is characterized in that The alarm module comprises: A first capacitor, a first resistor, a second resistor, a third resistor, a triode, a diode and a speaker; The base of the transistor is connected to the processor of the stack detection device through a first resistor and a first capacitor connected in series, the emitter of the transistor is grounded, and the second resistor is connected between the emitter and the base of the transistor, the collector of the transistor is connected to the negative electrode of the speaker, and the positive electrode of the speaker is connected to the power supply through the third resistor, the diode is connected in parallel at both ends of the speaker, and the positive electrode of the diode is connected to the negative electrode of the speaker.
7. The stack detection system according to claim 1, It is characterized in that The stack detection device is further used to store the actual usage percentage, calculate the maximum depth of stack usage according to the actual usage percentage, and set the stack space value according to the maximum depth of stack usage.
8. A stack detection method, It is characterized in that Applicable to stack detection devices, including: Receiving a stack maximum available space value and a stack bottom address sent by a terminal device, wherein the stack maximum available space value and the stack bottom address are obtained by the terminal device accessing and parsing a MAP file; Get the current stack pointer value and stack bottom address of the MCU chip under test in real time; When the current stack pointer value is not greater than the maximum stack pointer value saved at the last moment, display the actual usage percentage of the current stack; when the current stack pointer value is greater than the maximum stack pointer value saved at the last moment, save and display the current stack pointer value as the new maximum stack pointer value; The maximum stack pointer value is compared with the maximum available stack space value, and a warning is displayed when the maximum stack pointer value is greater than the maximum available stack space value.
9. The stack detection method according to claim 8, It is characterized in that Also includes: The actual usage percentage is stored or recorded, a maximum stack usage depth is calculated according to the actual usage percentage, and a stack space value is set according to the maximum stack usage depth.
10. A stack detection device, comprising a memory, a processor and a computer program stored in the memory, It is characterized in that The processor executes the computer program to implement the steps of the stack detection method according to claim 8 or 9.
