P14 · Embedded C/C++ for Microcontrollers · Lesson 1 of 1

Study guide — what to focus on

~15 min

Slide 1

How to use this module

This module is curated — the teaching is a top free university course (linked in the card above); our job is to point you at the right things, make you practice them, and certify you.

The plan

  1. Take the course (the card above — pick Audit the course to do it free). You don't need every lecture memorised — aim to understand the ideas below.
  2. Focus on these — they're what the check tests and what firmware actually stands on:
    • Fixed-width typesuint8_t, uint16_t, uint32_t from <stdint.h>, and why plain int is risky when a value must match a register.
    • Pointers — a pointer holds an address; *p reads/writes the value there. This is how you reach memory-mapped hardware.
    • Arrays vs pointers — an array is a fixed block that decays to a pointer to its first element, but is not a reassignable pointer (sizeof differs).
    • Bit manipulation — set REG |= (1 << n), clear REG &= ~(1 << n), test REG & (1 << n). This is register programming.
    • volatile — for hardware registers and ISR-shared data, so the compiler never caches a stale value or optimises the access away.
    • struct register maps — overlay a struct of volatile fields on a peripheral base address so you write GPIOA->ODR instead of a raw pointer.
    • Memory — flash vs RAM, stack vs heap, and why firmware usually avoids malloc on a tiny device.
    • const and functions — read-only data, and pass-by-value vs passing a pointer to modify the caller's variable.
  3. Practice in the browser (next section) — write and run real embedded C with nothing to install.
  4. Take the K-Check to earn your certificate.

Why this connects to building real products

This is the firmware layer of every product you design in Forge. When Forge picks a microcontroller and wires a sensor to it, the code that makes it do anything is exactly this: pointers into memory-mapped registers, bits set and cleared to configure a pin or a peripheral, volatile reads of an input, structs mapping a chip's datasheet onto named registers. Knowing embedded C is what lets you go from a design with an orderable parts list to a board that actually runs.

Slide 2

How to practice — write embedded C in the browser

The fastest way to make embedded C stick is to write and run it — and you can do that free in your browser, with no toolchain to install. Open Wokwi, a free online Arduino/ESP32 simulator: start a new Arduino Uno or ESP32 project, edit the C/C++ in the code pane, press Run, and watch a real simulated board react (LEDs, the serial monitor, wired-up buttons and sensors). For pure C bit-twiddling with no hardware, an online C compiler works too — print the result of REG |= (1 << 3) and friends and confirm the bits land where you expect.

For a first exercise, wire an LED and a push-button in Wokwi and drive them with bit manipulation instead of the tidy Arduino helpers: read the button by masking its port bit (if (PIND & (1 << 2))), and toggle the LED with PORTB ^= (1 << 5) (or set/clear it with |= and &= ~). Declare any flag you share with an interrupt as volatile, and notice how a uint8_t mask maps directly onto the register. Once blink-and-read works at the register level, you've done in the browser exactly what the course teaches on real silicon — the same pointers, masks, and registers, just simulated.