Embedded C for Microcontrollers

The parts of C that decide whether firmware works: types, memory, registers, interrupts and testing

Go beyond the basics of firmware and learn the C that small targets demand: integer promotion and undefined behaviour, memory placement and linker sections, safe register access, interrupt-safe data sharing, robust driver design, MISRA-style defensive coding, and testing and debugging on the host and the target.

Intermediate · 5 modules · 18 lessons · free certificate

About this course

Most firmware bugs are not exotic. They come from an integer that was promoted when nobody expected it, a register write that cleared the wrong flag, a variable shared with an interrupt without protection, or a driver that waits forever for hardware that never answers. Each of these follows directly from rules of the C language or the hardware that a desktop programmer rarely meets. This course explains those rules, shows what goes wrong when they are ignored, and gives patterns that hold up in shipped products.

We use Arm Cortex-M microcontrollers and the GCC toolchain as the concrete reference, because they are widely used and well documented, and we point out where 8-bit and 16-bit parts or other compilers behave differently. Code examples are short and written as plain text so they can be read on any screen. Each module ends with a five-question quiz that checks reasoning rather than memory.

The course assumes you already know what Embedded Firmware Fundamentals covers: microcontroller organisation, the toolchain and startup code, basic peripherals and interrupts. It does not cover task scheduling and kernel objects, which belong in RTOS Fundamentals, nor C++, Rust, Linux drivers or boot security, which is covered in Secure Boot and Firmware Updates.

Before you start: Working knowledge of C, including pointers, structs, bitwise operators and the preprocessor. Familiarity with the material in Embedded Firmware Fundamentals, or equivalent experience of building and flashing firmware for a microcontroller.

What you will learn

  • Predict the result of mixed-type integer expressions and recognise undefined and implementation-defined behaviour
  • Explain where each variable and constant lives in flash and RAM, and read a size report and map file
  • Access memory-mapped registers safely, including write-one-to-clear and set or clear registers
  • Share data between interrupts and main code with correct atomicity, critical sections and ring buffers
  • Structure drivers as encapsulated, non-blocking modules with clear error handling
  • Apply warnings, static analysis, MISRA-style rules, host unit tests and on-target debugging tools

Who it is for

  • Firmware engineers with a year or two of experience who want to close gaps in their C
  • Desktop or application programmers moving onto microcontrollers who already know C syntax
  • Hardware engineers who write bring-up and test firmware and want it to be robust
  • Technical leads who review firmware and set coding standards for a team

Syllabus

Module 1: C on Small Targets

Integer sizes, promotion, conversions and the behaviour the C standard leaves undefined or up to the compiler.

  1. Integer Sizes and Fixed-Width Types
  2. Integer Promotion and the Usual Arithmetic Conversions
  3. Undefined, Unspecified and Implementation-Defined Behaviour
  4. sizeof, Alignment, Padding and Endianness
  5. Module quiz (5 questions)

Module 2: Memory: Where Data Lives

Stack, static and heap storage, why dynamic allocation is often avoided, and how linker sections place code and data in flash and RAM.

  1. Stack, Static Storage and the Heap
  2. Why Dynamic Allocation Is Often Avoided
  3. Linker Sections, const and Flash Placement
  4. Module quiz (5 questions)

Module 3: Talking to Hardware from C

volatile and its limits, memory-mapped registers, CMSIS-style access, bitfields versus masks, and registers with special write rules.

  1. volatile in Depth and Its Limits
  2. Memory-Mapped Registers and CMSIS-Style Access
  3. Bitfields Versus Masks and Shifts
  4. Read-Modify-Write Hazards and Special Registers
  5. Module quiz (5 questions)

Module 4: Interrupts and Concurrency in C

Writing interrupt handlers that are short and safe, making shared data access atomic, using barriers where they matter, and building a lock-free ring buffer.

  1. Writing Interrupt Handlers in C
  2. Atomicity, Critical Sections and Memory Barriers
  3. Ring Buffers Between Interrupts and Main Code
  4. Module quiz (5 questions)

Module 5: Robust Modules, Standards and Testing

Encapsulated drivers with opaque handles and clear error handling, non-blocking state machines, defensive coding with warnings, static analysis and MISRA C, and testing and debugging on host and target.

  1. Encapsulation, Opaque Handles and Error Handling
  2. State Machines and Non-Blocking Drivers
  3. Defensive Coding: Warnings, Static Analysis, MISRA C and Asserts
  4. Testing and Debugging on the Host and the Target
  5. Module quiz (5 questions)

Free downloads for this course

Enrol for free

Discuss your project

Email support@aavico.com or use Get in Touch when the website finishes loading.