5.5.1 · D1 · HinglishEmbedded Systems & Real-Time Software

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

3,309 words15 min read↑ Read in English

5.5.1 · D1 · Coding › Embedded Systems & Real-Time Software › Microcontroller architecture — ARM Cortex-M series (M0, M3,

Parent note ARM Cortex-M Series padhne se pehle, us mein aane wale har word aur symbol ko samajhna zaroori hai. Hum har ek cheez ko zero se build karenge, ek aisi order mein jahan har idea apne pehle wale idea par lean karta hai.


1. Bit, byte, aur "32-bit"

Imagine karo: 8 light switches ki ek row hai. Har switch ek bit hai; poori row ek byte hai. ON/OFF switches ka pattern hi stored number hai.

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

"32-bit" kyun? Jab parent kehta hai Cortex-M ek 32-bit core hai, toh matlab hai ki CPU ke basic "haath" — registers jisme woh math karta hai, aur addresses jinhein woh point karta hai — 32 wires wide hain. Isse milta hai:


2. Hexadecimal — 0x40020000 padhna

Embedded code hex kyun pasand karta hai? Kyunki ek hex digit exactly 4 bits ke barabar hai. Toh do hex digits = 1 byte, aur 8 hex digits = 32 bits. 0x40020000 jaisa address 32 bits ka compact representation hai.

Sawaal: hex number 0x40020000 kitne bits represent karta hai?
8 hex digits × 4 bits = 32 bits.

3. Memory ek badi numbered street ki tarah

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

Topic ko yeh kyun chahiye: parent kehta hai ki peripherals memory-mapped hote hain — ek GPIO control register 0x40020000 par "rehta hai". Matlab is street par ek specific ghar memory cell se nahi balki ek physical pin controller se wired hai. Us ghar mein number likhne se hardware toggle ho jaata hai. Dekho Memory-mapped I/O and GPIO.


3b. Multi-byte values: endianness aur alignment

Ek single ghar ek byte hold karta hai. Lekin ek 32-bit value ko chaar ghar row mein chahiye. Do low-level rules decide karte hain ki woh chaar bytes kaise baithenge — aur galat karna har load aur store corrupt kar deta hai.

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

Yeh kyun matter karta hai: jab tum koi peripheral register ya memory mein koi value padhte ho, toh CPU bytes ko is order ke hisaab se reassemble karta hai. Agar tumne galat order assume kiya (maan lo kisi big-endian device ke saath data share kar rahe ho), toh number scrambled nikal aata hai. Isliye "little-endian" ek aisi fact hai jo tumhare paas har memory-mapped I/O discussion mein honi chahiye.

Recall Little-endian Cortex-M par, ek word ka least-significant byte kahan jaata hai?

Chaar gharon mein se lowest address mein.


4. Registers — CPU ki jebein

Imagine karo: agar memory sheher ke paar ek warehouse hai, toh registers tumhari jeb mein rakhi kuch cheezein hain — turant reach ho sakti hain, lekin sirf mutthi bhar hain. CPU sirf registers mein baithe values par math kar sakta hai, isliye kaam ek constant shuttle hai: memory se load karo → registers mein compute karo → wapas store karo.

Named registers jo parent list karta hai (aur jinhe tumhein pehchanana hai):

Naam Seedha matlab
R0R12 data ke liye general-purpose jebein
PC (Program Counter) chalane wali agli instruction ka address
LR (Link Register) "return address" — function ke baad wapas kahan jaana hai
xPSR status flags (kya last result zero tha? negative? etc.)
MSP / PSP do alag Stack Pointers (dekho §7)
Recall CPU directly memory par compute kyun nahi kar sakta?

Kyunki arithmetic hardware sirf registers se wired hai. Memory sirf explicit load/store steps ke through reach hoti hai — yeh simplicity core ko small aur low-power rakhti hai.


5. Instruction, aur Fetch–Decode–Execute rhythm

CPU ek teen-beat rhythm forever repeat karta hai:

  1. Fetch — memory se agli instruction padhna (PC ka address use karke).
  2. Decode — yeh pata lagana ki iska matlab kya hai.
  3. Execute — actually woh karna.
Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

Topic ko yeh kyun chahiye: agar har instruction teeno beats ka wait karti, toh ek instruction = 3 clock ticks. Pipeline (parent §1) inhe ek assembly line ki tarah overlap karta hai — yeh rhythm exactly woh hai jise ek pipeline speed up karti hai. Dekho Pipelining and superscalar execution.


6. Thumb / Thumb-2 — woh language jo CPU bolti hai

Yahan chhota kyun matter karta hai: embedded chips mein tiny memories hoti hain. Chhoti encoding matlab zyada program same flash mein fit hoga, aur fetching mein kam bytes lagte hain. RISC (Reduced Instruction Set Computer) ka matlab hai vocabulary deliberately chhoti aur regular hai — build karna simple, pipeline karna aasaan.


7. Stack, aur do kyun hain

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

Pehle, ek hardware term jis par hum aage lean karenge:

Topic ko yeh kyun chahiye: jab interrupt fire hota hai, toh CPU ko tumhare current registers stack par push karne chahiye taaki baad mein restore kar sake — yeh "automatic stacking" woh hai jo NVIC karta hai. Aur functions apna return address (LR) aur locals yahan push karte hain.

DO stacks (MSP + PSP) kyun? Taaki ek normal task ka scratch pile (PSP) interrupt/kernel pile (MSP) se alag rahe. Agar ek task apna stack overflow kar de, toh woh kernel wale ko nahi tod sakta. Yeh split RTOS isolation power karta hai — dekho RTOS task scheduling and context switching.


8. Interrupt — kandhe par thapki

Imagine karo: tum ek kitaab padh rahe ho (main program). Doorbell baji (interrupt). Tumne page bookmark kiya (registers push kiye), darwaza khola (handler run kiya), phir wapas apni exact line par aa gaye (registers pop kiye). Bookmark hi §7 wala stack push hai.

Yeh real-time define kyun karta hai: Cortex-M ka poora selling point yeh hai ki yeh "darwaza kholne" wala time bounded aur knowable hai. Woh controller NVIC hai jo upar define hua — dekho Interrupts and the NVIC.


9. Number types: integer, fixed-point, floating-point

Agla paragraph padhne se pehle, ek control-loop term jo parent use karta hai:


10. Cache aur TCM — fast vs predictable memory

Dono kyun hain: cache average par fast hai lekin ek "miss" slow hota hai, isliye timing unpredictable ho jaati hai — hard deadlines ke liye bura. TCM size ke badle guaranteed timing deta hai. Yahi tension M7 story hai: Cache vs TCM in real-time systems.


Prerequisite map

bit and byte

hexadecimal 0x

32-bit registers

memory addresses

endianness and alignment

memory-mapped IO

load and store

instructions

fetch decode execute

clock cycles

pipeline throughput

the stack MSP PSP

interrupts and NVIC

integer fixed float FPU

MAC SIMD DSP

cache vs TCM

Cortex-M topic

Har arrow ka matlab hai "right box samajhne ke liye left box zaroori hai." Notice karo ki sab kuch ek single Cortex-M topic node mein funnel hota hai — woh hi parent page hai.


Equipment checklist

Right side cover karo aur parent note padhne se pehle har ek ka jawab do.

Ek "byte" mein kitne bits hote hain, aur kitne patterns ho sakte hain?
8 bits, jisse patterns milte hain.
0x prefix ka kya matlab hai aur ek hex digit kitne bits encode karta hai?
0x ek hexadecimal number mark karta hai; har hex digit exactly 4 bits encode karta hai.
Ek 32-bit CPU har peripheral ko apna address kyun de sakta hai?
Kyunki billion addresses exist karte hain — name karne ke liye peripherals se kahin zyada.
Peripheral kya hota hai?
CPU ke aas-paas koi bhi controllable hardware block (timer, serial port, ADC, GPIO), jo CPU ko read/write slots ke set ki tarah dikhta hai.
Cortex-M cores by default kaunsa byte order use karte hain?
Little-endian — least-significant byte lowest address par hota hai.
Ek 32-bit word ke liye alignment rule kya hai, aur M0+ par todne par kya hota hai?
Word ek aisi address par shuru honi chahiye jo 4 se divisible ho; M0/M0+ par unaligned access HardFault raise karta hai.
Register aur memory mein kya fark hai?
Registers CPU ke andar kuch ultra-fast slots hain jahan math hota hai; memory ek badi, slower numbered street hai jise load/store se reach kiya jaata hai.
CPU ke rhythm ke teen beats bolo.
Fetch, Decode, Execute.
Clock cycle kya hai, aur kaam cycles mein kyun measure karte hain?
CPU metronome ki ek tick; cycles × tick-time = real time, isliye cycles se hum cores ko clock speed se independent compare kar sakte hain.
Stack kya hai, aur push/pop kya karte hain?
Memory ka ek last-in-first-out scratch pile; push ek value upar add karta hai, pop upar ki value hataata hai.
Cortex-M mein do stack pointers (MSP aur PSP) kyun hain?
Task scratch space (PSP) ko kernel/interrupt scratch space (MSP) se isolate karne ke liye, taaki ek task ka overflow kernel corrupt na kar sake.
NVIC kya karta hai?
Interrupts manage karta hai — priority ordering, nesting, aur handler par jump karne se pehle automatic register stacking.
MPU kya karta hai?
Memory regions ko read-only / no-execute / off-limits mark karta hai aur violations par fault karta hai, task isolation enforce karta hai.
Interrupt kya hai, aur jitter kya hai?
Ek hardware "abhi handle karo" signal; jitter woh hai ki response time events ke beech kitna vary karta hai.
Integer, fixed-point, aur floating-point define karo.
Integer = whole number; fixed-point = ek fixed imaginary decimal point wala integer; floating-point = fraction plus ek movable exponent-scale.
PID kya hai aur isse fast fractional math kyun chahiye?
Proportional–Integral–Derivative control; yeh errors ko fractional gains se multiply karta hai, isliye isse fast float ya fixed-point math chahiye.
Cache fast kyun hai lekin hard real-time ke liye bura kyun hai, aur iska solution kya hai?
Cache hit fast hota hai lekin miss slow hota hai, timing data-dependent ho jaati hai; TCM iske badle fixed-time access deta hai.

Agla step: yeh vocabulary pocket mein leke parent Cortex-M Series padho aur har symbol pehle se earned hoga.