Microcontroller Stack Overflow Prevention via Key Monitoring
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods for managing microcontroller stacks in embedded systems are inefficient in estimating optimal stack size, often leading to stack overflow issues and disrupting system execution, while consuming excessive processor resources.
Innovation Solution
A method that writes N keys in the microcontroller stack with decreasing memory space from the start to the end, allowing for precise monitoring of stack occupancy without excessive resource consumption, involving key distribution and storage in a data table, and reinitialization when keys are reached.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If theoretical calculations are used to evaluate stack size for limited theoretical scenarios, then stack overflow is avoided, but the stack size is significantly overestimated leading to design cost overrun
Solution Approach 1:
The patent applies preliminary action by pre-distributing N keys at specific addresses within the stack memory before process execution begins. These keys are positioned at addresses calculated based on the expected maximum stack usage, creating a predetermined monitoring structure that enables accurate tracking without requiring excessive stack allocation.
Solution Approach 2:
The patent uses keys as intermediary markers distributed throughout the stack memory. These keys serve as mediators between the stack management system and the monitoring process, allowing the system to detect stack usage levels by checking which keys have been overwritten, thereby enabling precise monitoring without consuming additional processor resources during runtime.
2Measurement precision
If keys are distributed throughout the stack with decreasing memory space intervals, then precise stack occupancy monitoring is achieved, but device complexity increases
Solution Approach 1:
The patent segments the stack monitoring function by distributing multiple keys at different addresses throughout the stack memory. Each key represents a specific stack usage threshold, and the segment between consecutive keys defines a monitoring zone. This segmentation allows precise measurement of stack occupancy by identifying which segment the current stack pointer resides in, without requiring complex continuous monitoring logic.
Solution Approach 2:
The patent changes the parameter of key distribution from uniform spacing to non-uniform spacing with decreasing memory space intervals between consecutive keys. This parameter change optimizes monitoring precision where it is most needed (in the frequently used lower stack regions) while reducing the number of keys required in less critical areas, thereby balancing precision with complexity.
3Reliability
If standard stack monitoring methods are used with keys at each end of the stack, then stack overflow is detected, but processor resources are excessively consumed and execution is disrupted
Solution Approach 1:
The patent applies partial action by placing keys at selective addresses throughout the stack rather than requiring continuous monitoring or keys at every possible address. The N keys are strategically positioned to provide adequate monitoring coverage with decreasing intervals, using only the necessary number of keys to achieve reliable detection without excessive processor intervention.
Solution Approach 2:
The patent implements periodic monitoring by checking key positions at defined intervals during process execution rather than continuously. The system periodically verifies which keys have been reached by the stack pointer, enabling efficient detection of stack usage patterns while minimizing processor resource consumption compared to continuous monitoring approaches.
Data Source
AI summary
A method for monitoring the free space of a stack of a microcontroller during the execution of a process using spaces of the stack from a start address to an end address of the stack, in which the method includes: in a prior step, writing N keys in the stack at N addresses of the stack, the memory space between two consecutive keys decreasing in a direction from the start address to the end address of the stack; and, in a step of executing the process, saving the address of the current key, corresponding to the address of the existing key, among the N keys, that is closest to the stack start address.


