Requirements and design notes
Testable requirements, traceability, one-page design notes and the documents a firmware team keeps.
Writing is part of the engineering
Firmware engineers write more than code. Requirements say what the product must do, precisely enough that someone can test it. Design notes record how and why it was built that way, so the next engineer, or you in a year, does not undo a decision whose reason was forgotten. In regulated fields (automotive, medical, avionics, industrial safety) these documents are mandatory and audited; everywhere else, they are what makes a team faster than one person.
Testable requirements
A requirement is useful only if two people would agree whether the product meets it. Compare:
| Weak | Testable |
|---|---|
| The device shall respond quickly. | The device shall send a response within 50 ms of receiving a valid command, measured at the UART pins. |
| The battery shall last a long time. | With a 2000 mAh battery and one report per hour, the device shall operate for at least 12 months at 25 °C. |
| The firmware shall handle errors. | If the temperature sensor does not respond for 3 consecutive readings, the device shall report fault code E12 and continue running with the last valid value for at most 60 s. |
| The display should be bright enough. | The display shall be readable at 10,000 lux ambient light, judged by the procedure in TP-07. |
The habits behind the right-hand column:
- One requirement per statement, with shall for what is mandatory (and should only for a genuine preference).
- Numbers with units, tolerances and conditions (temperature, supply voltage, load).
- Say what, not how: "shall store the last 100 events across power loss", not "shall use a ring buffer in flash".
- Cover the unhappy paths: invalid input, missing sensors, power loss mid-operation, out-of-range values.
- Include the non-functional ones: timing, power, memory and flash budgets, start-up time, the safe state after a fault.
Identifiers and traceability
Give every requirement a stable ID (REQ-BAT-003) and never reuse one. Then link each requirement forwards to the design and code that implement it and the tests that verify it. That chain, traceability, answers the questions every release review asks: is every requirement tested, and does every test check something required?
The cheapest form of traceability is the ID written where the work is done:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
/* REQ-BAT-001: The device shall raise a low-battery warning when the cell voltage is below 3400 mV.
REQ-BAT-002: The warning shall clear only when the voltage rises above 3500 mV (100 mV hysteresis). */
static bool low_battery(bool warning, uint16_t mv) {
if (!warning && mv < 3400u) return true; /* REQ-BAT-001 */
if (warning && mv > 3500u) return false; /* REQ-BAT-002 */
return warning;
}
/* Tests named after the requirement they verify, including the boundaries. */
static int failed;
static void check(const char *req, bool got, bool want) {
if (got != want) { failed++; printf("FAIL %s\n", req); }
}
int main(void) {
check("REQ-BAT-001 just above threshold", low_battery(false, 3400u), false);
check("REQ-BAT-001 just below threshold", low_battery(false, 3399u), true);
check("REQ-BAT-002 inside hysteresis", low_battery(true, 3450u), true);
check("REQ-BAT-002 at the clear threshold", low_battery(true, 3500u), true);
check("REQ-BAT-002 above the clear threshold", low_battery(true, 3501u), false);
printf("%d failed\n", failed);
return 0;
}
Requirements tools (Jama, Polarion, DOORS, or Markdown files in the repository with a script) collect these links into a traceability matrix. The tests at exactly 3399, 3400, 3500 and 3501 mV come straight from the numbers in the requirement; boundary values are where implementations go wrong.
Design notes
A design note is short: a page or two, written before or while the design is made, kept in the repository next to the code. A template that works:
- Context: the problem and the requirements it serves.
- Constraints: RAM, flash, timing, power, cost, standards.
- Decision: the design, with a diagram where it helps: a state machine, a sequence of messages, a memory map.
- Alternatives considered and why they lost.
- Consequences: what this makes easy, what it makes hard, what must be revisited if a constraint changes.
Recorded one decision at a time, these are called architecture decision records (ADRs). Their value is the why: "we poll the sensor instead of using its interrupt because the interrupt pin is shared with the radio on rev A boards" saves the next engineer a week.
The documents a firmware team keeps
| Document | Contents |
|---|---|
README | How to build, flash, debug and run the tests, from a clean machine |
| Interface definitions | Every message and register the firmware exposes: fields, units, ranges, byte order, versioning |
| Memory and flash maps | Where the bootloader, application slots, settings and logs live |
| Changelog | Per release: added, changed, fixed, known issues, written for the reader outside the team |
| Design notes and ADRs | The why behind the structure |
Comments in the code are documentation too: they should explain why (a hardware quirk, an errata workaround, a timing constraint), since the code already says what. Put units in names (timeout_ms, temp_dC) and the comment about them disappears.
Pitfall: Documents written once for a milestone and never updated are worse than none, because they are believed. Keep them in the repository, change them in the same pull request as the code, and review them together.
Interview question: How do you write a good requirement for firmware?
Answer: One testable statement using shall, with measurable values, units, tolerances and the conditions under which it applies, saying what the system must do rather than how. Give it a unique ID, cover error and boundary cases and non-functional properties such as timing, power and memory, and make sure it can be traced to the design that implements it and the test that verifies it. If I cannot describe the test that would check it, the requirement is not finished.
Build it: implement the alarm requirements, line by line
This is step 6, the last of the module project. The customer's specification for the vibration alarm arrives as numbered requirements, and the certification audit will ask, for each one, "where is it implemented, and which test proves it?" Write code that does exactly what they say, no more and no less. Each check below is named after the requirement it proves.
Lab: An alarm that meets a numbered specification
alarm_update(rms_mg) is called with each new RMS value (one per second) and returns the alarm state. The state starts at ALM_NORMAL.
| ID | Requirement |
|---|---|
| REQ-ALM-01 | The state shall become ALM_WARNING when RMS is above 2000 mg for 3 consecutive samples. |
| REQ-ALM-02 | The state shall become ALM_CRITICAL when RMS is above 4000 mg for 2 consecutive samples, from any state but ALM_FAULT. |
| REQ-ALM-03 | ALM_WARNING and ALM_CRITICAL shall return to ALM_NORMAL only after 5 consecutive samples below 1500 mg. A critical alarm shall not step down to a warning. |
| REQ-ALM-04 | A sample of 0xFFFF means the sensor failed; the state shall become ALM_FAULT immediately, from any state. |
| REQ-ALM-05 | ALM_FAULT shall be left, to ALM_NORMAL, only after 10 consecutive valid samples. Samples received in ALM_FAULT shall not start any other alarm. |
"Above" means strictly greater; "below" means strictly less. Each consecutive count starts again from 0 when a sample breaks the run. Counts for one rule run whatever the state, except as REQ-ALM-05 says.
Going deeper
Interview question: How would you turn 'keep my plants watered' into requirements for a greenhouse controller?
Answer: Ask what watered means (a moisture range), when watering is allowed, what must never happen (flooding, running the pump dry), and what the grower must be able to change. Write each as a testable statement with numbers (start below 30 %, stop at 45 %, never run more than 5 s), trace each to a design element and a test, and agree them before building.
Interview question: What is traceability, and why do safety standards require it?
Answer: Traceability is the documented link from each requirement to the design elements and code that implement it and to the tests that verify it, in both directions. Standards such as ISO 26262, IEC 62304 and DO-178C require it because it shows that every requirement, including every safety requirement, is implemented and tested, that there is no untested code without a reason, and what is affected when a requirement changes. Without it, a team cannot prove completeness to an assessor, or to itself.
Interview question: What belongs in a design note, and when should you write one?
Answer: The context and the requirements it serves, the constraints, the decision with a diagram if useful, the alternatives considered and why they were rejected, and the consequences. Write it before or while making a decision that is expensive to reverse or not obvious from the code: a memory layout, a protocol, a concurrency scheme, a choice between chips. Keep it short and in the repository, and update it in the same change as the code, so it records why the system is the way it is.
Explain it: In your own words, explain what makes a requirement testable, and how requirements connect to code and tests.
Answer: A testable requirement states one thing the system shall do, with numbers, units, tolerances and conditions, so there is an objective pass or fail. It says what, not how, and covers error cases and limits such as timing and power. Each requirement gets a permanent ID, and that ID is linked to the code that implements it and the tests that check it, often simply by writing the ID in both. The resulting traceability shows every requirement is implemented and tested, and the test cases come from the requirement's own boundaries.