Embedded Systems & Firmware

On many microcontrollers, what is the advantage of declaring a large table that never changes (such as font data) as const?

  1. AIt is placed in flash memory and does not consume scarce RAM
  2. BThe table contents are automatically compressed
  3. CThe table contents become freely writable at run time
Show answer and explanation

Answer: A. It is placed in flash memory and does not consume scarce RAM

Microcontrollers often have hundreds of KB of flash for programs but only tens of KB of RAM. A non-const initialized array goes in .data and is copied from flash to RAM at start-up, consuming RAM. Declaring it const lets it stay in flash as read-only data and be read from there. Some microcontrollers require a special attribute to place data in flash.

  • A. Correct. RAM is often much smaller than flash.
  • B. Nothing is compressed.
  • C. const means it will not be modified.
Practice this topic Back to topic

More Embedded Systems & Firmware questions

  1. What can be done through debug interfaces such as JTAG and SWD?
  2. You want to run a control calculation every 1 ms on a microcontroller without an OS. Which implementation is most suitable?
  3. What is the role of a microcontroller's brown-out detector (BOD, brown-out reset)?
  4. On a microcontroller with interrupt priorities, a higher-priority interrupt occurs while a lower-priority handler is running. What generally happens (assuming nesting is allowed)?
  5. In C, which statement sets only bit 3 of register reg to 1 without changing the other bits?