A walkthrough of using ChatGPT iteratively to design a USART hardware abstraction layer (HAL) in C. Starting from a rough initial prompt, the author goes through seven iterations, progressively refining the interface to support multiple devices, dependency inversion via function pointers, error codes, and callback support. Manual edits are made where AI output falls short. The final USART HAL is then used as a seed to quickly generate a matching SPI interface, demonstrating how AI can accelerate peripheral HAL generation while still requiring human oversight and domain expertise.

18m read timeFrom embeddedrelated.com
Post cover image
Table of contents
The Iterative AI Prompt ProcessIteration #1 – A general request for a USART interfaceIteration #2 – Multiple Devices and a Simplified InterfaceIteration #3 – Good Bye Strings and CommentsIteration #4 – Nit Picky ImprovementsIteration #5 – Return Codes and Dependency InversionIteration #6 – Manual AdjustmentsIteration #7 – Generate other HALs and InterfacesConclusions