PERSONAL - Embedded Systems and Security

Microcontroller Basics

CPU Architecture Characteristics

File Types

62985c99c840ce88fd01c2aab4a14593.webp

Pulse Width Modulation

100% duty cycle
████████████████████
--------------------> time

50% duty cycle
████____████____████
--------------------> time

20% duty cycle
██______██______██__
--------------------> time
100% duty cycle
████████████████████
--------------------> time

50% duty cycle
████____████____████
--------------------> time

20% duty cycle
██______██______██__
--------------------> time

Cortex M4

Instruction & Data flow Interrupt & Multitasking Debugging Protection
3-stage pipeline
Floating point unit (FPU)
Internal Bus Interconnect
NVIC
SysTick
WIC
Breakpoint unit
Watchpoint unit
Software trace
Instruction trace interface
ETM
Trace interface
Debug interface
MPU

f2a95ad724c3aef17b6fef12129f0649.webp

Circuitry Basics

b57490e8d32376263b1ca6752bbb254e.webp

Component What it is What it does Role in the circuit
+ (Input) Power source connection Supplies raw voltage (e.g. battery) Main energy source
C_IN Input Capacitor Smooths input voltage, filters noise, provides quick energy Stabilizes power right at the entrance
L1 Inductor (coil) Stores energy in magnetic field, resists sudden current changes Key part of voltage conversion (switching regulator)
D1 Diode One-way valve for current Prevents reverse current flow
C_OUT Output Capacitor Smooths output voltage Delivers clean, stable VCC
VCC Regulated power output Clean power rail Powers the microcontroller and other components
Q1 N-channel MOSFET Electronic switch controlled by its Gate Turns power to the load on/off
GND Ground (0V) Common reference point Return path for all current

Embedded Communication Standards

Protocol Year Topology Typical Wires Typical Speed Best For Complexity Typical Distance
I²C 1982 Bus SCL, SDA (+GND) 100 kHz, 400 kHz, 1 MHz, 3.4 MHz Sensors, EEPROMs, simple peripherals Low ≈ 3 m
I²S 1986 Point-to-Point SCK, WS, SD (+GND) Audio clock dependent Digital audio Low ≈ 10 m
SPI Late 1980s Star (master-slave) SCLK, MOSI, MISO, SS (+GND) High (application-dependent) High-speed peripherals, displays, flash memory Low ≈ 10 m
UART Before 1971 Point-to-Point TXD, RXD (+GND) Medium (baud-rate dependent) Simple device-to-device communication Very Low ≈ 10 m
RS-232 1962 Point-to-Point TXD, RXD (+GND) Up to 115.2 kbps (commonly 9.6–115.2 kbps) Legacy serial devices, industrial equipment Low ≈ 1 km @ 9.6 kbps; ≈ 100 m @ 115.2 kbps
CAN 1986 Bus CAN_H, CAN_L Up to 1 Mbps (distance-dependent) Automotive and industrial networks Medium 500 m @ 125 kbps; 40 m @ 1 Mbps
USB 1996 Tiered Star D+, D−, VBUS, GND (USB 2.0) Very High (1.5 Mbps–80 Gbps depending on version) General-purpose peripherals High 3–5 m (without active repeaters)

Universal Serial Bus (USB)

  1. detect device and speed
  2. read device descriptor
  3. assign address
  4. select configuration
  5. read interface descriptor
  6. load driver

Khattak & Koopman Code Review Checklist

Category Review Focus Example Questions
Function Correctness and functionality Does the code meet requirements? Does each function perform a single task? Are variables initialized before use?
Style Readability and maintainability Are naming conventions followed? Are comments accurate? Are magic numbers avoided? Is dead code removed?
Architecture Overall software design Is coupling minimized? Is cohesion high? Are functions appropriately sized? Are global variables minimized?
Interfaces Module interactions Are parameters validated? Are return values checked? Is error handling consistent? Are interfaces clearly defined?
Logic Control flow and algorithms Are conditional statements correct? Are loops well-formed? Is recursion justified? Is unreachable code eliminated?
Data Data structures and memory Are arrays bounds-checked? Are pointers used safely? Is integer overflow considered? Is memory initialized correctly?
Timing Real-time behavior Are deadlines met? Is worst-case execution time acceptable? Are blocking calls minimized? Are interrupt interactions safe?
Reliability & Safety Robustness and fault tolerance Are failures handled gracefully? Are assertions used appropriately? Is defensive programming employed? Does the system fail safely?

Attacking UART, JTAG

Port Type Typical Access Gained Difficulty Common Security Status
4-pin UART Root shell on Linux (often passwordless) Very easy Frequently left open
14-pin JTAG Full debug access, memory dump, firmware extraction Easy–Medium Often left enabled

Attacking ICs

IBM Attacker Taxonomy

Interrupts and Exceptions

b1a1837d2a53f2894775d49f5cc6caf9.webp

Cortex M4 Interrupt Handling

  1. store registers on stack (in this order!): PC, xPSR, r0-r3, r12, LR
    • PC will be overwritten as soon as possible, which is why it's stored first
  2. load handler address into PC (indexed by interrupt number)
  3. switch to privileged mode
  4. update interrupt number in IPSR
  5. store where to return to in LR: another interrupt (nested) or standard program + mode (user / privileged)

cce0062b0d94f6118c22847b4f266c96.webp

Types of Interrupts

Level Triggered Interrupt Line:

Low  ________________________
     |                      |
High |                      |__________

CPU sees interrupt pending the entire time.
Level Triggered Interrupt Line:

Low  ________________________
     |                      |
High |                      |__________

CPU sees interrupt pending the entire time.
Edge Triggered Interrupt Line:

Low  ________        __________
              |      |
High          |______|

              ^
          Interrupt!
Edge Triggered Interrupt Line:

Low  ________        __________
              |      |
High          |______|

              ^
          Interrupt!
Feature Level-triggered Edge-triggered
Trigger condition Signal remains at a level Signal changes state
Repeated if uncleared? Yes No
Shared IRQ support Excellent More difficult
Risk of missing interrupt Low Higher if edge isn't latched
Driver responsibility Must clear interrupt source Handle event before next edge
Polling Interrupts
CPU checks device repeatedly Device notifies CPU
Can waste CPU cycles CPU works on other tasks until needed
Simple to implement Requires interrupt hardware and ISR support
Response time depends on polling frequency Usually responds almost immediately
Predictable timing Less predictable due to asynchronous events

Exercises

Symbol Meaning
T_{event}TeventT_{event} Average time between events
DDD Deadline after the event
t_{proc}tproct_{proc} Time needed to process the event (subroutine duration)
t_{poll}tpollt_{poll} Time for one poll
t_{latency}tlatencyt_{latency} Interrupt latency (time between outside event and start of subroutine)
t_{switch}tswitcht_{switch} Context-switch time

Exceptions

Boot Sequence

  1. power-up, hardware reset: power-on reset and other reset events occur, hardware initializes clock sources and latches boot mode selection pins
  2. CPU executes BootROM code: startup software (SSW) runs first and performs essential initializations (clock system setup, memory initialization and protection), checks reset causes
  3. boot mode selection: normal boot (user application in Flash), BSL (bootstrap loader for Flash programming via UART / CAN; code loaded into PSRAM), PSRAM boot (run code already in PSRAM)...
  4. application startup: transfer control to user application or BSL loader; application sets up own vector table, stack pointer, clocks, peripherals...

Memory

Memory Management

ef719f4e0d17a78437e61156f4b471ad.webp

870114e590e82e0be451efe03b8859e2.webp

Sections

Section Variable Type
data initialized global
bss uninitialized global
heap dynamically allocated
stack local
Power off
    ↓
FLASH                      SRAM
+------------------+       +------------------+
| counter = 5      |       |      garbage     |
+------------------+       +------------------+

Power on / Reset
    ↓
Startup code runs before main()

memcpy(.data in FLASH → .data in SRAM)
memset(.bss, 0)

FLASH                      SRAM
+------------------+       +------------------+
| counter = 5      | ----> | counter = 5      |
+------------------+       +------------------+

main() starts
Power off
    ↓
FLASH                      SRAM
+------------------+       +------------------+
| counter = 5      |       |      garbage     |
+------------------+       +------------------+

Power on / Reset
    ↓
Startup code runs before main()

memcpy(.data in FLASH → .data in SRAM)
memset(.bss, 0)

FLASH                      SRAM
+------------------+       +------------------+
| counter = 5      | ----> | counter = 5      |
+------------------+       +------------------+

main() starts

Stack Frame

1484130c9407fb06e54a5d7c743ace72.webp

MPU Configuration

Security Services (Assets) and Cryptography

Symmetric Cryptography

1e95ac2fcd975d3e1353ed6f492d1752.webp

Symmetric Encryption Message Authentication Code
Confidentiality ✅ ❌
Integrity ❌ ✅
Authenticity ✅ ✅
Non-Repudiation ❌ ❌

Asymmetric Cryptography

Cryptographic Hash Functions

Asymmetric Encryption Digital Signatures
Confidentiality ✅ ❌
Integrity ❌ ✅
Authenticity ❌ ✅
Non-Repudiation ❌ ✅

Confusion and Diffusion

Memory Encryption

244b1a80a571d0aac6ff4fdab5a07a51.webp
4e937cea08a026840ed4e8b12b5759ad.webp
e79e022110955d355a2d566f1d179b12.webp

Side Channel Attacks

Advanced Encryption Standard (AES)

Trusted Computing

Device Identifier Composition Engine (DICE)

dfb0555c9f1cea7b42474e39d99f86c0.webp

Trusted Platform Module (TPM)

Concept of Separation

Software Separation

Hardware Separation (TrustZone)

Summary by Flavius Schmidt, ge83pux, 2026.
https://flaviusschmidt.com