Basic Steps to Develop an Embedded Program, With a Worked Example
The eight steps from requirements to a running microcontroller, shown on one real bare-metal STM32F407 program: register setup, the SysTick reload maths, what the compiler, linker and objcopy produce (with real file sizes), how to read a map file and an Intel HEX line, then flashing, debugging and testing.

Developing an embedded program takes eight steps: write down the requirements, pick a microcontroller that meets them, set up a cross-compiler and debugger, write the code (register setup, initialisation, interrupt handlers and a main loop), build it into a flash image, download it to the chip, debug it on the real hardware, then test and release it. Steps 4 to 8 repeat until the tests pass.
This guide walks through each step with one real program: a bare-metal LED blink for an STM32F407 microcontroller, written without any vendor library. We compiled and linked it on 18 Nov 2026 and took every file size, address and HEX line below from that build. A script kept with this article re-checks each number. It is written for engineering students and freshers in India who know some C and want to see what really happens between typing code and a blinking LED.
Key takeaways
- The build is five tools in a row: preprocessor, compiler, assembler, linker (with a linker script that "locates" code at real addresses) and a converter that writes the HEX or BIN file the programmer flashes.
- Our 51-line
blink.cbecame a 308-byte flash image: a 64-byte vector table, 240 bytes of code and 4 bytes of initial data. It needs 8 bytes of RAM plus the stack (build of 18 Nov 2026).- The .elf file from the same build is 134,560 bytes because it also carries symbols, debug information and padding. Only the 308 bytes go into flash.
- A 1 ms tick on a 16 MHz Cortex-M4 needs a SysTick reload value of 16,000,000 / 1,000 − 1 = 15,999 (Arm's rule: reload = N − 1 for a period of N clock cycles).
- Every line of an Intel HEX file ends with a checksum; all 23 lines of our file pass it, and the first data line holds the initial stack pointer 0x20020000 and reset address 0x08000041.
What are the basic steps to develop an embedded program?
The basic steps are: (1) define requirements, (2) choose the microcontroller and board, (3) set up the toolchain, (4) write the code, (5) build it (compile, assemble, link, locate, convert to HEX/BIN), (6) flash it to the target, (7) debug on hardware and (8) test and release. Building, flashing and debugging repeat many times a day.
The steps look like those of any software project, but three things make embedded work different. The code runs on a different processor from the laptop that builds it, so you need a cross-compiler. The program has no operating system to load it, so you decide where every byte sits in memory. And the "output" is physical: a pin voltage, a motor speed, a message on a CAN bus. You often need an oscilloscope or logic analyser to see whether the code worked. If embedded systems themselves are new to you, start with our explainer on what an embedded system is.
Step 1: How do you write requirements for an embedded program?
Write down, in numbers, what the device must sense, what it must drive, how fast it must react, how much power it may use and what it may cost. A requirement like "blink an LED at 1 Hz with ±1% timing, on mains power" can be tested; "blink an LED" cannot. Each later choice, from chip to code structure, traces back to these numbers.
For our example the requirement list is short:
| Requirement | Value for the blink example |
|---|---|
| Output | Green LED on pin PD12 of an STM32F4 Discovery board |
| Timing | 500 ms on, 500 ms off (1 Hz), from a 1 ms timer tick |
| Clock | 16 MHz internal oscillator (HSI), the chip's default after reset |
| Code style | Bare metal: no vendor library, no RTOS, registers written directly |
| Memory budget | Far below 1 MB flash / 128 KB main RAM |
A real product list is longer: input ranges and sampling rates, communication buses, the worst-case response time, battery life, operating temperature, the safety or EMC standards it must meet, and the unit cost at volume. Get these on paper before you choose a chip. Changing the microcontroller after the PCB is made is expensive.
Step 2: How do you choose a microcontroller?
Choose the smallest, cheapest chip that meets the requirements with margin: enough flash for code (plan for about twice your first estimate), enough RAM for buffers and stack, the right peripherals (timers, ADC, UART, SPI, I2C, CAN), a fast enough clock for the worst case, and good tools and documentation. For learning, pick a board with a built-in debugger.
| Learning board (chip) | Core and clock | On-chip memory |
|---|---|---|
| Arduino Uno (ATmega328P) | 8-bit AVR, 16 MHz | 32 KB flash, 2 KB SRAM, 1 KB EEPROM |
| STM32F4 Discovery (STM32F407VG) | 32-bit Cortex-M4 with FPU, up to 168 MHz | 1 MB flash, 192 KB SRAM (incl. 64 KB CCM) |
| ESP32 DevKit (ESP32) | Dual-core 32-bit Xtensa LX6, up to 240 MHz | 520 KB SRAM, external flash |
| Raspberry Pi Pico 2 (RP2350) | Dual Cortex-M33 or RISC-V, 150 MHz | 520 KB SRAM, 4 MB external flash |
Figures from the Microchip, ST, Espressif and Raspberry Pi datasheets and product pages, checked 18 Nov 2026 (links in Sources).
We use the STM32F407 here because its Discovery board has an ST-LINK debugger built in. It is also a Cortex-M4, a common 32-bit core, so what you learn carries over to many other chips. The same steps apply to an 8-bit AVR or an ESP32; only the register names and the tool names change. For a deeper look at how the core, buses and memories fit together, see embedded systems architecture with worked examples.
Step 3: What tools do you need to develop embedded software?
You need a cross-compiler toolchain (compiler, assembler, linker and object-file tools for the target CPU), an editor or IDE, a debug probe that connects your laptop to the chip (ST-LINK, J-Link or a board's built-in one), and the chip's datasheet and reference manual. Most vendor IDEs bundle all of this for free.
- Toolchain. For Arm Cortex-M the standard is the free Arm GNU Toolchain (
arm-none-eabi-gcc,ld,objcopy,size,gdb). Clang/LLVM can target the same chips; we used Apple clang with LLVM's lld linker for this article's build, and the steps are identical. - IDE. STM32CubeIDE (free; Eclipse with GCC and GDB, for Windows, Linux and macOS), MPLAB X for Microchip parts, ESP-IDF for ESP32, or VS Code with PlatformIO. Keil MDK and IAR are common in industry.
- Debug probe. Arm chips use SWD (Serial Wire Debug), which needs only two signals, SWDIO and SWCLK, instead of the four or more that JTAG uses, and shares pins with JTAG on chips that support both.
- Bench tools. A multimeter, and when timing matters, a logic analyser or oscilloscope.
- Documents. The datasheet (pins, electrical limits), the reference manual (every register) and the board's user manual (which pin the LED is on).
The third bullet decides more than students expect. With a probe you can stop the CPU, step through code and read any variable. Without one you are guessing from LED blinks.
Step 4: What does an embedded C program look like?
An embedded C program has five parts: register and constant definitions, global variables, interrupt service routines, an initialisation function that configures clocks and peripherals once, and a main() that never returns, usually an infinite "super loop". A small startup file runs before main() to set up the stack and memory.
Here is our complete program. Every register address comes from ST's STM32F407 device header and reference manual, and every SysTick detail from Arm's Cortex-M4 user guide.
/* blink.c - bare-metal LED blink for an STM32F407 (STM32F4DISCOVERY green LED on PD12).
* No vendor library: every register address comes from ST's RM0090 reference manual
* and Arm's Cortex-M4 Generic User Guide. Clock: 16 MHz internal HSI (the reset default). */
#include <stdint.h>
/* 1. Register definitions (memory-mapped peripherals) */
#define RCC_AHB1ENR (*(volatile uint32_t *)0x40023830u) /* RCC base 0x40023800 + 0x30 */
#define GPIOD_MODER (*(volatile uint32_t *)0x40020C00u) /* GPIOD base 0x40020C00 + 0x00 */
#define GPIOD_ODR (*(volatile uint32_t *)0x40020C14u) /* GPIOD base + 0x14 */
#define SYST_CSR (*(volatile uint32_t *)0xE000E010u) /* SysTick control and status */
#define SYST_RVR (*(volatile uint32_t *)0xE000E014u) /* SysTick reload value */
#define SYST_CVR (*(volatile uint32_t *)0xE000E018u) /* SysTick current value */
#define CPU_HZ 16000000u /* HSI after reset */
#define TICK_HZ 1000u /* 1 ms tick */
#define LED_PIN 12u /* PD12 */
#define BLINK_MS 500u
/* 2. Global data: one initialised (.data), one zeroed (.bss) */
static volatile uint32_t ms_ticks; /* .bss: written by the ISR */
uint32_t blink_period_ms = BLINK_MS; /* .data: initial value stored in flash, copied to RAM */
/* 3. Interrupt service routine: keep it short */
void SysTick_Handler(void) { ms_ticks++; }
static void delay_ms(uint32_t ms)
{
uint32_t start = ms_ticks;
while ((ms_ticks - start) < ms) { } /* wrap-safe unsigned subtraction */
}
/* 4. Initialisation */
static void board_init(void)
{
RCC_AHB1ENR |= (1u << 3); /* GPIODEN: clock the GPIOD port */
GPIOD_MODER &= ~(3u << (2u * LED_PIN)); /* clear MODER12[1:0] */
GPIOD_MODER |= (1u << (2u * LED_PIN)); /* 01 = general-purpose output */
SYST_RVR = CPU_HZ / TICK_HZ - 1u; /* 15999 -> one interrupt per ms */
SYST_CVR = 0u;
SYST_CSR = (1u << 2) | (1u << 1) | (1u << 0); /* CLKSOURCE=CPU, TICKINT, ENABLE */
}
/* 5. main: init once, then the super loop forever */
int main(void)
{
board_init();
for (;;) {
GPIOD_ODR ^= (1u << LED_PIN); /* toggle the LED */
delay_ms(blink_period_ms);
}
}
Four details in this file are worth understanding before you write your own:
volatiletells the compiler that a value can change outside the normal program flow. Hardware changes registers, and the interrupt changesms_ticks. Without it, the optimiser may readms_ticksonce and loop forever. Our embedded C interview questions cover this and the other keyword traps with tested code.- Read-modify-write.
GPIOD_MODER &= ~(3u << 24)clears only the two mode bits for pin 12 (mask 0x03000000), and|= (1u << 24)sets them to 01, output. The other 15 pins keep their settings. - Clock first. STM32 peripherals are unclocked after reset to save power. Writing bit 3 (GPIODEN) of RCC_AHB1ENR at 0x40023830 turns the GPIOD port on; skip this and the GPIO writes do nothing.
- The ISR is one line. Interrupt handlers should do the minimum and return; the main loop does the rest.
How do you calculate the SysTick reload value?
Divide the timer's clock by the tick rate you want and subtract one: reload = clock / tick rate − 1. At 16 MHz for a 1 ms tick that is 15,999. Arm specifies the subtraction because the counter counts from the reload value down to zero, which is reload + 1 clock cycles per interrupt.
SysTick is a 24-bit counter, so the reload value must lie between 1 and 0xFFFFFF (16,777,215). The longest possible period is therefore : 1.049 s at 16 MHz but only 99.86 ms at 168 MHz. If you later raise the clock to 168 MHz, the same 1 ms tick needs a reload of 167,999, which is why CPU_HZ is a named constant and not a magic number.
What does the startup code do before main()?
On reset, a Cortex-M core reads two words from the start of its vector table: the initial stack pointer, then the address of the reset handler. The reset handler copies initial values of global variables from flash to RAM (.data), fills uninitialised globals with zero (.bss), and only then calls main(). Vendor IDEs generate this file for you.
Our startup.c holds the 16-entry core vector table (64 bytes) with SysTick as entry 15. A production STM32F407 table also lists the chip's 82 peripheral interrupts, which makes it 98 words or 392 bytes. Note the reset address in the table is odd (0x08000041 for a handler at 0x08000040). Bit 0 set to 1 marks Thumb code, and Arm requires it on every vector.
Step 5: What happens when you build an embedded program?
The build turns C into a file the chip can store. The preprocessor expands #include and #define, the compiler turns C into assembly, the assembler makes a relocatable object file, the linker joins all object files and uses a linker script to place each section at a real address (the "locate" step), and objcopy writes the result as Intel HEX or raw binary.
| Step | Command (GNU names) | Output |
|---|---|---|
| Preprocess | gcc -E | .i: C with headers pasted in and macros expanded |
| Compile | gcc -S | .s: Thumb-2 assembly for the Cortex-M4 |
| Assemble | gcc -c (as) | .o: machine code with unresolved addresses |
| Link and locate | ld -T stm32f407.ld | .elf and a .map file with every address |
| Convert | objcopy -O ihex / -O binary | .hex or .bin for the programmer |
The linker script is the step students skip and interviewers ask about. Ours says flash starts at 0x08000000 with 1 MB and main SRAM at 0x20000000 with 128 KB. It puts the vector table first, code and constants after it, and gives .data two addresses: a RAM address where the program uses it and a flash address where its initial value is stored.
How do you read the size and map file?
Add the sections that go into flash (vector table, .text, .rodata and the stored copy of .data) to get flash use, and add .data, .bss and the stack to get RAM use. For our build that is 64 + 240 + 4 = 308 bytes of flash and 4 + 4 = 8 bytes of static RAM, which matches the 308-byte .bin file exactly.
The map file also shows the address of each function: Reset_Handler at 0x08000040, SysTick_Handler at 0x080000A8 and main at 0x080000B8. That is 0.029% of the chip's flash, so the budget is not a concern here. On an ATmega328P with 32 KB of flash and 2 KB of SRAM, reading this report after every build is a habit you need from day one.
We also checked the compiler's output against the source by disassembling main. It loads 0x40023830 and sets bit 3, clears 0x03000000 and sets 0x01000000 in GPIOD_MODER, writes 15,999 to SYST_RVR and 7 to SYST_CSR, then loops on an exclusive-OR of 0x1000 into GPIOD_ODR at 0x40020C14. This is the same check a reviewer does when a register write "doesn't work".
How do you read an Intel HEX file?
Each line of an Intel HEX file is one record: a colon, a byte count, a 16-bit address, a record type (00 data, 01 end of file, 04 upper address, 05 start address), the data bytes and a checksum. The checksum is chosen so that all the record's bytes add up to zero in the lowest 8 bits.
Our file has 23 records: one type-04 record that sets the upper address to 0x0800, 20 data records, one type-05 start address (0x08000041) and the end-of-file record :00000001FF. To check the record in Figure 4 by hand, add its 20 bytes before the checksum. The sum is 0x1D1, the low byte is 0xD1, and 0x100 − 0xD1 = 0x2F, the last byte of the line. Programmers and bootloaders reject any line that fails this test, which is how a corrupted download is caught.
Step 6: How do you load the program onto the microcontroller?
You write the HEX or BIN file into the chip's flash with a programmer. The usual routes are a debug probe over SWD or JTAG, a serial or USB bootloader built into the chip, or, on production lines, a gang programmer. On the STM32F4 Discovery the on-board ST-LINK programs over SWD from STM32CubeIDE or STM32CubeProgrammer.
When the STM32 boots from main flash (BOOT0 pin low), the flash at 0x08000000 also appears at address 0x00000000. That is where the Cortex-M core looks for its vector table on reset, which is why our image is linked at 0x08000000 and still starts correctly. Arduino Uno boards use a different route: a small bootloader (Optiboot) already in the ATmega328P's flash receives your program over the USB-serial link, so no probe is needed.
Step 7: How do you debug embedded code?
Connect the debug probe, start a GDB session (the IDE does this when you click Debug), and stop the CPU at breakpoints to inspect variables and registers. When the bug is about timing or signals rather than logic, measure the pin with a logic analyser or oscilloscope. Printf over a UART or Arm's SWO pin helps when stopping the CPU would hide the bug.
For the blink example the debug checklist is short and typical:
- Does the code reach
main()? Set a breakpoint there. If it never arrives, check the vector table and the reset handler. - Is the GPIOD clock on? Read RCC_AHB1ENR in the register view; bit 3 should be 1.
- Is PD12 an output? GPIOD_MODER bits 25:24 should read 01.
- Is the timing right? Put a logic analyser on PD12 and measure the period. It should be 1.000 s, and any error points to the clock setting, not the code.
One trap: Arm's documentation notes that SysTick stops counting while the processor is halted for debugging. Timing measured while stepping through code means nothing; measure with the CPU running.
Step 8: How do you test and release embedded software?
Test in layers: unit-test the logic on your laptop with a framework such as Unity, run static analysis against a coding standard such as MISRA C, then test the whole board, ideally with hardware-in-the-loop rigs that fake sensors and check outputs automatically. Release with a version number, a checksum or CRC of the image, and the exact toolchain version recorded.
- Unit tests on the host. Keep hardware access behind small functions so the logic (filters, state machines, protocol parsers) compiles and runs on a PC. Unity, a test framework in pure C, runs both on a PC and on an 8-bit target.
- Static analysis and coding rules. MISRA C, used widely in automotive work, published its current edition, MISRA C:2025, in March 2025. Checkers flag undefined behaviour and risky constructs before they reach hardware.
- Integration and hardware-in-the-loop (HIL) tests. The real board, with simulated inputs, checked against the Step 1 requirements.
- Release. Tag the source, archive the .elf (you need its symbols to debug field returns), store the image checksum, and document how to reproduce the build.
Safety-critical products add a formal process on top, for example ISO 26262 for road vehicles, with traceability from every requirement to its code and tests. The steps stay the same; the evidence required at each one grows.
Which mistakes do beginners make most often?
The most common beginner mistakes are forgetting to enable a peripheral's clock, leaving out volatile on variables shared with interrupts, doing slow work inside an ISR, and treating the .elf size as the flash size. Others are getting a reload or prescaler off by one, and never reading the size report until the chip runs out of memory.
| Symptom | Likely cause |
|---|---|
| GPIO writes do nothing | Peripheral clock not enabled in RCC |
| Delay loop never ends at -O2 | Shared variable not volatile |
| Timing 0.006% slow | Reload set to 16,000 instead of 15,999 |
| Crash before main() | Bad vector table or linker script addresses |
| Random resets under load | Stack overflow into .bss, or watchdog not serviced |
The off-by-one row is real arithmetic: a reload of 16,000 gives 16,001 cycles per tick instead of 16,000, so every tick is 1/16,000 = 0.00625% long, about 5.4 s a day for a clock built on it.
Where do these skills lead, and how can you learn them?
These eight steps are the daily work of an embedded software engineer. In Skill-Lync's placement records, 278 learners placed in embedded roles had a median starting offer of ₹4.0 LPA, with the middle half between ₹3.5 and ₹5.0 LPA. Cyient and Nexteer Automotive were the most frequent hirers in that group.
Those figures are based on 3,711 Skill-Lync placement records up to 7 Nov 2026 (data snapshot of 15 Nov 2026). They are a self-selected sample of our learners who reported a placement, mostly early-career offers from 2021 to 2023, so treat them as a starting point, not a market survey. Our embedded engineer salary page has more detail.
To practise the steps with feedback, Skill-Lync's Embedded Programming Essentials starts with C for embedded work, including the compilation process and preprocessor in week 3. Fundamentals of Embedded Systems (12 weeks) moves on to microcontroller architecture, GPIO, timers, interrupts and serial protocols. Compare all options on our embedded systems courses page, revise the theory in the free microcontrollers book, or talk to a Skill-Lync counsellor about which fits your branch and year. For a gentler start with more peripheral examples (UART baud rates, ADC, debouncing), read our embedded software guide for beginners.
Frequently asked questions
Which language is best for embedded programming?
C is still the main language for microcontroller firmware because it gives direct register access, predictable code size and compilers for almost every chip. C++ is common on larger 32-bit parts, MicroPython suits quick prototypes on boards like the ESP32 and Pico, and Rust is growing. Assembly is used only for small startup or timing-critical pieces.
Is embedded C different from normal C?
Embedded C is standard C used under hardware constraints, not a separate language. The differences are in how you use it: memory-mapped registers through volatile pointers, fixed-width types such as uint32_t, bit manipulation, interrupt handlers, no operating system underneath, and usually no dynamic memory allocation. The compiler is a cross-compiler for the target chip.
What is the difference between a compiler and a cross-compiler?
A native compiler produces code for the machine it runs on, such as a laptop compiling a laptop program. A cross-compiler runs on one machine and produces code for a different processor. Embedded work uses cross-compilers, for example arm-none-eabi-gcc running on an x86 or Apple laptop to build Thumb-2 code for a Cortex-M microcontroller.
What is the difference between a HEX file and a BIN file?
A BIN file is a raw copy of the flash contents with no addresses, so the programmer must be told where it starts. A HEX file is text: each line carries its own address, record type and checksum. In our build the BIN was 308 bytes and the HEX 927 bytes for the same image.
Can I learn embedded programming with Arduino?
Yes, Arduino is a good first step for wiring and simple logic, but its libraries hide the steps this article covers: registers, clocks, the linker and startup code. Once you are comfortable, write one program on the same ATmega328P without the Arduino functions, or move to an STM32 board and program the registers directly.
Do I need an RTOS for my embedded program?
Not for simple devices. A super loop with interrupts, like our blink program, handles many products. Consider an RTOS such as FreeRTOS or Zephyr when you have several independent jobs with different deadlines, for example a motor control loop, a communication stack and a user interface, that become hard to schedule by hand.
Sources and further reading
- Arm, Cortex-M4 Devices Generic User Guide (ARM DUI 0553B): SysTick registers and reload rule, vector table, Thumb bit. Accessed 18 Nov 2026.
- STMicroelectronics, STM32F407 CMSIS device header (stm32f407xx.h) and system_stm32f4xx.c: peripheral base addresses, register offsets, 16 MHz HSI default. Accessed 18 Nov 2026.
- STMicroelectronics, RM0090 reference manual (boot configuration) and STM32F407VG product page.
- STMicroelectronics, UM1472 Discovery kit user manual: LD4 green LED on PD12.
- Microchip, ATmega328P datasheet; Espressif, ESP32 Series datasheet; Raspberry Pi, Pico 2 product page.
- Optiboot project, Optiboot serial bootloader (default on the Arduino Uno).
- Microchip, Intel HEX file specification: record types and checksum.
- Arm, Arm GNU Toolchain downloads; STMicroelectronics, STM32CubeIDE user guide (UM2609); SEGGER, SWD target interface.
- ThrowTheSwitch, Unity test framework; MISRA, MISRA C; ISO, ISO 26262-1:2018.
- Skill-Lync placement records, snapshot of 15 Nov 2026 (3,711 records up to 7 Nov 2026; embedded domain n = 278).


