5.5.1 · HinglishEmbedded Systems & Real-Time Software

Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

2,317 words11 min readRead in English

5.5.1 · Coding › Embedded Systems & Real-Time Software


YEH family exist kyun karti hai?

Ek chip ki jagah ek family kyun? Kyunki embedded needs bahut bade range mein hoti hain:

  • Ek $0.20 sensor jo sirf ek pin toggle karta hai → sabse sasta, lowest-power core chahiye (M0).
  • Ek motor controller jo 20 kHz par PID math karta hai → fast multiply + shayad floating point chahiye (M4).
  • Ek camera pipeline jo FFTs karta hai → caches aur high clock chahiye (M7).

Ek core sab ke liye optimal nahi ho sakta, isliye ARM inhe segment karta hai.


Char cores ek nazar mein

Core Pipeline Architecture DSP (SIMD) FPU Cache/MPU Typical clock
M0/M0+ 2-stage ARMv6-M optional MPU ~48 MHz
M3 3-stage ARMv7-M MPU ~72–120 MHz
M4 3-stage ARMv7E-M SIMD/DSP optional single-precision MPU ~100–180 MHz
M7 6-stage, dual-issue ARMv7E-M optional single +double I/D caches, MPU ~300–600 MHz
Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

Architecture kaisi bani hai (first principles)

1. Harvard-ish bus aur pipeline

Ek CPU yeh karta hai: instruction Fetch karo → usse Decode karo → usse Execute karo. Agar ek-ek karke kiya jaye, to har instruction 3 clock cycles leti hai. Ek pipeline inhe assembly line ki tarah overlap karta hai.

M7 mein 6th stage + dual-issue kyun add kiya? Do wajah hain:

  1. Har stage mein chhoti logic → chip ko zyada ooncha clock kiya ja sakta hai (zyada MHz).
  2. Dual-issue (superscalar): har cycle mein do instructions fetch/decode karo → 1 se zyada ho sakta hai.

2. Interrupt machine: NVIC + exception model

Real-time ke liye Cortex-M ki defining feature hai NVIC (Nested Vectored Interrupt Controller).

3. Do stacks, do modes

Cortex-M mein MSP (Main Stack Pointer) aur PSP (Process Stack Pointer) hote hain, saath mein Handler mode (interrupts) vs Thread mode (normal code). Do stacks kyun? Taaki ek RTOS har task ko uska apna PSP stack de sake jabki interrupts shared MSP use karein — ek task ke stack mein crash hone par kernel ka stack corrupt nahi hoga.

4. Memory-mapped sab kuch

Koi special I/O instructions nahi hain. Ek GPIO register ek fixed address par rehta hai jaise 0x40020000. Tum ise normal load/store se read/write karte ho. Kyun? Simplicity + ek uniform addressing model = simpler core = lower power.


Worked examples


Common mistakes (Steel-man + fix)


Recall Feynman: ek 12-saal ke bacche ko explain karo

Char robots imagine karo jo sab ek hi simple instruction cards padhte hain.

  • M0 ek chhota sasta robot hai — yeh ek ek card padhta hai, slow lekin almost zero power pita hai.
  • M3 thoda smarter hai aur ek chhote conveyor belt par cards padhta hai to kabhi wait nahi karta.
  • M4 ke haath mein ek calculator bana hua hai — yeh bade numbers instantly multiply kar sakta hai (music/sound robots ke liye great).
  • M7 bada wala hai: yeh ek saath do cards padhta hai, super fast chalta hai, aur abhi use ki hui cheezein ek chhoti notebook mein rakhta hai (ek cache) taaki shelf par wapas na daudna pade. Woh trick jo sab share karte hain: jab koi "emergency!" chillaata hai (ek interrupt), woh instantly ek bookmark drop karte hain (registers save karte hain) aur ek ekdam same time mein, har baar — woh "har baar same" hi wajah hai ki yeh rockets aur pacemakers chalate hain.

Flashcards

Sab Cortex-M cores kaun sa instruction set execute karte hain?
Thumb / Thumb-2 (16- aur 32-bit mixed encoding) — koi full 32-bit ARM (A32) state nahi hoti.
NVIC interrupt par kitne registers auto-stack karta hai, aur kaun se?
8 — R0–R3, R12, LR, PC, xPSR.
Cortex-M interrupt latency ko "deterministic" kyun kehte hain?
Stacking + vector lookup ek fixed, jaane-pehchane cycle count (~12 cyc) lete hain, isliye worst-case latency bounded aur calculable hai.
NVIC mein "vectored" ka matlab kya hai?
Har interrupt ka vector table mein apna slot hota hai, isliye CPU software dispatch loop ke bina seedha uske handler par jump karta hai.
M0 vs M7 pipeline depth?
M0/M0+ = 2-stage; M7 = 6-stage aur dual-issue (superscalar).
M4 FPU ka bada trap kya hai?
Yeh sirf single-precision hai; double math slow software emulation par fall back karti hai.
Hardware mein double-precision FP kaun sa Cortex-M kar sakta hai?
M7 (optional double-precision FPU); M4F sirf single-precision hai.
M4 ko M3 se numerically kaun si feature alag banati hai?
DSP/SIMD instructions (jaise SMLAD) aur ek optional single-precision FPU.
N-stage pipeline se I instructions run karne ke cycles ka formula (koi stalls nahi)?
(N − 1) + I.
Do stack pointers (MSP/PSP) kyun?
RTOS ko har task ka stack (PSP) kernel/interrupt stack (MSP) se isolate karne deta hai safety ke liye.
Real-time ke liye M0+, M7 se behtar kyun ho sakta hai?
Shallow pipeline + koi cache nahi → kam timing jitter; M7 cache misses timing ko data-dependent bana deti hain.
Cortex-M par peripheral register tak kaise pahuncho?
Memory-mapped: ek fixed address par normal load/store (koi special I/O instructions nahi).
FPU enable karne wala register kaun sa hai, aur bhool gaye to kya hota hai?
CPACR (CP10/CP11 set karo); FP instructions warna HardFault ki tarah trap ho jaati hain.
M7 ko caches ke bawajood guaranteed timing kaun si memory deti hai?
TCM (Tightly-Coupled Memory).

Connections

Concept Map

designed for

segmented into

cheapest core

balanced control

numeric crunch

high throughput

adds pipeline + Thumb-2

adds DSP SIMD + FPU

adds caches + dual-issue

2-stage pipeline

6-stage superscalar

gives ideal

shorter stages

Cortex-M family

Low-power deterministic embedded

Range of needs

M0 / M0+

M3

M4

M7

Pipelining

IPC to 1 per clock

Higher clock MHz