Beta Solutions Blog

One year developing Firmware with AI

Date:  Mar 13, 2024

Introduction

In our ongoing effort to continuous improvement, we’ve embraced the emergence of Artificial Intelligence and integrated it into our workflow. The adoption of such technologies has improved the quality of our code while also freeing developers to focus on higher level decision making throughout a project. By trialing a number of AI tools, we’ve seen improvements in our development practices, albeit not without encountering a set of challenges.


This piece aims to share how AI has improved our firmware and what we’ve found useful, what AI doesn’t do well and how we’ve mitigated this, and what we hope the next year will bring in terms of Artificial Intelligence with regards to embedded systems firmware.


Although there are a lot of AI tools out there, this article focuses in on our experience with using GitHub Co-pilot

Rinnai HydraHeat™ Hot Water Pump.

How has AI changed the way we develop firmware?


GitHub Copilot is an AI-powered code completion tool that integrates into our code editor (Visual Studio Code). It assists developers with writing code by generating suggestions for small to medium chunks of code by leveraging a generative AI model trained on public code repositories. Copilot predicts and generates code suggestions as developers type. You may have noticed tools in other fields implementing similar features to help predict user actions. Gmail for example are developing a tool to help you draft emails which you can read about
here.


GitHub Copilot can accurately anticipate the developer's next steps based on the context of the code being written. This predictive capability enables software and firmware engineers to focus on higher-level design aspects and complex problem-solving, rather than getting bogged down in repetitive coding tasks. Take this scenario:

A developers needs to write a driver for a TMP451 temperature sensor they are using in a weather station they are developing. They write the function below which reads the temperature back over a communication bus.

HydraHeat™ diagram demonstrating what each component does.


They test the function and if all went well they move on to the next function which is an API to get the humidity. Before AI assistance, the developer would now have to write a very similar function to get the humidity, but with small and important details changed.

With Co-pilot however, it sees how the get temperature function was made and makes a prediction on what the humidity function will be.


The AI suggestion has copied the logic and style from the "get temperature" function but changed the important parts so it is now reading back the humidity. We reviewed this code and it is indeed correct! 


How it Works


This example highlights some important features of developing with AI:


  • Consistently styled code - The code it suggests is written in the same style as the rest of the file. This doesn’t necessarily affect the performance of the code but it does make it easier for developers to read and thus improves the code’s maintainability.
  • No human errors - When developers copy and paste it’s easy to miss or forget to change parts and often leads to code that looks correct but isn’t. This could be reworded to: "This leads to hard-to-diagnose bugs which have a high chance of not being detected until far further down the development pathway.
  • Saved time - It obviously saved time by writing the whole function in seconds, but an underestimated factor is it took less mental energy of the developer to do it. This allows developers to stay focused on the high level architecture and not get bogged down in the details. Of course the details are very important, but it takes a lot less energy to review the function than to write it.


It’s important to mention that even when writing the original temperature function, Co-pilot was making suggestions here too. Co-pilot saw the temperature was calculated above so there is a high probability that we would want to "print" (log) this reading. The handy thing here is it gives a nicely formatted readable message.

HydraHeat™ Hot Water Heat Pump circut board


Another thing that AI does really well is its documentation. GitHub Co-pilot has an inbuilt command specifically to force it to suggest documentation. You can see below that it’s generated a doxygen style comment for our get temperature function.


HydraHeat™ Hot Water Heat Pump showing the  Integrated wireless board


Limitations and Tips

While the integration of AI tools into firmware development has brought significant advancements, it has not been without its set of challenges. These limitations, ranging from issues of code relevance to the intricacies of managing AI-generated suggestions, have necessitated a thoughtful approach to leveraging AI technology effectively.

Where does AI struggle?


By the previous section you might be thinking AI tools could just write the whole program by itself. Fortunately for software developers, it’s not THAT good…. yet. 


Unlike human developers who possess an innate contextual understanding and have project-specific knowledge, AI tools can sometimes offer solutions that are not relevant to the specific problem at hand and for really specific/niche problems, sometimes it just makes stuff ups!


Accurate temperature monitoring Unit


Here is an example where the developer wants to use the law of sines to calculate the ground distance and GitHub Co-pilot just makes up an equation. This points out the importance of code review to add an additional layer of scrutiny, ensuring that AI tools aren’t slowing down and making the development process worse.

 
AI tools need to understand the problem space to generate relevant solutions.This often involves detailed input from developers, which can be time-consuming and seem like a waste of time. However, refining the process of inputting context can markedly improve the quality of their outputs, making them more applicable and useful.


You can see the developer here has given the AI contextual information in the form of a comment explaining the steps to correctly initalise the sensor. Without this the AI cannot really give an accurate suggestion. As you can see its done a pretty good job now that it does have the information.

HydraHeat™ Hot Water Heat Pump Technician App diagram


In the specific case of Github Copilot, it also grabs contextual information from open tabs in the IDE. This gives the AI context beyond other code written in the file. Other tools have specific places to input contextual information. For example Open AI’s GPT playground has a system message for this very reason.

Automated test fixture to ensure quality during production of HydraHeat™ control systems.

Looking Towards the Future of AI in Firmware Development

It's clear that the landscape of AI is continuously changing, with new advancements on the horizon that promise to further revolutionise our development processes. Looking ahead, we anticipate several key trends and developments that could shape the future of firmware development with AI.


  • Specific fine tuned AI Models - While generic AI models are undoubtedly valuable and continue to improve, there is a growing desire for more specialised models tailored for specific tasks, such as embedded system development. Many existing AI tools have been primarily trained on languages like Python and JavaScript, highlighting the need for targeted training on languages and frameworks commonly used in firmware development. By focusing on developing and training AI models that are optimised for the intricacies of embedded systems, we can further improve their contextual understanding of firmware development.


  • User Interface Improvements - While the advancements in AI tools for firmware development have been significant, there is room for improvement in their user interfaces. Tools like GitHub Copilot, while valuable in functionality, can sometimes be unpredictable and their suggestions can end up just being distracting. Similarly, interfaces like the GPT playground have been noted for their complexity and lack of user-friendliness. It is understandable that these tools prioritize functionality over sleek user interfaces, given the complexity of their underlying AI models. However, moving forward, there is an opportunity to enhance the user experience by making AI tools more intuitive and responsive to user needs.


  • Higher Level Descion making - Expanding the scope of AI capabilities in firmware development has shown promise in enhancing lower-level coding tasks. However, when it comes to higher-level decision-making processes such as specification gathering, firmware architecture design, and code reviews, the utility of AI tools has not yet been fully realized. Moving forward, there is a growing anticipation for AI to play a more significant role in these critical areas. By leveraging AI for tasks such as automating specification gathering, optimizing firmware architecture, and automating code review processes, we aim to unlock new efficiencies and insights that can elevate the overall quality and innovation in our development projects. As AI technologies evolve, we look forward to harnessing their potential to drive advancements in these higher-level aspects of firmware development.


Conclusion

Finding the balance between leveraging AI-generated assistance and relying on human expertise is crucial. Developers need to discern when to accept AI suggestions and when to proceed based on their professional judgment and understanding of the project. This delicate balance underscores the increasing importance of establishing comprehensive project specifications at the outset. Doing so lays a good foundation for the collaboration between AI tools and human developers. Clear project requirements early on, allows developers to harness AI technology effectively, enhance productivity, and elevate the overall quality of firmware.


If you have a project that involves firmware development, feel free to reach out to us to discuss the potential benefits we can offer with this AI-integrated approach.

Share by: