What a microcontroller is
The one chip that runs your program, and where the program and its variables live.
Read this first
An embedded system is a computer built into a product to do one job: a washing machine controller, a bike light, a thermostat, a drone. It has no screen or keyboard of its own, it starts the moment power arrives, and it runs the same program for years.
The computer inside is usually a microcontroller, often written MCU. One chip holds the processor core, the memory and the peripherals (the parts that talk to the outside world: pins, timers, serial ports, analog inputs). Popular families for learning are the ARM Cortex-M chips (STM32, nRF52, RP2040), the AVR chips in classic Arduino boards, and the ESP32.
Two kinds of memory matter from day one. Flash keeps your program and your constants, and it keeps them when the power is off. RAM holds the variables your program changes while it runs, and it holds nothing useful at power up until the startup code fills it in. Flash is bigger, RAM is faster, and both are small: a beginner board may have 256 KB of flash and 32 KB of RAM, hundreds of thousands of times less than a laptop.
On Cortex-M chips the big regions are fixed by ARM, and you will meet them in every debugger: the low addresses are for code, RAM starts at 0x20000000, and the peripherals start at 0x40000000. Where exactly the flash sits inside the code region is up to the chip maker: 0x08000000 on STM32, 0x10000000 on the RP2040, 0x00000000 on nRF52. A pointer value tells you what kind of memory it points at just from its first digits.
When the chip starts, a little startup code copies the initial values of your initialised global variables from flash into RAM, sets the globals that have no initial value to zero, and then calls main(). Everything else in RAM is left as it is. Local variables of a function live on the stack, a region of RAM that grows and shrinks as functions are called and return. Then your main() runs a loop that never ends. There is no operating system to return to.
To remember
- An MCU is processor, memory and peripherals on one chip.
- Flash keeps the program across power cycles. RAM holds the variables and holds nothing useful at power up.
- On Cortex-M, RAM starts at 0x20000000 and peripherals at 0x40000000.
- Globals with an initial value live in RAM and get their value copied from flash at startup. Locals live on the stack.
- main() runs a loop forever. There is nothing to return to.
Check what you read
3 questions from the question bank on the ideas above. Each one comes with an explanation after you answer.
Sign in to answer the questions. Your answers count towards your level.
Sign inThe lesson text and the project are free to read without an account.
Build this
Blink the on-board LED
You need
- One development board. Good first choices: Raspberry Pi Pico, an STM32 Nucleo-64, an Arduino Uno, or an ESP32 dev kit. The Pico, a Nucleo-64 and an ESP32 kit each cost under 20 USD. An official Uno is about 27 USD, clones are under 10.
- A USB cable that carries data, not only power.
- The free tools for that board: the Arduino IDE works for all four, or STM32CubeIDE for Nucleo, or the Pico SDK for the Pico.
Steps
- Install the tools and plug the board in. Make sure the computer sees it.
- Open the blink example that ships with the tools, build it and load it onto the board.
- Change the on and off times to 100 ms and load it again. Then change them to 1000 ms.
- Find in the code the line that turns the LED on. Comment it out, load again and watch what happens.
Done when
The on-board LED blinks at a speed you chose, and you changed the program and loaded it at least three times.