Firmware Development with Large Language Models: A Practical Workflow and Real-World Lessons
Large language models can assist firmware developers with driver porting, chip platform adaptation, display configuration, boot flow changes, and multi-module debugging, but they are only useful when engineering judgment and verification remain in control. This article presents a practical workflow covering requirements clarification, solution design, technical specifications, task breakdown, phased implementation, testing, and review. It also examines structured development skills, subtask splitting, TDD in firmware contexts, PDF-to-Markdown documentation preparation, and how to judge whether a model has actually completed a task.
1. Conclusion First: LLMs Improve Efficiency, but They Cannot Replace Engineering Judgment
In firmware development, the value of large language models is no longer limited to completing a few lines of code or generating a simple function. For tasks such as driver porting, chip platform adaptation, display configuration, boot flow changes, and multi-module integration, LLMs can participate in requirements clarification, code search, implementation design, test case writing, and issue localization.
In practice, however, one conclusion is very clear: whether an LLM is useful often depends less on the model itself and more on whether the development workflow is rigorous enough.
If you simply tell the model, “Help me port this driver to the new platform,” common outcomes include:
- Multiple files are modified quickly without confirming the existing architecture.
- Generated interface names do not match the project’s actual definitions.
- Compile options, linker scripts, or boot code are ignored.
- Register bit-field meanings are misjudged.
- The model claims the feature is complete without actually compiling or testing it.
- Unrelated code is modified to eliminate errors, causing the problem scope to expand.
A more reliable approach is not to ask the model to “complete the task in one step,” but to split the work into engineering steps that are reviewable, verifiable, and reversible.
2. Recommended Standard Workflow: Move Step by Step from Requirements to Verification
In actual testing, I used a relatively fixed process:
Requirements clarification → solution design → technical specification → task breakdown → phased implementation → compile and test → result review.
The core value of this workflow is that it turns a “code generation problem” into an “engineering collaboration problem.” The model does not directly enter the file modification stage. Instead, it first clarifies goals, boundaries, and verification criteria.
2.1 Requirements Clarification: First Determine What Actually Needs to Change
Descriptions in firmware tasks are often incomplete. For example, “add display rotation support” may involve the following:
- The valid range of rotation angles.
- The definition of the coordinate system.
- Whether width and height are swapped when switching between landscape and portrait.
- Whether the framebuffer layout needs to change.
- Whether the flush interface supports non-contiguous regions.
- Whether the configuration needs to be persisted.
- Whether the old behavior must remain compatible.
If these questions are not confirmed first, the model can easily fill in gaps based on common experience and produce a solution that is logically reasonable but unsuitable for the project.
Therefore, before starting modifications, require the model to output its understanding of the requirements, including:
- How the current feature works.
- The goal of this change.
- What is out of scope for this change.
- Modules that may be affected.
- Acceptance criteria and exception scenarios.
This stage should not rush into code generation. The more accurate the requirements understanding, the less rework later.
2.2 Solution Design: Read the Project Before Deciding How to Change It
Large firmware projects often contain complex implicit dependencies between code components. A single configuration macro may affect initialization, task scheduling, driver registration, and test code at the same time. If the model reads only the current file, it can easily make incorrect judgments about the overall structure.
A safer approach is to have the model first perform code reconnaissance:
- Find declarations and implementations of related interfaces.
- Confirm call chains.
- Identify platform-specific code versus common code.
- Check build conditions and macro definitions.
- Review existing tests or examples.
- Map the lifecycle of data structures.
- Mark files that may be affected but should not be modified yet.
Then ask the model to provide two or three implementation options and explain the pros and cons of each. For example, a feature can be implemented at the driver layer, adaptation layer, or business layer, and the location affects reusability, test difficulty, and compatibility. Making these choices explicit is more reliable than accepting the model’s first option.
2.3 Form a Technical Specification: Turn Natural Language into Executable Constraints
Before complex modifications begin, it is best to create a short technical specification that includes at least:
- Functional goals.
- Inputs and outputs.
- Interface changes.
- State transitions.
- Error handling.
- Concurrency and interrupt constraints.
- Memory and performance limits.
- Compatibility requirements.
- Test and acceptance criteria.
For example, when adding a new hardware configuration interface, it is not enough to describe it as “support setting parameters.” You also need to define parameter ranges, handling of invalid values, behavior when configuration is repeated, whether calls are allowed before and after initialization, and whether the old configuration is retained on failure.
The purpose of the technical specification is to give every subsequent model modification a basis and to provide a unified standard for human review.
3. Practical Value of Structured Skills: Reduce Ineffective Edits
In testing, structured development capabilities have a clear impact on LLM performance. The “skills” discussed here are not a specific product, but a set of reusable engineering rules and operation templates.
3.1 Brainstorming Stage
This stage is used to explore the problem space, not to require an immediate final solution. The model can help list:
- Possible implementation paths.
- Impact scope.
- Hidden risks.
- Information that needs to be supplemented.
- Existing code that is worth reusing.
However, brainstorming results must be filtered. Not every possibility listed by the model should be treated as fact.
3.2 Specification and Planning Stage
Convert the final solution into a task list, for example:
- Modify public interfaces.
- Add platform adaptation implementations.
- Update the initialization flow.
- Add boundary checks.
- Add unit tests.
- Run static checks.
- Complete compilation for the target platform.
- Perform hardware integration testing.
Task granularity should not be too large. “Complete driver porting” is not a task suitable for direct execution, while “add a platform initialization function,” “replace interrupt registration logic,” and “verify DMA buffer alignment requirements” are easier to check individually.
3.3 Execution and Review Stage
After each small task is completed, review the actual diff instead of letting the model continuously modify dozens of files. The recommended rhythm is:
- Modify a small number of related files.
- Review the changes.
- Run formatting checks or static analysis.
- Compile the corresponding module.
- Run available tests.
- Confirm the result before moving to the next step.
This approach may appear slower on the surface, but it can significantly shorten the time needed to localize problems.
4. Subtask Splitting: Useful for Large Porting Projects, but Guard Against Context Drift
When a project involves dozens of files, multiple platform layers, and many repetitive changes, independent tasks can be assigned to different subagents or separate contexts. For example:
- One task analyzes the old platform interfaces.
- One task reviews hardware differences on the new platform.
- One task generates a test plan.
- One task checks configuration files.
- The main task merges the design and performs final verification.
The advantage is cleaner context. Individual tasks are not overwhelmed by unrelated implementation details, and independent work can be processed in parallel.
However, this also introduces new risks: different subtasks may interpret naming, interface contracts, and error handling inconsistently. Therefore, every subtask must be given unified constraints, including:
- Project directory structure.
- Coding standards.
- Interface naming rules.
- Files that must not be modified.
- Dependencies.
- Output format.
- Acceptance criteria.
After subtasks are completed, the main workflow still needs a consistency check. Multiple results cannot simply be concatenated.
5. How TDD Fits Firmware Scenarios
Firmware development does not always have a complete automated test environment, but test-driven thinking still applies.
5.1 Define Observable Behavior First
For example, for a ring buffer, you should first clarify:
- What is returned when reading from an empty buffer.
- How writing to a full buffer is handled.
- Whether read and write pointers are allowed to wrap around.
- Whether concurrent access requires a lock.
- How zero-length data is handled.
- How insufficient memory is reported.
Then implement the code. This makes it less likely that the model will miss boundary conditions.
5.2 Build Test Doubles for Hardware-Related Code
Register access, time delays, interrupt triggering, and DMA operations are often difficult to execute directly in a host environment. They can be replaced through abstract interfaces or simulation layers. The focus of testing is not necessarily verifying real hardware, but verifying:
- Whether parameters are passed correctly.
- Whether state machines transition as expected.
- Whether error paths are reachable.
- Whether retry counts meet requirements.
- Whether recovery is possible after a timeout.
5.3 Tests Must Not Cover Only the Success Path
Tests generated by LLMs tend to focus on normal cases, so you should actively require coverage of:
- Maximum and minimum values.
- Null pointers and invalid handles.
- Timeouts.
- Repeated initialization.
- Insufficient resources.
- Abnormal hardware status returns.
- Concurrent access from interrupts and tasks.
- Missing configuration or version mismatch.
6. Document Processing Is Critical to Model Accuracy
Chip datasheets, register manuals, display configuration documentation, and boot flow documents are often the most important sources of information in firmware development. However, asking a model to read complex PDFs directly does not produce stable results.
Common problems include:
- Multi-column layouts causing reading order errors.
- Table content being split into unrelated text fragments.
- Headers and footers mixing into register descriptions.
- Timing diagrams in images not being parsed accurately.
- Bit-field names and widths becoming misaligned.
- Cross-references between document sections being lost.
A more reliable approach is to establish a document preprocessing workflow first, converting materials into well-structured Markdown or plain text and splitting them by topic.
7. A Suggested PDF-to-Markdown Workflow
Step 1: Extract Body Text and Tables
First remove repeated headers, footers, table-of-contents noise, and unrelated copyright information, while preserving chapter headings, body text, lists, and table structures. For register tables, preserve the following fields where possible:
- Register name.
- Address offset.
- Bit-field range.
- Reset value.
- Read/write attribute.
- Function description.
- Access restrictions.
Step 2: Fix Structure and Semantics
Automatically converted documents may still contain broken lines, misalignment, and confused table columns, requiring manual or script-based fixes. In particular, check:
- Whether bit-field numbering is continuous.
- Whether hexadecimal addresses have been split apart.
- Whether negative signs and units have been lost.
- Whether attributes such as “read-only” and “write-one-to-clear” are preserved.
- Whether table columns are mismatched after page breaks.
Step 3: Organize Reference Materials by Topic
Do not put hundreds of pages into a single file. Split them as follows:
- Clocks and reset.
- GPIO and interrupts.
- Display controller.
- DMA.
- Power management.
- Boot flow.
- Error codes and debugging notes.
This makes retrieval easier and reduces the chance that the model mixes unrelated chapters together.
For critical registers, it is advisable to create a separate “human confirmation checklist” recording addresses, default values, key bit-fields, and usage restrictions. After the model generates code, verify each item against the checklist.
8. How to Judge Whether the Model Has Truly Completed the Task
“The code has been modified” does not mean the task is complete. At minimum, distinguish between the following states:
- Code has been generated.
- Syntax checks have passed.
- Module compilation has passed.
- Full build has passed.
- Host tests have passed.
- Code has run on target hardware.
- Regression verification has been completed.
Each state requires corresponding evidence, for example:
- Whether compilation was actually executed.
- Whether the correct configuration was used.
- Whether only a single file was compiled.
- Whether the linking stage succeeded.
- Whether tests cover the newly added logic.
- Whether hardware logs match expectations.
- Whether resource usage and boot time were checked.
Without evidence, the model can only say, “Based on code analysis, this may be correct.” It should not draw a direct conclusion.
9. Final Assessment: Treat the LLM as an Engineering Assistant, Not an Automatic Programmer
The real value of LLMs in firmware development lies mainly in information organization, code navigation, solution comparison, repetitive work, and test completion. They can significantly speed up exploration, but hardware manuals, timing constraints, concurrency behavior, and platform differences still require developer oversight.
A more mature way to use LLMs can be summarized as follows:
- Let the model understand the problem before letting it modify code.
- Form specifications and plans before breaking down execution tasks.
- Give every change clear verification criteria.
- Convert complex documents into structured, searchable formats.
- Manually review code related to registers, timing, memory, and interrupts.
- Do not accept completion claims without compilation, test, or runtime evidence.
If these principles are built into team processes, LLMs will no longer be just code generators. They will become engineering assistants that can participate in requirements analysis, implementation collaboration, and quality verification. For complex firmware projects, what really determines the outcome is not “whether the model can write code,” but whether a development system can be established that continuously constrains the model and verifies its results.
