r/embedded • u/kbot_numberb • Apr 22 '26
AI in embedded design work
Hi! I work in FreeRTOS based embedded systems and recently started using Claude. It has mainly been helpful in ancillary work making python tools, but the only benefit I get from it in the embedded space is the auto-complete.
I am looking for courses or workshops that would help my understanding of where / how it could be used to speed up the work that I do. I did find Beningo's course on it and am considering that, but also would like to find other options. Hoping to convince co-workers to try different courses and we could pool our learnings afterwards.
any recommendations you have tried that dove deep and helped your adoption of AI?
8
u/tonyarkles Apr 22 '26
While I don’t have a particular course or workshop to point you at, I can share the #1 “trick” that has added a ton of value to my workflow using Codex or Claude: working through design documentation/implementation plans for non-trivial features before building them. Markdown, right in your git repo. Write up a rough first draft and use whatever LLM to expand and iterate on it. You’re going to miss some details that the LLM will find. The LLM will miss some details that you will find. Go through a couple of rounds of it and you’re going to have a really solid plan. Get the LLM to put together fine-grained implementation steps.
After you’ve got that document, it’s up to you whether you want to write the code yourself or get the LLM to do it. It goes either way for me, depending on a bunch of factors. If you do get the LLM to do it, though, having that doc together ahead of time means that your implementation prompts end up being “Go ahead and build phase 1 from @add-tcp-radio-bridge.md” followed by reviewing the patch before committing it.
Close second: debugging. I have gotten a ton of mileage out of prompts like “today we had something unexpected happen. When we did X we expected Y to happen, but instead we observed Z. The entry point for this is in receive_command() in @commandlistener.c and the unexpected log message we saw was in @firezemissiles.c line 78. Can you trace through the execution flow from receive_command() and figure out how we could end up getting that log message? It doesn’t make sense to me yet. Write your analysis into @bug123-no-missile-fire.md.”
After there’s a first cut analysis, ask more questions and iterate a bit.
If you have a stack trace from GDB or similar, include it. I have gotten amazing results from a 1-line problem description and a stack trace. Like… one example that comes to mind was a hard crash on an embedded Linux process. Codex came back with something like “here’s the most likely scenario: the function that was executing during the crash implicitly expects polygons to have a CCW winding order and it looks like it will walk past the end of the array if you give it a CW polygon instead. The function is receiving those polygons through the event bus in FooPolygonEvent messages. The code that generates the input polygons is in foo.c:87. The code generating the polygons does correctly make them CCW but only if the implicit assumption that the two messages that establish the bounds of those polygons have monotonically increasing timestamps. If [other piece of code several events upstream] happens to receive the timing messages out of order from the network (it can happen), you’ll end up with a reversed polygon and hit this undefined case.”
I was shocked. It brought receipts (specific file/line markers) throughout and when I manually traced through the execution flow in my head, it made 100% perfect sense. It won’t always. Sometimes they do hallucinate and you need to be mindful of that. The results are often phenomenally good though.
2
u/oceaneer63 Apr 22 '26
All good points, and I had some similar experiences including a stack growth/overrun issue where the LLM correctly identified a DSP co-processor in the MCU as the source of the problem because it recognized its stack frame pattern. I have done some basic LLM code writing tests such as asking it to implement X-modem for me in C/C++. The results have been encouraging. I also am 'collaborating' with it now to review a large, multi-layered function library for consistency and clean-up including identifying cases where lower layer code such as core code references chip or board level capabilities and correcting that.
Ultimately, my theory is that LLM will be useful for writing new code as long as you keep the LLM extremely 'grounded', that is asking it to strictly stick with your established architecture and always make use of your existing function library / API rather than starting to twiddlenMCau registers directly.
I say its a theory because I dont yet have proof this will actually work and be productive. My AI working environment is Google Gemini with a custom 'gem' that contains all the documentation, instructions and both the library code and headers to serve as the knowledge base for the LLM. I choose Gemini in part because I understand it may have the biggest context window of the LLM and so can work with the biggest set of knowledge to keep it grounded.
But that all said, I still consider myself a newbie when it comes to AI supported embedded code development.
1
u/tonyarkles Apr 22 '26 edited Apr 22 '26
Yeah, wholeheartedly agree. A month or two ago I had a really interesting experience that was simultaneously helpful and hilariously bad. Working on a linux driver for a MIPI camera connected through a GMSL2 serializer/deserializer. The vendor provided us with a bunch of poorly documented “vendor-grade” initialization code for the three chips. It wasn’t working consistently.
I threw Codex at the problem in the background while I was doing my own debugging. It came back with a pretty solid analysis of what was probably happening and a list of register names/addresses/values that it suggested I cross-check. The serializer and deserializers in this case have NDA’d datasheets, so I was somewhat surprised that it knew them all and what the values should be. The plan seemed solid, though, and the explanation of what it was looking for was logical and, honestly, appreciated because I don’t have a ton of experience with MIPI and GMSL (I was helping out a colleague who was stuck).
When I go to start fetching the register values… I get completely different answers than Codex had said I should get. I pull up the datasheet and start cross-checking, only to discover:
yes, the proposed plan was solid
yes, those were the right register names to look at
…all of the register addresses and values were completely hallucinated
When I pushed back a little bit it did come back and admit that it didn’t have access to the actual datasheet and had put together the register names based on forum posts, and couldn’t actually tell me why it thought those were the right addresses and values.
It ended up being useful anyway, one of the register names it told me to look at indeed indicated that the initialization code was misconfiguring the serializer. It sure was a good reminder though that you can’t take any of this stuff at face value without looking at it critically.
Edit: oh, one more thing that I noticed in your post: the comment about the biggest context window. I don’t disagree, but I will also point out that managing what is and isn’t in the context window seems to be a pretty significant and important skill. Having a big context window is great iff you make sure it has lots of relevant information in it and not too much irrelevant information. A few times I have forgotten to start a new session when switching between two very different and independent modules and have been frustrated that it kept wanting to put code in module A even though I’d told it we were working on module B. Poor context management, poor results.
1
u/oceaneer63 Apr 22 '26
I have seen some register/bit hallucinations as well. Gemini advised me to put the particular datasheets I want it to use in the knowledge base for the project, then instruct it to only use that documentation. Just one more step of 'grounding' the LLM.
1
u/thegreatunclean Apr 23 '26
If you can close the feedback look with automated testing and adversarial reviews it's like unlocking a superpower. The model can iterate on code to debug issues hands-off and then argue with itself about whether whatever solution it finds is fit-for-purpose. I've had multiple debugs that end up with "The literal fix is X, but Y and Z indicate a structural / algorithmic mistake in the design and it should be properly addressed at line L".
1
1
u/b1ack1323 Apr 23 '26
I have TCP on my Oscilloscope and Power Supply, I have tied that to Warp and had it build, run debug and check the oscilloscope and toggle IO with the power supply.
Have found some really niche bugs that would have taken me a while to tease out almost fully autonomous.
Just today I fixed a comms issue between two binary devices with Warp, matching some variables and doing live hardware tests with GDB on both sides.
It’s definitely a time saver for some things.
0
u/keitarusm Apr 22 '26
I've been playing with this a lot. I get the feeling it's super controversial. AI can now use all of the same tools I do to look at hardware. Even my MSO. For me the no brainer piece is to use it to automate the simple/tedious stuff. People will probably argue to use scripts instead, but the major difference is that the AI can run those tasks and when it runs into a problem it doesn't just complain to the user, it fixes it, or tries again, it troubleshoots. All by itself. I've been using it as a layer on top of my build system. I can just prompt 'check this firmware on our target' and it will build, flash, collect debug output or logic analyzer data or Wireshark capture whatever. It gives me a nice quick summary, and I can look at the actual results at my leisure. If you're looking at a small tweak, it understands the firmware and expected output just as well as I do. I can do all these things myself. It would probably take me less than a minute. The AI does it in seconds. Over the course of the workday that really adds up for me. If you haven't decided on your provider yet, I can usually do less than 1 hr of real work on Claude Pro before hitting usage limits. I have never once hit a usage limit with Codex and ChatGPT Plus. The output is identical in my use case.
22
u/Dependent_Bit7825 Apr 22 '26
I've had stunning success with refactors and with device drivers.
For refactors, a detailed prompt that explains the commonality you want to surface between different pieces of existing code, perhaps along with a notion of the future API can get you very far.
For drivers, I can usually that say "I need a driver for the xx chip. I have a similar driver in the repo for you that works. Please model the API on yy. Make it a polling/interrupt driver and only access SPI/i2c through my existing hal so that the driver is portable"
Sometimes such a driver will work right away. Often they are partially borked, but not tragically so. And just getting the boilerplate and register definitions in place is a huge time saver.