ProjekinAja. Embedded Systems Stage 3 · Firmware Lesson 3.1
● Stage 3 · Lesson 3.1

Inside a Microcontroller: Core, Memory, Peripherals, and Buses

A microcontroller is a CPU that agreed to live next to its peripherals and share an address space with them.

⏱ ~24 min read 🧠 Mental model 🔧 ESP32-C3 worked example

🎯 By the end you'll understand

What is physically inside the ESP32-C3 on Beacon's module and how the pieces talk: one RISC-V core, three kinds of memory with three different lifetimes, and a wall of peripherals that are nothing more than addresses. Why "a register is an address" explains half of embedded programming. Why clocks, not code, are where power is saved — and why a peripheral whose clock is off is a peripheral that silently does nothing. How the chip gets from a reset pulse to your app_main(), and why Beacon chose one core over two.

KEY INSIGHTThe CPU is the least interesting part

On a laptop the CPU is the product and everything else is plumbing. On a microcontroller it is the reverse: the core is a small, boring engine whose only job is to move numbers between addresses — and the interesting question is what lives at each address.

Here is the bench scenario this lesson is built around. A learner writes a clean LEDC PWM setup by poking the registers directly, because the datasheet lists them and the driver felt like ceremony. The code compiles, runs, returns no error, and the LED stays dark. The oscilloscope on the pin shows a flat line. Every register write "succeeded" — and every one of them landed on a block of silicon that was not being clocked. The peripheral was not broken, not misconfigured, not asleep. It was simply not listening, because nobody had turned its clock on. Understanding why that is possible is the same as understanding what a microcontroller is.

🔑 Hold onto this

A microcontroller is one address space shared by a CPU, several memories, and dozens of peripherals. Reading or writing an address is the only thing the core can do. Whether that address is SRAM, flash, a UART's transmit FIFO, or a GPIO output latch is decided by the memory map — a fixed table baked into the chip. Every driver you will ever write is a thin layer that turns "set the duty cycle" into "write this value to that address, in this order, after that clock is on." When something does nothing, ask which address you actually wrote, and whether anything was awake to receive it.

CORE CONCEPTAnatomy of an MCU: core, buses, memory, peripherals

Strip the marketing off the ESP32-C3 datasheet and the block diagram has four kinds of thing in it:

RISC-V core RV32IMC · 160 MHz · single core Instruction bus + data bus · one 32-bit address space (0x0000_0000 – 0xFFFF_FFFF) ROM 384 KB 1st-stage boot · libs SRAM 400 KB .data .bss heap stacks Cache → flash .text .rodata via MMU SPI flash 4 MB in module · 80 MHz QIO RTC SRAM 8 KB survives deep sleep Peripherals GPIO I2C UART LEDC… each a block of registers at 0x6000_xxxx read-only, always there lost in deep sleep RTC_DATA_ATTR lives here
Everything hangs off one address space. The core does not "talk to the UART" — it stores a byte to an address that happens to be the UART's transmit FIFO. The flash is not on the bus directly; a cache and an MMU make a window of it appear at fixed addresses. Sizes are the ESP32-C3 datasheet's.

Two consequences fall out immediately. First, the CPU is fungible. The RISC-V core in the C3, the Xtensa cores in the S3, and the Cortex-M in an STM32 all do the same job — the toolchain hides the instruction set. What you actually program against is the memory map and the peripherals, which is why moving a driver between two chips from the same vendor is easy and between vendors is a rewrite. Second, speed is a property of the address, not the core. A load from SRAM completes in a cycle or so. A load from flash goes through the cache: a hit is nearly as fast, a miss stalls the core for dozens of cycles while the SPI flash streams a line in. A load from a peripheral register crosses a slower bus and may take several cycles more. Same instruction, three different costs.

📖 Harvard, von Neumann, and why the C3 is "sort of both"

Textbooks split architectures into von Neumann (one bus for code and data) and Harvard (separate buses). The ESP32-C3 has separate instruction and data buses — Harvard-style, so the core can fetch an instruction and load data in the same cycle — but the same physical SRAM and flash are reachable from both, at different addresses. That is why the technical reference manual lists the internal SRAM twice, once in the 0x4037_Cxxx instruction range and once in the 0x3FC8_xxxx data range. One memory, two doors. ESP-IDF's IRAM_ATTR and DRAM_ATTR are instructions to the linker about which door a symbol should be reachable through.

HOW IT WORKSThe memory map: three memories, three lifetimes

The memory map is the single most useful page in any MCU manual, and almost nobody reads it until something crashes. Here is the ESP32-C3's, reduced to what a firmware author needs. Addresses are from Espressif's technical reference manual; if you are about to hard-code one, look it up again — the exact ranges are the kind of thing an errata sheet quietly changes.

RegionAddress range (data bus)SizeSpeedSurvives deep sleep?Typical use
Mask ROM0x3FF0_0000 (data) / 0x4000_0000 (instr)384 KBFast, read-onlyYes (it is ROM)First-stage bootloader, ROM library routines
Internal SRAM0x3FC8_0000 (data) / 0x4037_C000 (instr)384 KB + 16 KB cacheFastest (≈1 cycle)No — contents lost.data, .bss, heap, task stacks, IRAM code
External flash (mapped)0x3C00_0000 (data) / 0x4200_0000 (instr)4 MB in moduleFast on cache hit, slow on missYes (non-volatile).text, .rodata, partitions (app, NVS, OTA)
RTC FAST memory0x5000_00008 KBFastYes — powered in deep sleepWake stubs, counters that must persist between sleeps
Peripherals0x6000_0000 onward—Slower bus, side effectsRegisters reset unless in RTC domainGPIO at 0x6000_4000, UART0 at 0x6000_0000, etc.

The column that matters most for Beacon is the one people skip: what survives deep sleep. Beacon spends 99.9 % of its life asleep at ≈ 8 µA, and deep sleep on the ESP32-C3 powers down the core, the main SRAM, and every peripheral except the RTC domain. When the RTC timer fires 60 s later, the chip does not "wake up" in the way a laptop resumes — it reboots. Your program starts from the reset vector again, app_main() runs again, and every variable in SRAM is garbage. The only state that carries across is what you deliberately placed in the 8 KB of RTC memory with RTC_DATA_ATTR, plus whatever you wrote to flash. So Beacon's advertising sequence number — the one byte in the BLE payload that lets a gateway detect missed reports — cannot be an ordinary static uint8_t. It has to live at 0x5000_xxxx, or it is zero every minute.

Flash data window (8 MB) 0x3C00_0000 SRAM data view (384 KB) 0x3FC8_0000 ROM data view 0x3FF0_0000 ROM instruction view 0x4000_0000 SRAM instr view (IRAM) 0x4037_C000 Flash instr window (.text) 0x4200_0000 RTC FAST memory (8 KB) 0x5000_0000 Peripheral registers 0x6000_0000 data bus (loads/stores) instruction bus (fetch) · RTC + peripherals Same SRAM appears twice — one physical memory, two bus doors. Ranges per Espressif TRM; verify before hard-coding.
The ESP32-C3 address ladder. Notice the two views of SRAM and ROM: the instruction bus and data bus reach the same silicon at different numbers. Peripheral registers are reachable only from the data side, which is why you cannot run code out of a peripheral register. RTC FAST memory is the exception in the other direction: it is reachable from both buses, which is exactly why a deep-sleep wake stub — real executable code — can live there and run before the main image is loaded.

A second thing the map tells you: flash is not always there. When the chip is erasing or programming a flash sector — writing to NVS, receiving an OTA image — the SPI flash is busy and the cache is disabled. Any code fetch or constant read that misses the cache during that window would return garbage, so ESP-IDF forbids it: code that can run while flash is being written must be in IRAM (IRAM_ATTR), the constants it touches in DRAM (DRAM_ATTR), and the string in your ESP_LOGI call inside an interrupt handler becomes a crash with the message "Cache disabled but cached memory region accessed". This is not an ESP-IDF quirk; it is the memory map being honest with you.

DEFINITIONA register is an address

Here is the idea that unlocks datasheets. A peripheral register is a 32-bit word at a fixed address whose bits are wired to hardware. Writing to it changes the hardware; reading from it samples the hardware. Nothing is stored in the sense a variable is stored — write a 1 to bit 8 of the GPIO "output set" register and pin 8 goes high, but read that same register back and you get zero, because it is a command port, not a memory cell. The ESP32-C3's GPIO block lives at 0x6000_4000; its output-set register is a few bytes in. The two programs below do exactly the same thing to the same address.

gpio_two_ways.cESP-IDF 5.x · register vs driver
#include "driver/gpio.h"
#include "soc/gpio_reg.h"      // GPIO_OUT_W1TS_REG etc. — the addresses

#define LED_PIN  8          // dev-kit LED; Beacon's WS2812 is a different story

// Way 1: the driver. Enables the pad, sets direction, clears pulls.
static void led_init_driver(void)
{
    gpio_config_t cfg = {
        .pin_bit_mask = 1ULL << LED_PIN,
        .mode         = GPIO_MODE_OUTPUT,
        .pull_up_en   = GPIO_PULLUP_DISABLE,
        .pull_down_en = GPIO_PULLDOWN_DISABLE,
        .intr_type    = GPIO_INTR_DISABLE,
    };
    ESP_ERROR_CHECK(gpio_config(&cfg));
    gpio_set_level(LED_PIN, 1);
}

// Way 2: the address. Same silicon, no safety net.
static void led_init_raw(void)
{
    REG_WRITE(GPIO_ENABLE_W1TS_REG, 1u << LED_PIN);  // W1TS = "write 1 to set"
    REG_WRITE(GPIO_OUT_W1TS_REG,    1u << LED_PIN);  // pin high
    // ...but the IO_MUX pad function, drive strength and pull state
    // are separate registers the driver also touched. Forget one and
    // the pin is "high" inside the GPIO block and floating at the pad.
}

Notice the naming: W1TS (write-1-to-set) and W1TC (write-1-to-clear). These exist because a plain read-modify-write of the output register — read all 22 bits, flip one, write all back — takes three instructions, and an interrupt landing between them that changes another pin would be overwritten. A set/clear pair is atomic in one store. That is a hardware-level solution to a software-level race, and it is the first hint that concurrency on an MCU starts below the RTOS (Lesson 3.4 makes this precise).

💡 How to read a register description without drowning

Every register page in a technical reference manual has the same four things: the address (base + offset), the bit fields with names, the access type per field (R, W, R/W, WO, W1TS, RC…), and the reset value. Read the access type first. A "W" field that reads back zero is not broken. A "R/WC" (read, write-1-to-clear) status bit will not clear if you write zero to it. A reset value tells you what the peripheral is doing before your code runs — GPIO9 on the C3 resets with its pull-up enabled, which is the entire reason it can double as the boot-mode strap (Lesson 3.3). Only after the access type do the bit-field semantics matter.

ESP-IDF's drivers are worth using not because register access is hard but because the order is. The gpio_config() call above also selects the pad's function in the IO_MUX, sets the drive strength, and disconnects any peripheral signal that was routed to the pin through the GPIO matrix. Miss any of those and the register block is happy while the physical pin does something else. The driver is the datasheet's init sequence, written once by someone who read the errata.

SEE ITMemory map explorer: put four things somewhere and pay for it

Beacon's firmware has four allocations that must go somewhere: a 40 KB ring buffer of raw sensor samples (for the motion-classification experiment in Stage 4), a constant lookup table used to linearise the SHT40 humidity reading, the application task's stack, and a 16-byte record — sequence number, last battery reading, boot count — that must survive deep sleep. Place each one. The widget links your choices against the ESP32-C3's regions and tells you what fits, what is fast, what survives, and what the linker refuses. The worst decisions here look fine right up until the first sleep cycle.

⚙ Interactive · ESP32-C3 memory map explorer

Choose a region for each allocation, then Link. Then Deep sleep & wake to see which allocations still hold their values. Capacities below are the datasheet's; the "free after IDF + BLE" figures are illustrative round numbers, not measurements.

4 KB
4 KB
SRAM · 384 KB total · ≈ 180 KB free for app after IDF + NimBLE (illustrative)—
RTC FAST memory · 8 KB total · ≈ 7 KB free (illustrative)—
Flash .rodata headroom in OTA slot (illustrative 300 KB spare)—
Link result
—
Sample loop cost
—
After wake
—

    Place the allocations, then link.

    The widget's trap is the fourth allocation. Leaving the record as a static variable in SRAM links perfectly, runs perfectly, and produces a device whose sequence number is zero on every report — the gateway sees a tag that never misses a packet and never counts, which is worse than one that visibly fails. The second trap is the lookup table: placing it in RTC memory "so it survives" costs you the scarcest 8 KB on the chip for a constant that survives anyway, because flash does. Persistence is a property of the region, not of your intent.

    CORE CONCEPTClocks and clock gating: where the power actually goes

    Digital CMOS logic burns power in two ways. There is a small static leakage that exists whenever the transistors are powered, and there is dynamic power spent every time a node switches — charging and discharging the tiny capacitance of the wires and gates. Dynamic power scales roughly as C · V² · f: the capacitance being switched, the square of the supply voltage, and the switching frequency. What that means at the bench is that a peripheral doing nothing but receiving a clock still toggles thousands of flip-flops 160 million times a second, and every one of those toggles is a withdrawal from Beacon's 1000 mAh.

    So a modern MCU is built as a tree of clocks with a gate on every branch. The clock tree starts at a source — on the C3, a 40 MHz crystal, an internal ~17.5 MHz RC oscillator, and a phase-locked loop that multiplies the crystal up to 480 MHz — passes through dividers that produce the 160 MHz CPU clock and the 80 MHz peripheral bus clock, and then fans out to each peripheral through an enable bit. Clear the bit and the peripheral's flip-flops stop toggling. Its registers hold their last value; it draws only leakage; and it cannot respond to anything, including your writes.

    XTAL 40 MHz accurate, slow to start RC ~17.5 MHz ±few %, instant RTC slow clk ~136 kHz RC · runs in sleep PLL 480 MHz off in sleep CPU 160 MHz APB 80 MHz ÷3 ÷6 EN I2C0 · SHT40 + LIS2DH12 0 LEDC (PWM) — gated: writes ignored EN UART0 / USB-Serial-JTAG EN BLE baseband + radio RTC timer · wakes at 60 s Deep sleep = PLL off, CPU/APB stopped, all gates closed; only the RTC slow clock and its timer keep running.
    The clock tree, simplified. Each peripheral sits behind an enable gate. The LEDC block in this drawing is the bench scenario from the top of the lesson: its registers accepted every write and its output never moved. Divider ratios are illustrative of the C3's defaults (160 MHz CPU, 80 MHz APB from a 480 MHz PLL).

    Deep sleep is the extreme case of this idea: the PLL stops, the CPU and APB clocks stop, every gate closes, and the main power domain is switched off entirely. What is left is a small always-on RTC domain running from a ~136 kHz RC oscillator, ticking a timer that will, 60 s later, re-enable the power domain and let the ROM bootloader start over. Beacon's ≈ 8 µA sleep figure is essentially the cost of that RTC domain plus the module's flash standby current, the regulator's quiescent current, the sensors' sleep modes, and the battery divider's leakage — none of it is the core, because the core does not exist while asleep.

    ⚠ The failure mode: a peripheral that does nothing

    ESP-IDF's drivers enable a peripheral's clock as part of their init call — buried inside ledc_timer_config() is the equivalent of periph_module_enable(PERIPH_LEDC_MODULE), which sets the LEDC bit in the system clock-enable register and pulses its reset. Bypass the driver, or call a "set duty" function before the "init timer" one, and you write to a block that is gated. There is no bus error, no exception, no return code. Reads of the block come back as its reset values (or the last value before it was gated), which can look plausible. The RTC and RC oscillator have an equally silent version: if you configure a peripheral to use a clock source you then disable for sleep, the peripheral wakes up dead. When a peripheral does nothing, the first three questions are: is its clock enabled, is it out of reset, and is its pin actually routed to it through the IO_MUX/GPIO matrix. Only then look at the configuration registers.

    HOW IT WORKSFrom reset to app_main: ROM → bootloader → app

    Power arrives, the brown-out detector releases reset, and the core starts fetching from a fixed address in mask ROM. From there a chain of three programs runs, each smaller and dumber than the next one it loads. Understanding the chain is what makes Lesson 3.3's GPIO9 trap and Lesson 4.9's OTA rollback obvious instead of magical.

    1

    First-stage bootloader (mask ROM, cannot be changed)

    Sets up minimal clocks and the SPI flash interface, then samples the strapping pins. On the ESP32-C3 these are GPIO2, GPIO8, and GPIO9. If GPIO9 is low (with GPIO8 high), the ROM enters download mode and waits on UART0 / USB Serial/JTAG for a flashing tool instead of booting. Otherwise it reads the second-stage bootloader from flash offset 0x0 into SRAM and jumps to it. This code is the same in every C3 ever made; it is why a bricked app can always be reflashed.

    2

    Second-stage bootloader (ESP-IDF, in flash at 0x0)

    Reads the partition table at flash offset 0x8000, checks the otadata partition to see which app slot is current (Beacon has two, ota_0 and ota_1), verifies the chosen image's checksum (and signature, if secure boot is on), programs the flash MMU so the image's code and constants appear at 0x4200_0000 / 0x3C00_0000, copies the image's SRAM-resident segments in, and jumps to the app's entry point. If the image is marked "new, unverified" and the previous boot did not confirm it, the bootloader rolls back to the other slot — that is R7's rollback, and it lives here, not in your code.

    3

    Application startup (your image, before app_main)

    ESP-IDF's startup code zeroes .bss, initialises the heap allocator over the free SRAM, brings up the console, starts the FreeRTOS scheduler, and creates the main task, which finally calls app_main(). By the time your first line runs, roughly a hundred kilobytes of someone else's code has already executed. On a deep-sleep wake the whole chain repeats; esp_sleep_get_wakeup_cause() is how the app finds out it is a wake rather than a cold boot.

    Two numbers to keep. The reset-to-app_main time on a C3 with default settings is on the order of tens of milliseconds, most of it the second-stage bootloader verifying the image and the app's own initialisation; this is part of Beacon's 45 ms active window and it is not free. And the ROM's download-mode decision is made from the strapping pins at the moment reset is released — the ROM does not re-check later. Beacon's button on GPIO9 has to be low during that instant for the trap to fire, which is exactly why the failure is "only when the user holds it while inserting the battery."

    BEACONWhy Beacon runs an ESP32-C3 and not an S3

    Lesson 1.6 chose the ESP32-C3-MINI-1 for Beacon and promised the firmware-side argument here. The ESP32-S3 is the obvious alternative from the same vendor: two Xtensa LX7 cores at 240 MHz, up to 512 KB SRAM, vector instructions, more pins, and the same BLE 5.0 radio. Here is what each choice buys.

    PropertyESP32-C3 (Beacon)ESP32-S3What it means for Beacon
    Cores1 × RISC-V @ 160 MHz2 × Xtensa LX7 @ 240 MHzBeacon's active work is ~45 ms of I2C and radio per minute. One core is idle 99 % of that.
    Where the BLE stack runsSame core as the app (as FreeRTOS tasks)Usually pinned to core 0, app on core 1On the C3, a long ISR or a hogging task delays the radio. That is a discipline problem (3.4, 3.8), not a hardware limit at Beacon's load.
    SRAM400 KB512 KB (+ optional PSRAM)Beacon's firmware v0 uses well under 100 KB of static data. Neither is a constraint.
    Module footprint (MINI-1)13.2 × 16.6 mm15.4 × 20.5 mm (S3-MINI-1)R8 is 35 × 25 mm for the whole board. Every square millimetre goes to the antenna keep-out (5.7).
    Deep-sleep current (chip, datasheet typical)≈ 5 µA≈ 7–8 µASmall, but R1 is a six-month budget and 8 µA total is the canon sleep figure. Every µA is ~12 % of it.
    Price (module, small qty)LowerHigherR5 caps BOM at IDR 150,000; the module is the single largest line.
    Toolchain / debugRISC-V GCC, native USB-JTAG on GPIO18/19Xtensa GCC, native USB-JTAG tooEqual in practice. The C3's ISA is open and easier to read in a disassembly.

    What the S3's second core would have bought is isolation: the radio stack on one core, the application on the other, so a misbehaving application task can never delay an advertising event. That is genuinely valuable in a product that streams audio or runs a display. For a tag that wakes, samples two I2C sensors, sends three advertising packets, and sleeps, the isolation protects against a problem the design does not have — and the price is a bigger module, more sleep current, and a second scheduler to reason about. Single-core simplicity means every timing question in Stage 3 has one answer: what is the core doing right now? The cost of that choice is that Lessons 3.4 and 3.8 become mandatory reading — on one core, ISR length and task priorities are the only isolation you get.

    🔑 Beacon firmware v0: what this lesson fixes

    Three decisions for the milestone firmware follow from the memory map. (1) The persistent record — sequence number, boot count, last battery reading — is declared RTC_DATA_ATTR so it survives the 60 s deep sleep. (2) The sensor drivers' constants and the log strings stay in flash; only the I2C ISR helpers and anything that must run during an OTA flash write get IRAM_ATTR. (3) The application uses ESP-IDF drivers for GPIO, I2C, and LEDC rather than raw registers, precisely so the clock-enable and IO_MUX sequencing is never Beacon's bug. Where a raw register read is useful — reading the reset reason, checking a strapping pin at boot — it is wrapped in one named function with the TRM page number in a comment.

    WEAKNESSWhere this bites

    ✗ Treating a wake from deep sleep as a resume

    Engineers arriving from Linux expect suspend/resume: the program continues where it left off. On the ESP32-C3 a deep-sleep wake is a reset that happens to preserve 8 KB of RTC memory and the RTC timer. Any state machine that keeps its current state in a normal variable restarts in BOOT every minute — which is fine for Beacon's design, because the FSM in 3.7 is written so that every wake starts at BOOT deliberately. The bug appears when someone "optimises" by keeping a sensor's calibration in SRAM, or a partially received OTA image in a heap buffer, and then wonders why the second sleep cycle destroys it. If it must persist, it is RTC memory (small, fast, volatile if the battery is pulled) or flash (large, slow, wears out). There is no third option.

    ✗ Believing a register write because it did not fail

    Stores to a peripheral address never fail. Not when the clock is off, not when the peripheral is held in reset, not when the pin is routed elsewhere through the GPIO matrix, not when you wrote the wrong offset and hit a reserved word. The bus completes the transaction and the core moves on. The only evidence is physical: a scope on the pin, a logic analyser on the bus, or a read-back of a status register that the hardware, not you, sets. "The code ran without errors" is a statement about the core, not about the peripheral, and on an MCU those are different machines.

    ✗ Hard-coding addresses from a forum post

    The ESP32, ESP32-S2, ESP32-C3, and ESP32-S3 share peripheral designs and differ in base addresses, bit positions, and which pins are RTC-capable. A GPIO register snippet copied from an ESP32 tutorial will compile for a C3 and write to the wrong place. Use the soc/*_reg.h headers, which are generated per chip, and let GPIO_OUT_W1TS_REG resolve to whatever this silicon needs. If you must cite a raw number in a comment, cite the TRM revision next to it. The memory map is a contract with one specific chip.

    KEY INSIGHTHow this connects

    • Reading a Datasheet Without Getting Fooled (1.6) — the datasheet skills from Stage 1 apply verbatim to the technical reference manual: every register has conditions (clock on, reset released, pin routed) exactly as every electrical parameter has conditions. The module choice argued here was first made there on cost and footprint.
    • Toolchain and Build: From Source to Flash (3.2) — the next lesson is the memory map from the linker's side: which section each symbol lands in, how the partition table carves the 4 MB flash, and what happens when the image no longer fits its OTA slot.
    • GPIO, Timers, and PWM (3.3) — the ROM's strapping-pin sample from the boot sequence becomes Beacon's GPIO9 button trap, and LEDC gets its clock turned on properly.
    • FreeRTOS Essentials (3.8) — the single-core decision defended here is the reason task priorities and ISR discipline carry the whole isolation burden.

    Everything in Stage 3 is a special case of this lesson. Interrupts are the core being told to jump to an address. Buses are peripherals whose registers are FIFOs. Drivers are ordered sequences of register writes with the timing the datasheet demands. The RTOS is a program that decides which sequence of addresses the core visits next. When a later lesson feels abstract, come back to the map and find the address.

    GLOSSARYKey terms introduced

    Memory map
    The fixed assignment of address ranges to memories and peripherals inside a chip. Determines the speed, lifetime, and side effects of every load and store.
    Memory-mapped peripheral
    A hardware block controlled through registers that occupy ordinary addresses. Writing configures it; reading samples it. There is no other way to reach it.
    Register access type
    The datasheet's per-field rule — R, W, R/W, W1TS, W1TC, RC — describing what a read or write actually does. Reading it first prevents most register-level bugs.
    Clock gating
    Stopping a peripheral's clock through an enable bit so its logic stops switching and stops drawing dynamic power. A gated peripheral ignores register writes silently.
    RTC memory
    The 8 KB of SRAM in the ESP32-C3's always-on RTC power domain. The only RAM whose contents survive deep sleep; reached via RTC_DATA_ATTR.
    IRAM / DRAM attributes
    Linker hints placing code (IRAM_ATTR) or data (DRAM_ATTR) in internal SRAM instead of flash, required for anything that runs while the flash cache is disabled.
    Strapping pin
    A GPIO whose level at reset release is sampled by the ROM to choose boot mode or configure the chip. GPIO2, GPIO8, and GPIO9 on the ESP32-C3.
    Second-stage bootloader
    ESP-IDF's small program at flash offset 0x0 that reads the partition table, selects an app slot, maps it through the flash MMU, and handles OTA rollback.

    ACTIVE RECALLCheck your understanding

    Answer in your own words first, then reveal.

    1You write a value to a PWM duty-cycle register, read it back, and see your value. The pin is still flat on the scope. Name three things, in the order you would check them, that can make this happen.›

    First, is the peripheral's clock enabled and its reset released? Some register files hold written values even while gated, so a read-back is not proof of life; the output logic is not switching. Second, is the pin actually routed to this peripheral? On the ESP32-C3 the LEDC channel output has to be connected to the pad through the GPIO matrix and the pad's IO_MUX function set; otherwise the PWM is happily toggling an internal signal that reaches no pin. Third, is the timer that drives the channel configured and running? A duty value is meaningless until the LEDC timer it references has a frequency and resolution and has been started. Only after those three does the duty register's value itself matter. Every one of these is silent — no error, no exception.

    2Beacon's advertising sequence number is declared as static uint8_t seq; and incremented every report. What does the gateway see, and what is the one-line fix?›

    Every report carries seq = 1 (or 0, depending on where the increment sits), because each 60 s wake from deep sleep is a reset: SRAM is unpowered during sleep, .bss is zeroed by the startup code, and the variable starts from zero every time. The gateway cannot detect missed packets and the "field looks perfect" while it is not. The fix is to move the variable into the RTC power domain: RTC_DATA_ATTR static uint8_t seq;. It then lives at 0x5000_xxxx, survives deep sleep, and is only lost when the battery is disconnected or the chip is fully reset. It does not survive a power cycle — if that matters, it must be written to NVS in flash, at the cost of a flash write per report and eventual wear.

    3Why does ESP-IDF crash with "cache disabled but cached memory region accessed" when you log from inside an interrupt during an NVS write, and what does the memory map say about the fix?›

    Log strings are constants, and constants live in .rodata, which is in flash and reached through the cache window at 0x3C00_0000. While the flash is being erased or programmed (NVS write, OTA), the SPI flash cannot serve reads, so ESP-IDF disables the cache. An interrupt that fires in that window and touches a flash-resident string, or whose handler code itself is in flash, would read garbage, so IDF traps it deliberately. The fix is to make the ISR's code and any data it touches SRAM-resident: mark the handler IRAM_ATTR, keep its constants DRAM_ATTR, and never call ESP_LOGx from an ISR at all (use ESP_DRAM_LOGx if you must, or defer to a task, as 3.4 teaches). The memory map is telling you that flash is a shared, occasionally unavailable resource, and SRAM is the only always-there memory.

    4A colleague argues Beacon should have used the dual-core ESP32-S3 "for safety, so the BLE stack can never be starved." Give the strongest version of their argument and then the reason the C3 was chosen anyway.›

    Strongest version: on the single-core C3, the BLE controller and host run as FreeRTOS tasks on the same core as the application, so a long ISR, a task with a priority set too high, or a busy-wait in a driver can delay a scheduled advertising event or a controller timing deadline; a second core pinned to the radio removes that class of bug structurally rather than by discipline. That is true and it is why the S3 is right for audio, display, and streaming products. The C3 was chosen because Beacon's application load is tiny — about 45 ms of I2C traffic and three advertising packets per minute — so the isolation protects against a problem the design does not have, and it costs a larger module footprint against R8's 35 × 25 mm, higher deep-sleep current against R1's µA budget, and higher price against R5's BOM cap. The single-core cost is real but it is paid in Lessons 3.4 and 3.8: short ISRs, sane priorities, no blocking in the app task. Those are habits worth having on any chip.

    Next: the linker decides where your program lives →