Multiple choice questions, fill-in-the-blank exercises, true/false, and interview preparation questions covering all Module 1 concepts.
20
MCQ Questions
10
Fill in Blanks
15
Interview Q&A
10
True / False
Score Tracker
0 Correct
0 Wrong
0 Attempted
Section 1: Multiple Choice Questions
1. Which of the following best describes an embedded system?
Correct! An embedded system is a dedicated computer system designed to perform one or a few specific functions, often with real-time computing constraints, embedded within a larger system.
2. What is the base address of the Flash memory on STM32F407?
Correct! Flash memory on STM32F407 starts at 0x08000000. SRAM1 starts at 0x20000000 and peripherals start at 0x40000000.
3. Why is the volatile keyword required for hardware peripheral register pointers?
Correct!volatile tells the compiler that the value can change at any time (by hardware), so it must not cache it in a CPU register. Every read/write must go to the actual memory address.
4. What is the size of uint32_t on ARM Cortex-M4?
Correct!uint32_t is always exactly 4 bytes (32 bits) on any platform. This guaranteed size is why we use fixed-width types instead of unsigned int in embedded code.
5. To SET bit 3 of a 32-bit register variable reg, which operation is correct?
Correct! OR-assignment (|=) sets the specified bit without affecting others. AND with complement (&= ~) clears a bit. XOR-assignment (^=) toggles a bit.
6. What is the main difference between a Microcontroller (MCU) and a Microprocessor (MPU)?
Correct! An MCU (like STM32F407) integrates the CPU core, Flash, SRAM, and peripherals (GPIO, UART, SPI, etc.) on a single chip. An MPU (like Raspberry Pi’s BCM2837) is just the processing core and needs external RAM and storage.
7. Which C header file provides uint8_t, uint16_t, and uint32_t?
Correct!<stdint.h> (C99 standard) defines all fixed-width integer types. Always include this header at the top of every embedded C file.
8. What does the startup file do before calling main() on an STM32?
Correct! The Reset_Handler (startup code) copies initialized global variables (.data) from Flash to SRAM, zero-initializes uninitialized globals (.bss), then calls main().
9. To CLEAR bit 7 of register reg, which operation is correct?
Correct! AND with bitwise NOT clears the target bit while leaving all others unchanged. ~(1U << 7) creates a mask with all bits 1 except bit 7.
10. The STM32F407 has how much Flash memory?
Correct! STM32F407VGT6 has 1 MB Flash (0x08000000 to 0x080FFFFF), 192 KB SRAM total (112 KB SRAM1 + 16 KB SRAM2 + 64 KB CCM), and runs at up to 168 MHz.
11. What is the ARM Cortex-M4 CPU core clock speed of the STM32F407?
Correct! STM32F407 runs at up to 168 MHz. It also includes a DSP unit and floating-point unit (FPU) making it suitable for signal processing tasks.
12. Where in memory are uninitialized global variables stored on an MCU?
Correct! Uninitialized (or zero-initialized) globals go into the .bss section in SRAM. The startup code zeros this region before calling main(). Initialized globals go to .data in SRAM (copied from Flash at startup).
13. Which bus does GPIOA connect to on STM32F407?
Correct! All GPIO ports (A through K) on STM32F407 are connected to the AHB1 bus. Their clocks are enabled through the RCC_AHB1ENR register.
14. What does const uint32_t * const ptr mean?
Correct! Read right to left: ptr is const (pointer is fixed), pointing to uint32_t that is const (data cannot change). Use this for pointers to Flash lookup tables.
15. Which GCC optimization flag disables all optimizations (best for debugging)?
Correct! -O0 disables all optimizations, preserving the code as written. This makes debugging easier since variables are not optimized away. -O2 and -O3 are common for production releases.
Section 2: Fill in the Blanks
Type your answer and click Check to reveal the correct answer.
2. To toggle bit 4 of a register, use: reg ____= (1U << 4);
Answer: ^ (XOR). reg ^= (1U << 4) toggles bit 4.
3. The keyword that prevents compiler optimization of a hardware register variable is:
Answer: volatile — forces every read/write to go to the actual memory address.
4. The startup code zeros the section in SRAM before calling main().
Answer: .bss — contains uninitialized global and static variables; zeroed at startup per C standard.
5. RCC_AHB1ENR register address on STM32F407 is
Answer: 0x40023830 — RCC base is 0x40023800, AHB1ENR is at offset 0x30.
6. An MCU integrates CPU, , SRAM, and peripherals on a single chip.
Answer: Flash — MCU = CPU + Flash + SRAM + Peripherals, all on one chip.
7. GPIOA Mode Register (MODER) offset from GPIOA base address is
Answer: 0x00 — MODER is the first register in the GPIO register map at offset 0x00.
8. To read bit 2 of register reg, use: (reg >> ___) & 1U
Answer: 2 — shift right by the bit position, then AND with 1 to isolate that bit.
9. The C standard header that provides fixed-width types is <.h>
Answer: stdint — <stdint.h> is part of the C99 standard and provides uint8_t, uint16_t, uint32_t, etc.
10. On ARM Cortex-M4, a pointer variable itself is bytes wide.
Answer: 4 — on a 32-bit processor, all pointers are 4 bytes (32-bit addresses). On 64-bit systems pointers are 8 bytes.
Section 3: True or False
1. On ARM Cortex-M4, the long data type is always 8 bytes.
2. A peripheral register on STM32F407 must be accessed through a volatile pointer to prevent compiler optimizations.
3. The GPIOA Output Data Register (ODR) is at offset 0x14 from the GPIOA base address.
4. In embedded C, main() should return when the application is done.
5. uint8_t is always exactly 1 byte on every platform.
6. Before accessing a GPIO peripheral on STM32F407, its clock must be enabled in RCC.
7. An embedded system can have more than one microcontroller.
8. Dynamic memory allocation with malloc() is the recommended practice in embedded C.
9. The Cortex-M4 processor has a built-in floating-point unit (FPU).
10. C code is the preferred language for embedded systems because it compiles to efficient machine code and gives direct hardware access.
Section 4: Interview Questions and Answers
Click “Show Answer” to reveal a detailed model answer. Practice articulating these out loud.
Q1: What is the difference between an MCU and an MPU? When would you choose one over the other?+
Model Answer:
An MCU (Microcontroller Unit) integrates a CPU core, Flash memory, SRAM, and peripherals (GPIO, UART, SPI, I2C, ADC, timers, etc.) all on a single silicon die. Examples: STM32F407, PIC32, AVR ATmega.
An MPU (Microprocessor Unit) contains only the CPU core (and possibly cache). It requires external RAM (DDR), external storage (SD card/eMMC), and often an OS. Examples: Raspberry Pi’s BCM2837, TI AM335x (BeagleBone).
Choose MCU when: Real-time control, low power, simple application, no OS needed, cost-sensitive, small form factor (washing machine controller, drone ESC, automotive ECU).
Choose MPU when: Complex OS (Linux/Android), large memory needed, multimedia processing, running databases or web servers (router, smartphone, industrial HMI).
Q2: Why do we use fixed-width types like uint32_t instead of unsigned int in embedded C?+
Model Answer:
The C standard does not specify the exact size of int, long, etc. — only minimum sizes. On a 32-bit ARM, int is 4 bytes, but on an 8-bit AVR it may be 2 bytes.
In embedded systems, we often interact directly with hardware registers that have exact sizes (e.g., a 32-bit peripheral register). Using unsigned int to access a 32-bit register could silently fail on a different architecture.
uint32_t from <stdint.h> is guaranteed to be exactly 32 bits on every platform. This makes code portable and predictable — critical when bit-banging hardware registers, implementing communication protocols, or writing to memory-mapped I/O.
Q3: Explain what volatile does and give three real use cases in embedded C.+
Model Answer:
volatile is a type qualifier that instructs the compiler: “Do not cache this variable in a register — always read from or write to its actual memory address.” It prevents the compiler from optimizing away reads/writes that it considers redundant.
Three real use cases:
Hardware peripheral registers: A UART status register changes when data arrives. Without volatile, a polling loop would be optimized away.
ISR shared variables: A flag set in an Interrupt Service Routine and checked in main(). Without volatile, main() may cache the old value and never see the ISR update.
RTOS task shared variables: Two tasks sharing a flag variable. Without volatile, one task’s cached copy may never see updates from the other.
Q4: How do you set, clear, toggle, and read a specific bit in a hardware register?+
Model Answer:
For bit position n in register reg:
/* SET bit n */ reg |= (1U << n);
/* CLEAR bit n */ reg &= ~(1U << n);
/* TOGGLE bit n*/ reg ^= (1U << n);
/* READ bit n */ uint8_t bit_val = (reg >> n) & 1U;
The 1U (unsigned 1) ensures the shift is done on an unsigned type, avoiding undefined behavior from signed integer overflow. The bit mask approach touches only the target bit, leaving all other bits unchanged — essential for hardware registers where other bits control different functions.
Q5: What is the STM32F407 memory map? Name the three main regions.+
Model Answer:
STM32F407 has a 4 GB (32-bit) address space. The three main regions are:
Flash (Code) — 0x08000000: 1 MB non-volatile storage for your program code and read-only data. This is where your .text and .rodata sections reside.
SRAM — 0x20000000: 192 KB total (112 KB SRAM1 + 16 KB SRAM2 + 64 KB CCM). Stores stack, heap, .data, and .bss sections. Volatile — loses content on power loss.
Peripheral — 0x40000000: Memory-mapped I/O registers for all peripherals (GPIO, UART, SPI, I2C, TIM, ADC, etc.). Accessing these addresses talks directly to hardware.
Q6: Why should embedded C programs avoid dynamic memory allocation (malloc)?+
Model Answer:
Four key reasons to avoid malloc() in embedded systems:
Heap fragmentation: Repeated malloc/free creates holes in heap memory. Over time, there may be enough total free memory but no single contiguous block large enough for a new allocation.
Non-deterministic timing: malloc() execution time is not fixed. Real-time systems require deterministic response times.
No MMU: Most MCUs lack a Memory Management Unit. A heap overflow silently corrupts adjacent memory with no OS protection.
Limited SRAM: STM32F407 has 192 KB SRAM total. Heap management overhead and fragmentation waste precious memory.
Use static arrays, global buffers, or stack-allocated variables instead.
Q7: What is the role of the startup file in an STM32 project?+
Model Answer:
The startup file (e.g., startup_stm32f407xx.s) is an assembly file that executes on reset before main(). Its responsibilities:
Vector table: Places the initial stack pointer and Reset_Handler address at the start of Flash (0x08000000). The hardware reads these on reset.
Stack initialization: Sets up the Main Stack Pointer (MSP).
.data copy: Copies initialized global variables from Flash (load address) to SRAM (run address).
.bss zero: Zeroes the .bss section so uninitialized globals start at 0 (as required by C standard).
Calls main(): Transfers control to your C program.
Safety trap: If main() returns, spins in an infinite loop to prevent undefined behavior.
Q8: What is the difference between const uint32_t *p and uint32_t * const p?+
Model Answer:
const uint32_t *p — pointer to const data. The pointer itself can change (point to a different address), but you cannot modify the value at the address through this pointer. Used for read-only data parameters in functions: void func(const uint8_t *buf) tells callers “I won’t modify your data.”
uint32_t * const p — const pointer to non-const data. The pointer address is fixed (cannot be reassigned), but the data it points to can be modified. Used for a pointer that is permanently bound to one hardware register address.
Memory aid: read right to left. In uint32_t * const p, the first const encountered reading right-to-left applies to p (the pointer). In const uint32_t *p, const applies to uint32_t (the data).
Q9: Why do we need to enable the peripheral clock before using a GPIO on STM32?+
Model Answer:
STM32 microcontrollers use clock gating to minimize power consumption. Each peripheral has its clock disabled by default at reset. If you try to write to a GPIO register without enabling its clock first, the write has no effect — the peripheral is essentially powered off.
The Reset and Clock Control (RCC) peripheral manages all peripheral clocks. To enable GPIOA, you set bit 0 (GPIOAEN) in the RCC_AHB1ENR register. Only then can you configure and use GPIOA registers.
This is the most common beginner bug on STM32: configuring GPIO pins but forgetting to enable the RCC clock first, resulting in no output/input activity with no error message.
Q10: How do you write a struct that maps to a hardware peripheral’s registers?+
Model Answer:
Create a struct where each member corresponds to a register, in the exact order they appear in the hardware’s register map. All members must be volatile to prevent compiler optimization. Member sizes must match register widths (uint32_t for 32-bit registers).
The struct works because the compiler lays out members consecutively in memory with no padding (for same-sized uint32_t members). Cast the base address to a pointer of this struct type, and all member accesses automatically hit the correct register offsets. This is exactly how CMSIS device header files work.
Q11: What is the difference between .data and .bss memory sections?+
Model Answer:
.data section: Contains global and static variables that have non-zero initial values. Example: int counter = 10;. Initial values are stored in Flash at link time. On startup, the Reset_Handler copies them from Flash to SRAM so the variable can be modified at runtime.
.bss section: Contains global and static variables with zero or no initial value. Example: int counter; or int counter = 0;. No initial values are stored in Flash (it would be wasteful to store all zeros). Instead, startup code just zeroes out this SRAM region. BSS stands for “Block Started by Symbol”.
Key difference: .data uses Flash space (to store initial values) and SRAM. .bss uses only SRAM and saves Flash space since zeros don’t need to be stored explicitly.
Q12: What does the suffix U mean in 1U << 5 and why is it important?+
Model Answer:
The U suffix makes the integer literal unsigned. Without it, 1 is a signed int. Shifting a signed integer left into the sign bit causes undefined behavior in C.
For example, 1 << 31 is undefined behavior (shifting into sign bit of a 32-bit int), but 1U << 31 is well-defined (sets bit 31 of an unsigned int).
In embedded code, always use 1U (or 1UL for 64-bit shifts) in bit manipulation macros to avoid subtle bugs with signed overflow, especially when working with 32-bit registers where all 32 bits are valid.
Q13: Name five characteristics of embedded systems.+
Model Answer:
Single-function focus: Designed for one specific task (e.g., engine control, temperature regulation).
Real-time operation: Must respond to events within strict time deadlines.
Resource constrained: Limited CPU speed, Flash (code storage), and SRAM (working memory).
Reliability and stability: Often runs for years without restart; must be fault-tolerant.
Power efficiency: Battery-powered or power-sensitive deployments require careful power management.
Additional characteristics: small physical size, low cost per unit, direct hardware interaction, harsh environment operation.
Q14: What is CMSIS and why is it useful?+
Model Answer:
CMSIS (Cortex Microcontroller Software Interface Standard) is an ARM standard that provides a hardware abstraction layer for all Cortex-M processor families. It includes:
Device header files (stm32f407xx.h) with struct-based register definitions, base addresses, and bit-field macros — exactly the struct pointer pattern we wrote manually.
Core peripheral access (SysTick, NVIC, MPU, FPU) through standardized functions.
Compiler intrinsics for instructions like __NOP(), __WFI(), __enable_irq().
Without CMSIS, every vendor would use different naming conventions. With CMSIS, code structure is consistent across ST, NXP, Microchip (Atmel), and other ARM vendors, improving portability and readability.
Q15: Walk me through the complete sequence of what happens when you power on an STM32F407.+
Model Answer:
Power-on reset: Hardware resets all registers to default values.
Boot mode selection: Hardware samples BOOT0/BOOT1 pins to decide boot source (Flash, system memory, or SRAM).
Vector table read: Hardware reads the initial Stack Pointer value from address 0x08000000 and the Reset_Handler address from 0x08000004.
Stack pointer set: MSP is loaded with the value from the vector table.
Reset_Handler called: Execution jumps to Reset_Handler in the startup file.
.data copy: Startup code copies initialized globals from Flash to SRAM.
.bss zeroed: Startup code zeros uninitialized globals in SRAM.
SystemInit() called: (optional) Configures system clock speed.
main() called: Your C application begins execution.
Super-loop runs: Application runs forever in while(1).
Lesson 1.1 Complete!
You have finished the quiz for Module 1 Lesson 1.1. Move on to Lesson 1.2 to set up STM32CubeIDE and flash your first program to the board.
2 Comments