UNIT 03 · FOUNDATIONS
Processors and Memory
What the chip does with every address.
Unit 2 treated memory as a row of numbered bytes and a peripheral as a pointer. This unit opens the chip and shows what answers those addresses: a processor core that fetches and executes instructions, buses that decode each address into one memory or one register block, flash that can only be erased a sector at a time, SRAM that forgets everything at power-off, and a clock and reset system that decides when any of it starts. Knowing this is the difference between code that happens to work and code whose timing, memory use and start-up behaviour you can predict.
The unit in six ideas
- 1A microcontroller is a processor core, program memory, data memory, peripherals, interconnect, clock and reset, and debug logic on one chip.
- 2The core repeats fetch, decode, execute; the program counter holds the address of the next instruction and branches work by writing it.
- 3A bus transfer is an address, control signals and data; slaves can insert wait states or return an error.
- 4SRAM is fast, freely writable and volatile; flash is nonvolatile, reads fast, and writes in a slow erase-then-program cycle.
- 5Static objects live in
.data(initial values copied from flash) or.bss(zeroed); constants stay in flash; locals live on the stack;mallocblocks on the heap. - 6Clock frequency sets the length of every cycle; RC oscillators start fast but drift, crystals are accurate, PLLs multiply a reference up.
Lessons
What Is Inside a Microcontroller?
When it executes count = count + 1, which of those rectangles actually take part, and what are the other twenty-seven for?
Instructions, Registers, and the CPU
How does that tiny vocabulary add up to every program you will write, and why is an if really about the flags left behind by the previous instruction?
Buses and Address Spaces
What is that something, and what does it do when two parts of the chip want the same memory in the same clock cycle?
Flash, RAM, and Nonvolatile Memory
What is the rule, and how do you store a setting that must survive ten years of power cycles when each piece of flash can only be rewritten a few thousand times?
The Stack, the Heap, and Static Storage
Where exactly do local variables, globals and malloc blocks live on a microcontroller, and how do you know the stack is big enough?
Clocks, Reset, and Execution
What do they do, and what can firmware count on?