Embedded Interview Prep Flashcards

(47 cards)

1
Q

What is the difference between a microcontroller and a microprocessor?

A

An MCU integrates CPU, memory, and peripherals on one chip for dedicated control (e.g. ATmega328P, STM32F4). An MPU is just a CPU core requiring external memory and I/O, optimized for high-performance OS tasks (e.g. Intel Core i7, ARM Cortex‑A).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Key differences between polling and interrupt-driven I/O? When prefer each?

A

Polling repeatedly checks a flag—simple but wasteful. Interrupts signal events—more efficient, lower latency. Use polling for tight-loop or simple tasks; use interrupts when events are sparse or real-time response is needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the role of a watchdog timer in embedded systems.

A

A watchdog is a hardware timer that resets the system if not periodically kicked by firmware. It recovers from hangs or deadlocks, ensuring reliability in unattended devices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are memory-mapped I/O and port-mapped I/O? Describe differences.

A

MMIO shares the CPU’s address space for peripherals accessed like RAM. Port-mapped I/O uses a separate I/O space with special instructions (e.g. x86 IN/OUT). MMIO is common in MCUs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Purpose of using volatile variables in embedded C? Example.

A

volatile prevents compiler optimizations on variables changed outside program flow (e.g. hardware registers or ISR flags). Example: volatile uint8_t dataReady; set in ADC ISR.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is debouncing and why is it necessary?

A

Mechanical switches bounce, generating multiple transitions. Debouncing filters noise via hardware RC or software delay/state machine so one press equals one event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Difference between hard real-time and soft real-time systems? Examples.

A

Hard RTOS must meet deadlines 100% (e.g. airbag controller). Soft RTOS allows occasional misses with performance penalty (e.g. multimedia). Hard uses tighter scheduling guarantees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is DMA and how does it improve performance? Use case.

A

DMA transfers data between memory and peripherals without CPU, freeing CPU for tasks and reducing latency. E.g. streaming ADC samples into RAM while CPU processes previous buffer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Difference between cooperative and preemptive multitasking? Advantages/disadvantages.

A

Cooperative: tasks yield control voluntarily—simple, low overhead, but one task can block others. Preemptive: scheduler interrupts tasks—better responsiveness, but adds context-switch overhead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Common causes of stack overflow and how to prevent or detect it?

A

Deep recursion, large local arrays, unbounded interrupts. Prevent via static analysis, limit recursion/buffer sizes, measure via stack canaries or fill with pattern to check watermark.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does an interrupt vector table work?

A

A fixed-address array of function pointers. On interrupt, CPU indexes the table, fetches ISR address, and jumps. It centralizes and maps interrupts to handlers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Difference between static and dynamic memory allocation? Trade-offs.

A

Static is deterministic with no fragmentation—preferred in MCUs. Dynamic (malloc/free) is flexible but risky (fragmentation, unpredictable latency)—use pools or avoid in tight systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are race conditions and how to prevent them?

A

Race conditions occur when concurrent contexts access shared data unsafely. Prevent with mutexes, disabling interrupts, atomic ops. E.g. ISR and main both updating a multi-byte counter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is memory alignment and why important?

A

Alignment places data on natural boundaries (e.g. 4‑byte on 4‑byte boundary). Misaligned access can cause slow or fault on some architectures—always align data structures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain priority inversion and how to handle it.

A

Low‑priority holds a mutex, medium preempts, high waits—low never runs. Mitigate via priority inheritance or ceiling protocols to boost low’s priority temporarily.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Difference between a bootloader and firmware? Roles during startup.

A

Bootloader initializes hardware, verifies/updates and loads firmware. Firmware is the main application. Bootloader runs first, then jumps to firmware entry.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Difference between bare‑metal programming and using an RTOS?

A

Bare‑metal has no OS—low overhead, full control, manual scheduling. RTOS provides tasks, IPC, timers—faster development but adds footprint and switching overhead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Role of an RTOS scheduler? Round‑robin vs priority‑based.

A

Scheduler picks the next ready task. Round‑robin cycles same‑priority tasks equally. Priority‑based runs highest‑priority ready task, preempting lower ones.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Ensure data consistency between ISR and main program?

A

Use volatile, disable interrupts during shared access, atomic operations, or lock-free buffers. Example: ring buffer for UART RX.

20
Q

What is a memory leak and why is it problematic?

A

Memory allocated but never freed accumulates until OOM—critical in small RAM. Detect via heap tracing, guard blocks. Prevent with pools or avoid dynamic alloc.

21
Q

Key considerations for low‑power design? Techniques.

A

Minimize active time, sleep modes, clock gating, voltage/frequency scaling, batch I/O, DMA usage, wake on interrupt, optimize code paths.

22
Q

Difference between ISR latency and execution time? Importance.

A

Latency is time to start ISR after event; execution time is duration ISR runs. Latency affects responsiveness; execution time impacts scheduling and interrupt blocking.

23
Q

Typical stages in embedded software lifecycle?

A

Requirements → design → implementation → testing → integration → deployment → maintenance. Ensures reliability and traceability.

24
Q

How handle clock drift? Clock synchronization techniques.

A

Crystal calibration, periodic NTP/PTP, external RTC modules, GPS reference, temperature‑compensated oscillators.

25
Purpose of linker script? Influence on memory layout.
Maps sections to addresses, sets vector location, reserves regions. Controls code/data placement in Flash and RAM.
26
Difference between ROM, RAM, Flash? Uses in MCU.
ROM: mask‑programmed code. Flash: erasable non‑volatile for firmware. RAM: volatile for stack/heap/variables.
27
Purpose of double buffering? Benefits.
Two buffers alternate between fill and process/use phases—prevents tearing, ensures continuous data flow (graphics, ADC).
28
What is a circular buffer and how implement? Use cases.
Fixed array with head/tail indices modulo length. Ideal for producer/consumer FIFO (UART, streaming data) with constant-time ops.
29
Differences between SPI, I²C, and UART? Selection criteria.
UART: async point-to-point. I²C: 2‑wire multi-master, addressing, slower. SPI: 4‑wire full-duplex, high-speed, needs CS per device.
30
Role of a HAL? Portability benefits.
Abstracts hardware into APIs, enabling same firmware across MCU families by swapping HAL implementations.
31
Edge-triggered vs level-triggered interrupts? Scenarios.
Edge triggers on transition—use for single events. Level triggers while signal active—use for conditions requiring repeated servicing.
32
Advantages/disadvantages of cooperative vs preemptive multitasking.
See #9.
33
Key factors when choosing an RTOS?
Footprint, licensing, scheduling, APIs, memory, latency, power management, peripheral/driver support, tooling, community/commercial backing.
34
Implement inter-task communication? Mechanisms.
Queues/message buffers for data transfer, semaphores for signaling, mutexes for mutual exclusion with priority inheritance.
35
What is a memory barrier and why important?
Enforces ordering of memory operations to prevent compiler/hardware reordering that breaks synchronization in concurrent contexts.
36
Purpose of mutexes vs binary semaphores?
Mutex: ownership and priority inheritance for resource protection. Binary semaphore: simple flag, no ownership/inheritance.
37
What is cache coherency and why important?
Ensures all processors/DMA see latest data; without it caches can hold stale data leading to corruption; requires maintenance protocols.
38
Steps to bring up a custom board with new MCU?
Power-up, clock setup, pin muxing, debug console, memory test, peripheral init, bootloader verify, smoke test hardware features.
39
Function of MPU vs MMU?
MPU offers region-based access control (no virtual memory). MMU provides virtual memory with paging, caching, and protection.
40
Fixed-point vs floating-point arithmetic? Trade-offs.
Fixed-point: deterministic, fast on no-FPU MCUs, smaller code. Floating-point: easier math, but slower, larger; use FP when FPU available or precision critical.
41
Implications of global variables in concurrency/ISR? Safety.
Globals risk data races. Protect via `volatile`, disable interrupts, atomic ops or mutexes; minimize scope and document usage.
42
How measure or estimate stack usage and why critical?
Use linker maps, stack canaries, fill stack with pattern and measure watermark to prevent overflow in limited RAM.
43
Role of a startup file and tasks before `main()`?
Sets stack pointer, clears BSS, copies data section from Flash to RAM, configures clocks and memory, then calls `main()`.
44
What is interrupt nesting and control mechanisms?
Allow higher-priority ISRs to preempt lower. Managed via interrupt priorities and CPU interrupt-enable registers.
45
Role of vector table in Cortex-M and configuration?
Defines ISR addresses at fixed base (default 0x00000000). VTOR can relocate it to RAM/Flash for dynamic ISR mapping.
46
Typical sources of jitter and how minimize?
Sources: interrupt latency, OS scheduling, bus contention, clock drift. Minimize: reduce ISR times, use DMA, prioritize, hardware timers, optimize software.
47
Typical steps to bring up custom hardware board with a new microcontroller?
Power-up checks, clock config, pin muxing, debug console, memory integrity tests, peripheral init, bootloader operation, smoke tests.