Skip to content

Firmware Fundamentals — question 2 of 10

Write a real answer. It is graded against the question's rubric, and the mastery movement is computed by the same engine the product uses. Scoring here is deterministic rather than model-written, so this page costs nothing to run and nothing is saved. In a track built from your own posting, the same rubric is graded by the model, which is what produces feedback about your reasoning rather than about coverage.

STATUS_REG is a pointer to a fixed hardware address, e.g. `#define STATUS_REG ((uint8_t*)0x4000)`. The value at that address changes due to hardware activity, not due to anything the CPU writes.

A student writes firmware that polls a hardware status register to know when a peripheral is ready: `while (*STATUS_REG != READY) { }` followed by code that reads data out. On a debug build (no optimization) it works fine. The moment they turn on -O2 optimization, the board hangs forever at that loop even though the peripheral is clearly ready (an LED tied to the same signal turns on). What's happening, and what's the fix?

How sure are you?

Being confidently wrong costs more mastery than admitting a guess — that is deliberate, and it is how misconceptions get found.

Neither is graded, and nothing here is recorded.