Skip to content
AXXA

Architecture

Maintainable architectures for embedded systems

Embedded products outlive their first hardware, their first team and their first requirements. Five structural decisions that determine whether the software can follow.

Published
Reading time
3 min read

An embedded product is rarely finished. The first release ships on one board; the second needs a different sensor because the original went end-of-life; the third adds connectivity that nobody planned for. Ten years later the product is still in the field, maintained by engineers who never met the original authors.

Whether that journey is cheap or painful is decided largely by a handful of structural decisions made in the first year. None of them require a particular framework or methodology. All of them require deliberate intent.

1. Isolate hardware access explicitly

The single most valuable separation in an embedded code base is the one between code that knows about the hardware and code that does not. When application logic calls register-level functions directly, every hardware change becomes an application change.

A hardware abstraction layer does not need to be elaborate. It needs to be narrow, owned by the application, and expressed in the application’s vocabulary. An interface like pressure_sensor_read_kpa() is useful; a thin wrapper that exposes the SPI transaction is not: it simply moves the coupling one file away.

/* Owned by the application: describes what it needs, not how it is done. */
typedef struct {
    int  (*init)(void);
    int  (*read_kpa)(int32_t *out_millikpa);
    void (*set_sample_rate)(uint16_t hz);
} pressure_sensor_ops;

Two implementations should exist from the start: the real driver, and a fake used for host-based tests. If writing the fake is difficult, the interface is probably leaking hardware detail.

2. Make dependency direction a rule, not a habit

Layered diagrams are easy to draw and easy to violate. The diagram stays clean while the include graph slowly becomes a mesh.

The remedy is to make the intended dependency direction checkable. In CMake, that means one target per component, with dependencies declared explicitly through target_link_libraries and include paths that are PRIVATE unless there is a reason otherwise. A component that is not linked cannot be included by accident. For larger systems, a small script in CI that inspects the target graph and rejects forbidden edges is cheap insurance.

3. Treat time and memory as part of the interface

In resource-constrained systems, a function’s contract is not only its inputs and outputs. It is also how long it may take, whether it may block, whether it allocates, and from which context it may be called.

These properties are usually implicit, which is why they are violated. Write them down where the next engineer will see them (in the interface header, not in a separate document) and verify them where you can:

  • Allocate memory statically or at initialisation; forbid heap use in steady state, and enforce it with a linker or allocator hook.
  • State which functions are safe to call from interrupt context.
  • Give each periodic task an explicit execution-time budget and measure it on target as part of regular testing.

A system whose budgets are explicit can be reasoned about when a feature is added. A system whose budgets are implicit can only be tested and hoped about.

4. Separate configuration from variation

Embedded products rarely exist as a single variant. Different boards, markets and customers produce different builds. The naive approach, #ifdef blocks spread throughout the code, makes every variant a fork that happens to share a repository.

A more maintainable approach separates three things:

  1. Build-time selection of which components and drivers are included, done in the build system rather than in source files.
  2. Static configuration of included components, expressed as data structures that are validated at compile time.
  3. Runtime parameters, kept to the minimum that genuinely needs to change after deployment.

When variation lives in a small number of well-known places, adding a variant is configuration work rather than a code review of the entire system.

5. Record the decisions, not just the design

The design describes what the system is. Future engineers need to know why: which constraints were real, which alternatives were considered, which trade-offs were accepted knowingly.

Architecture decision records (a short document per significant decision, with context, options and consequences) cost an hour to write and save weeks of archaeology later. Keep them in the repository, next to the code they explain, and review them like code.

What this buys you

None of these practices make the first release faster. Their value appears at the second hardware revision, the third team, the security update five years after launch. That is precisely when most of an embedded product’s engineering cost is incurred, and when the architecture either carries the team or slows it down.

Contact

Have a system that needs to work and keep working?

Tell us about the system, the constraints and what is at stake. A senior engineer will read it and reply personally.

Start a conversation