Embedded Development Architecture Standards: Making Code Elegant, Reliable, and Portable Like LEGO!

1. Why do 90% of embedded projects fail during the “maintenance phase”?

👇 Let’s start with a soul-searching question

  • When requirements change, do the driver layer, business layer, and UI all need to change too?

  • When a newcomer takes over the code, do they spend two weeks just trying to find the entry point?

💡 The root cause: There is no unified “architecture standard”!

Today, I will guide you step by step to make your project a “maintainable, portable, and upgradable” model project!

2. Remember these five core goals!

Goal

One-sentence mantra

Readability

Code is documentation

Maintainability

Low coupling of modules

Reliability

Defensive programming

Portability

Hardware abstraction layer

Compliance

Supported by industry standards

3. Programming standards: Nipping “bad code” in the bud

1️⃣ Documentation first

  • Doxygen generates API documentation with a comment rate of ≥ 30%.

2️⃣ Modular design

  • Function granularity: adc.c, uart.c, app.c.

  • Global variables are strictly prohibited; everything should be encapsulated in structs.

3️⃣ Hardware isolation

  • Register operations → hal_xxx.c

  • Business logic → app_xxx.c

📌 Tip: Treat “portability” as a requirement, not a fire drill!

4. Version control & documentation management: Say goodbye to “legacy code”

  • Commit message template

  Fix: ADC sampling frequency configuration error  Feat: Added Bootloader OTA upgrade  Docs: Updated pin mapping table
  • Documentation essentials

    • Requirements specification

    • Architecture design document

    • Interface definition document

    • Change log (Changelog)

5. Testing and validation: Discover bugs early, keep your hair!

Test Type

Methods & Tools

Key Metrics

Unit Testing

Ceedling / Unity

100% coverage of boundary conditions

Integration Testing

Logic analyzer + host script

0% packet loss in UART communication

Hardware Testing

Oscilloscope + temperature chamber

Stable operation from -40 to 85 ℃

6. Safety and reliability: No crashes on-site, no running away from the boss

  • Watchdog

Independent hardware watchdog + software window watchdog for double insurance.

  • Exception handling

Sensor reading → timeout 50 ms, retry 3 times

HardFault → save registers + logs + revive in place

  • Functional safety

Automotive products: ISO 26262 (ASIL-C)

Industrial control: IEC 61508 (SIL-2)

7. Resource optimization: Saving Flash is earning

  • ROM slimming

Place const constants in Flash, trim redundant library functions with one click.

  • RAM slimming

Use static variables instead of malloc, statically calculate stack depth.

8. Debugging & upgrading: On-site upgrades without disassembly

  • Debug interface

Reserve SWD + UART RTT, with 5-level log filtering (DBG/WARN/ERR/FATAL).

  • OTA upgrade

Bootloader → dual partition + CRC32 verification + breakpoint resume.

9. Team collaboration: The correct posture for Code Review

  • Merge Request template

    • Motivation for changes

    • Risk points

    • Screenshot of test report

  • Review Checklist

    • Does it comply with MISRA-C?

    • Is there exception handling?

    • Unit test coverage ≥ 80%

10. A mind map to take away the full text!

Embedded Development Architecture Standards: Making Code Elegant, Reliable, and Portable Like LEGO!

🚀 Put the standards into practice, so that the next maintainer will be “grateful” to you!

Leave a Comment