Embedded Systems & Firmware

On a small microcontroller without an MMU, what should be kept in mind about excessive stack use?

  1. AThe stack grows automatically without limit, so there is nothing to worry about
  2. BA stack overflow always shows an error screen
  3. CStack overflow may not be detected immediately and can silently corrupt neighboring data, so avoid deep recursion and large local arrays and estimate usage
Show answer and explanation

Answer: C. Stack overflow may not be detected immediately and can silently corrupt neighboring data, so avoid deep recursion and large local arrays and estimate usage

A PC OS places a no-access page beyond the stack to detect overflow, but microcontrollers without an MMU often lack that mechanism, and an overflowing stack silently overwrites whatever variables lie beyond it. The symptoms appear elsewhere, making the cause hard to track down. Developers avoid deep recursion and large local arrays, estimate maximum usage with tools, or write a marker pattern at the stack's end and check whether it has been overwritten.

  • A. Stack size is limited.
  • B. There is no mechanism to display an error screen.
  • C. Correct. It tends to cause mysterious bugs.
Practice this topic Back to topic

More Embedded Systems & Firmware questions

  1. A 12-bit A/D converter with a 3.3 V reference reads a value of 2048. What is the closest input voltage?
  2. When a microcontroller captures many A/D conversion results at regular intervals, what is the advantage of using DMA?
  3. When representing peripheral registers with C bit-field structs, what needs care?
  4. On many microcontrollers, what is the advantage of declaring a large table that never changes (such as font data) as const?
  5. What can be done through debug interfaces such as JTAG and SWD?