Embedded systems and IoT

Stage 1 of 10 · 6 lessons · ~6 weeks

C for embedded

Learn the parts of C that hardware work depends on: exact-width integers, bitwise operations, pointers, volatile and the memory map of a small chip.

Start: Why C still runs the hardware

Lessons· one lesson for each topic, in this order

  1. 1Why C still runs the hardware
  2. 2Fixed-width integer types
  3. 3Bitwise operations and masks
  4. 4Pointers and memory-mapped registers
  5. 5volatile and compiler optimisation
  6. 6Flash, RAM, stack and heap

Do this

  • Write set, clear, toggle and test macros for a bit and use them on a variable.
  • Rewrite an old exercise using only stdint.h types.
  • Trace five pointer snippets on paper, then run them to check.
  • Build a program for your board or a simulator and read its flash and RAM use.
  • Break a program by removing volatile from an interrupt flag with optimisation on, then fix it.

Start with· follow one of these

Practise

  • Compile and run C for a microcontroller in the browser before your board arrives

Keep handy

Also worth your time

Before moving on: A small C program, compiled for your board or a simulator, that sets, clears and tests bits in a variable standing in for a register, uses only stdint types, and prints its memory use from the build output.

Tauseef's advice
Do the bit exercises until they are boring. Every later stage is registers, masks and flags, and people who are shaky here lose days to bugs that are one wrong operator. Compile for a real chip or a simulator from the first week, not only on your laptop.

Mark this stage as not done?