Firmware Development with LLMs: From Code Review to a Runnable Game
This article examines how LLM-assisted programming tools handle firmware development, using a brick-breaker game running in a firmware environment as a case study. It covers task decomposition, structured code review, staged logging, pointer lifetime issues after display-mode switching, graphics protocol identifier mistakes, and maintainability improvements such as platform/game separation, explicit state modeling, bounds checking, and frame-rate control. It also outlines criteria for evaluating such tools and practical guidance for developers, concluding that LLMs can support code understanding, debugging, and iterative fixes but do not replace knowledge of memory models, interface specifications, build systems, and hardware runtime environments.
As large models move from “generating code” toward “participating in the full development workflow,” their capability boundary is expanding from ordinary scripts and business pages to complex scenarios such as operating-system boot stages, firmware programs, and low-level graphics applications. Compared with conventional application development, firmware development lacks a complete runtime environment and has limited debugging options. Memory lifetime, protocol call order, and build configuration can all directly determine whether a program starts. Such tasks are therefore well suited to observing the real engineering capability of intelligent programming tools.
This article uses a Chinese brick-breaker game running in a firmware environment as an example. The focus is not on comparing a specific model, but on analyzing whether an intelligent programming tool can complete the loop from code understanding to problem fixing when it faces unfamiliar code, a complex build environment, and real runtime failures.
1. Why Firmware Development Better Tests Large-Model Capability
In desktop or web development, developers can usually rely on mature debuggers, logging systems, and third-party libraries. Even when a program fails, stack traces, exception logs, or automated tests often help locate the problem quickly.
Firmware programs are different. The main challenges include:
- Incomplete runtime environment
The firmware stage usually has no complete operating-system services and lacks common capabilities such as a file system, process management, graphical windows, and standard input/output. Programs need to use boot services and device protocols provided directly by the firmware.
- Limited debugging information
A program may exit immediately after startup, or may show no visible output at all. Developers often have to rely on serial output, memory inspection, or staged logs to determine how far execution has progressed.
- More sensitive resource lifetimes
Structures, buffers, or device description information returned by some interfaces are valid only during specific call stages. If a program caches a pointer that has already become invalid, later access may cause an exception.
- Complex build chain
Source code passing syntax checks does not mean the final image can boot. Configuration files, target architecture, linker scripts, boot media, and firmware images can all cause problems.
Therefore, an intelligent programming tool that can only complete code has limited value. The truly meaningful capability is to understand project structure, analyze execution paths, propose verifiable hypotheses, and continuously revise them based on runtime feedback.
2. Task Design: Do Not Just Ask the Tool to “Write a Game”
If a complex task is stated directly as “please write a firmware game,” the output is often unstable. A more reasonable approach is to divide the task into multiple stages.
Stage 1: Confirm the Environment and Constraints
Clarify the following information first:
- Which type of firmware interface the target runtime environment belongs to;
- Which compilation toolchain is used;
- Who calls the program entry point;
- Whether graphics output uses a linear framebuffer or another drawing method;
- Whether keyboard input comes from a firmware protocol or a custom driver;
- Whether dynamic memory is allowed;
- How the output file is generated and started.
The purpose of this step is not to add formal complexity, but to prevent the tool from making guesses when key assumptions are unclear.
Stage 2: Implement a Minimal Closed Loop First
Do not require a complete game at the beginning. First have the program complete the following in order:
- Output startup logs;
- Obtain the graphics output interface;
- Clear the screen;
- Draw a rectangle;
- Read keyboard input once;
- Enter an exit-capable main loop.
Only after these basic capabilities are verified should you add the ball, paddle, bricks, collision, and scoring logic.
Stage 3: Add Experience Optimizations Last
For example:
- Chinese title and prompts;
- Color and layout adjustments;
- Game speed control;
- Pause and restart;
- Boundary collision optimization;
- Keyboard input debouncing;
- Frame-rate limiting;
- Abnormal exit handling.
This layered approach separates “environment issues,” “protocol issues,” and “business-logic issues,” significantly reducing troubleshooting cost.
3. Code Review Stage: What a Large Model Can Find
In an actual test, the existing source code was first provided in full to the intelligent programming tool for a structured review, rather than immediately asking for a rewrite.
A qualified review process should cover the following modules:
1. Entry Function
Check whether entry parameters are correct, whether startup services have completed, whether there are uninitialized variables, and whether the exit path releases necessary resources.
2. Main Loop
The main loop should have a clear execution order, for example:
Read inputUpdate game stateDetect collisionsClear the old frameDraw the new frameWait for the next frame
If the loop has no waiting mechanism, the program may occupy the processor completely. If drawing happens before updating, the display may lag. If input reading is blocking, the game may lose continuous animation.
3. Graphics Module
Confirm whether drawing coordinates are out of bounds, whether the color format matches, whether the stride of each row is correct, and whether the clear-screen operation covers the entire valid area.
4. Input Module
Firmware input interfaces differ from ordinary operating-system keyboard events. The tool should check how key states are read, how key release is determined, how repeated triggers are handled, and how the exit key is processed.
5. Memory and Pointers
One of the most common problems in low-level programs is an incorrect pointer lifetime. The review should focus on:
- Whether a pointer may be null;
- Whether the data pointed to is still valid;
- Whether an old address is used after an interface call;
- Whether the structure size matches the interface definition;
- Whether buffer capacity has been verified.
Through modular review, the tool can first build a full picture of the project and then move to specific fault localization, instead of blindly modifying a line of code.
4. First Runtime Failure: Why “It Compiles” Does Not Mean “It Runs”
In the test, the program built successfully and was able to start, but it exited shortly afterward. Only the startup prompt appeared on the screen, and then the program stopped working.
This type of problem usually indicates:
- The entry function has executed;
- At least part of initialization succeeded;
- The exception occurs before the main loop or just after entering it;
- The build chain is basically usable, but the runtime state is incorrect.
To improve localization efficiency, the tool can be asked to add staged logs:
[1] Enter entry function[2] Locate graphics interface[3] Query display mode[4] Set display mode[5] Acquire frame buffer[6] Initialize input[7] Enter game loop
If the log stops between step 4 and step 5, the problem scope can be narrowed to display-mode switching and framebuffer acquisition, without continuing to suspect the game logic.
Typical Problem: Old Pointer Invalid After Mode Switching
Some firmware graphics interfaces return description information when querying the display mode, which may include the framebuffer address, resolution, and pixel format. A mode-switching operation may reconfigure the display device and invalidate previously obtained description information.
If the code execution order resembles:
Query display informationSwitch display modeUse previously saved display information
there is a risk of accessing an invalid pointer.
A safer flow should be:
Query the current modeSelect the target modeSwitch to the target modeQuery display information againRead the new framebuffer addressStart drawing
This kind of error is not necessarily common in high-level languages, but it is very common in firmware environments. The value of an intelligent programming tool is that it should not only point out “this may crash,” but also explain why it crashes in combination with the call order and provide a verifiable fix.
5. Second Problem: Incorrect Graphics Interface Identifier Configuration
When the program no longer crashes but still cannot display graphics, the problem has usually shifted from memory safety to interface identification or protocol acquisition.
Graphics output in a firmware environment is generally located through a protocol identifier. A project may contain multiple similar identifier definitions at the same time. If the wrong identifier is used, the program may exhibit:
- Interface lookup failure;
- A null pointer being returned;
- An incompatible structure being found;
- The program continuing to execute but producing no image;
- The call result appearing successful while no valid output is produced.
At this point, troubleshooting should focus on:
- Whether the protocol identifier comes from the current firmware interface specification;
- Whether the identifier declaration and the called function belong to the same version;
- Whether the structure definition matches;
- Whether the return status is checked correctly;
- Whether the obtained interface pointer is null;
- Whether the graphics mode is actually switched successfully.
The code should not simply contain:
LocateGraphicsInterface(&graphics);graphics->SetMode(graphics, mode);
A more reliable implementation should check the status of each step:
status = LocateGraphicsInterface(&graphics);if (Error(status) || graphics == NULL) {Log("graphics interface unavailable");return status;}status = graphics->SetMode(graphics, mode);if (Error(status)) {Log("failed to set display mode");return status;}
For low-level programs, error handling is not an add-on feature; it is a primary means of locating problems.
6. From “Runnable” to “Maintainable”: Focus of the Second Optimization Round
Getting the program to start is only the first stage. To make it a relatively complete engineering project, structured optimization is still needed.
1. Separate Platform Code from Game Logic
It is recommended to split the code into:
- Startup and platform initialization;
- Graphics interface wrapper;
- Input reading;
- Game state management;
- Collision detection;
- Drawing functions;
- Logging and error handling.
The benefit is that even if the display interface is replaced in the future, the game rules do not need to be fully rewritten.
2. Define State Data Explicitly
Game objects should contain information such as position, velocity, size, and state. For example:
Ball:Position, velocity, radius, whether it is movingPaddle:Position, width, height, movement speedBricks:Position, size, whether alive, colorGame:Score, lives, pause state, end state
The clearer the state data, the easier it is to test collision and drawing logic.
3. Prevent Coordinate Out-of-Bounds
When drawing a rectangle, ensure:
x >= 0y >= 0x + width <= screen_widthy + height <= screen_height
If coordinates are produced by accumulating velocity, boundary clipping must be performed again after the update. Otherwise, a negative coordinate may cause an out-of-bounds write to the framebuffer, eventually appearing as screen corruption, freezing, or even a system-level exception.
4. Control Frame Rate
Firmware programs usually do not have a mature high-precision timing framework. Refresh rhythm can be controlled through a timer service or a simple delay, but the delay should not directly block all input processing.
A more reasonable structure is:
Record the current timeRead inputUpdate state according to the time differenceDraw the current frameWait for the next update time
This avoids large speed differences when running on different devices.
7. How to Evaluate the Real Capability of Intelligent Programming Tools
A single successful run does not prove that a tool is reliable in all scenarios. Evaluation should focus on the following indicators:
1. Whether It Can Understand the Complete Project
A good tool should not focus only on the current file. It should identify dependencies and call order between modules.
2. Whether It Can Propose Verifiable Hypotheses
For example, it should explain that “continuing to use old display information after mode switching may cause an exception,” rather than merely providing a piece of unexplained modified code.
3. Whether It Can Adjust Judgments Based on Logs
An incorrect first guess is not the main concern. The key is whether, after receiving runtime results, it can narrow the scope and correct its direction.
4. Whether It Can Control the Scope of Changes
Low-level code is not suitable for large-scale rewrites. A safer approach is to make local fixes first and refactor only after confirming that the problem has disappeared.
5. Whether It Respects the Verification Loop
After every modification, the program should be rebuilt, started, observed through logs, and checked visually. A “fix” without verification is only a guess.
8. Practical Advice for Developers Using Large Models
Finally, this type of task can be summarized into a general method:
- Provide context before goals: Explain the environment, interfaces, build method, and constraints.
- Review before modifying: Let the tool build a problem list instead of rewriting immediately.
- Run in stages: Verify startup first, then graphics, input, and the main loop.
- Increase observability: Use serial logs, stage markers, and error codes.
- Fix one class of problem at a time: This makes it easier to determine whether a fix is truly effective.
- Keep rollback-capable versions: Once low-level changes expand in scope, problems can quickly become more complex.
- Manually review critical code: Especially pointers, memory, protocol calls, and boundary checks.
- Write success criteria clearly: For example, “it can start, display graphics, accept input, and exit normally,” rather than vaguely saying “complete the game.”
Overall, the value of large models in firmware development is not just generating hundreds of lines of code. It is the ability to participate in code understanding, problem localization, debugging collaboration, and iterative optimization. When tasks are broken down into verifiable engineering steps and supported by sufficient logs and human review, intelligent programming tools can indeed help developers handle low-level work that was previously tedious. However, they still cannot replace a basic understanding of memory models, interface specifications, build systems, and hardware runtime environments. The truly efficient approach is to let human experience define the boundaries while the model expands analysis and implementation efficiency.
