8 Must‑Know Embedded Interview Questions and How to Ace Them
This article presents eight high‑frequency embedded‑system interview questions, explains the underlying concepts such as boot process, interrupt handling, stack overflow detection, struct alignment, bit‑banding, dynamic memory risks, volatile usage, and provides concise C code examples and best‑practice answers to help candidates succeed in technical interviews.
Question 1: How does the CPU load code from Flash and start execution?
Interview focus
Understanding the embedded system boot process
Proficiency with linker scripts (.ld files)
Standard answer
After power‑up, the CPU reads the stack pointer (SP) and program counter (PC) from a fixed address (usually 0x00000000).
According to the .text section defined in the linker script, code is copied from Flash to RAM (if required).
The .data section (initialized globals) and the .bss section (zero‑initialized globals) are initialized.
Finally, execution jumps to main().
Bonus answer: In STM32, SystemInit() configures the clock before main() runs.
Question 2: Why shouldn’t an ISR call printf ?
Interview focus
Understanding of re‑entrant functions and interrupt context
Standard answer
printf is not re‑entrant: it uses static buffers, causing data corruption when called from multiple contexts.
Long execution time: it may block higher‑priority interrupts.
Potential deadlock: printf may invoke system calls that are disabled in interrupt context.
Correct practice: Set a flag in the ISR and handle the output in the main loop, or use an RTOS message queue.
Question 3: How to detect stack overflow in C?
Interview focus
Practical experience with memory management
Standard answer
Method 1 – Magic number:
#define STACK_MAGIC 0xDEADBEEF
uint32_t stack_sentinel = STACK_MAGIC;
void check_stack() {
if (stack_sentinel != STACK_MAGIC) {
printf("Stack Overflow!");
}
}Method 2 – MPU protection: Configure a memory‑protection unit region at the stack boundary to generate an exception on overflow.
Bonus: FreeRTOS provides uxTaskGetStackHighWaterMark() to check peak stack usage.
Question 4: Impact of struct alignment in embedded systems
Interview focus
Understanding memory access efficiency
Standard answer
Performance impact: Unaligned 32‑bit accesses on Cortex‑M0/M3 cause multiple memory operations.
Hardware constraints: Some DMA controllers require 4‑ or 8‑byte alignment.
Memory savings: Using #pragma pack(1) removes padding, reducing size at the cost of speed.
Example:
struct __attribute__((packed)) SensorData {
uint8_t id; // 1 byte
uint32_t value; // 4 bytes (no 3‑byte padding)
};Question 5: What is “bit‑banding” and how to implement it in C?
Interview focus
Knowledge of ARM‑specific features
Standard answer
ARM Cortex‑M provides alias addresses that allow individual bit access without affecting other bits in the same byte.
Implementation:
#define BITBAND(addr, bit) (0x42000000 + ((uint32_t)(addr)-0x40000000)*32 + (bit)*4)
*(volatile uint32_t *)BITBAND(&GPIOA->ODR, 1) = 1; // Set PA1 onlyQuestion 6: Why avoid dynamic memory allocation in embedded systems?
Interview focus
Understanding real‑time system stability
Standard answer
Fragmentation: Long‑running systems may run out of contiguous memory.
Non‑deterministic timing: malloc/free execution time is unpredictable.
Safety risk: Allocation failure can crash the system.
Alternatives: Use static memory pools or object‑pool patterns (e.g., CAN message buffers).
Question 7: Role of the volatile keyword in the given code
Interview focus
Depth of understanding compiler optimizations
Standard answer
Prevents optimization: Guarantees each access reads/writes the actual hardware register.
Disables reordering: Preserves the order of operations as written.
Typical use cases:
Hardware registers
Shared variables in multithreaded code
Globals modified by interrupts
Common mistake: Assuming volatile provides atomicity – it does not.
Question 8: How to implement a lightweight memory pool in C?
Interview focus
Ability to implement memory‑management algorithms
Standard answer
Core idea: Pre‑allocate a large block, manage free blocks with a linked list or bitmap, allocate by removing a node, and free by inserting it back.
Code framework:
typedef struct {
void *start_addr;
uint16_t block_size;
uint16_t total_blocks;
uint8_t *mem_map; // bitmap of usage
} mem_pool_t;
void mem_pool_init(mem_pool_t *pool);
void *mem_pool_alloc(mem_pool_t *pool);
void mem_pool_free(mem_pool_t *pool, void *ptr);Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
