<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MCUcraft</title>
    <description>The latest articles on DEV Community by MCUcraft (@mcucraft).</description>
    <link>https://dev.to/mcucraft</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4261031%2F5314d50f-fcbd-45b6-81a4-8f931955c75b.png</url>
      <title>DEV Community: MCUcraft</title>
      <link>https://dev.to/mcucraft</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mcucraft"/>
    <language>en</language>
    <item>
      <title>"It compiles" is not "it works": how we test AI-generated firmware against the rules you wrote</title>
      <dc:creator>MCUcraft</dc:creator>
      <pubDate>Mon, 23 Nov 2026 19:00:35 +0000</pubDate>
      <link>https://dev.to/mcucraft/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules-you-wrote-420i</link>
      <guid>https://dev.to/mcucraft/it-compiles-is-not-it-works-how-we-test-ai-generated-firmware-against-the-rules-you-wrote-420i</guid>
      <description>&lt;p&gt;When an AI writes firmware for your device, the first question is not "is the code pretty?". It is: &lt;strong&gt;does the device do&lt;br&gt;
what I asked?&lt;/strong&gt; A firmware that compiles, passes a linter and reads well can still leave the heater off forever, never close&lt;br&gt;
the gas valve, or keep a buzzer screaming after the air is clean again.&lt;/p&gt;

&lt;p&gt;This post explains how MCUcraft checks that, what the check catches, and what it does not.&lt;/p&gt;
&lt;h2&gt;
  
  
  From your sentences to numbered rules
&lt;/h2&gt;

&lt;p&gt;You describe the device in a chat: &lt;em&gt;"Air quality monitor for my workshop, on an STM32. It measures CO2, temperature and&lt;br&gt;
humidity, shows them on a small OLED display, and sounds a buzzer when CO2 goes above 1500 ppm. Powered from USB-C. I want a&lt;br&gt;
custom PCB."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before any code exists, those sentences become &lt;strong&gt;rules with an identifier&lt;/strong&gt;, each one tied to the words you used: the CO2&lt;br&gt;
limit at 1500 ppm, the buzzer, what happens when the sensor stops answering. Where you did not say something&lt;br&gt;
(how far below 1500 ppm the alarm should clear, for example), the generator picks a value and &lt;strong&gt;writes it down as an&lt;br&gt;
assumption&lt;/strong&gt;, in the code and in the project, so you can correct it.&lt;/p&gt;
&lt;h2&gt;
  
  
  The code has to say where each rule lives
&lt;/h2&gt;

&lt;p&gt;The firmware generator does not just write code. For every rule it &lt;strong&gt;declares where it implemented it&lt;/strong&gt;: which file, which&lt;br&gt;
function. Then a deterministic check verifies the claim: the function exists, in that file. A rule that has no place in the&lt;br&gt;
code is not silently dropped: it is reported.&lt;/p&gt;

&lt;p&gt;On top of that, a set of checks reads the code itself: limits compared in the right direction, the state machine the&lt;br&gt;
project declared, outputs that actually move, the power budget. They are useful, but they share a weakness we measured&lt;br&gt;
early: &lt;strong&gt;they read the text of the code&lt;/strong&gt;. Green means "not broken". It does not mean "does what you asked".&lt;/p&gt;
&lt;h2&gt;
  
  
  Running the whole firmware on a PC
&lt;/h2&gt;

&lt;p&gt;So the last check does not read the code: it &lt;strong&gt;runs it&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The whole firmware is compiled for the PC, with a stand-in for the Arduino core.&lt;/li&gt;
&lt;li&gt;The one file that talks to the hardware (the drivers) is replaced by a stub. When the firmware asks "what is the CO2?",
the stub answers with the value the test script says, in physical units (ppm, °C, mA). Every command the firmware sends
to an output (buzzer on, relay off) is recorded with its time.&lt;/li&gt;
&lt;li&gt;Time is simulated, so a 15-minute rule takes milliseconds to test.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the stub the bench generates for the air quality monitor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/parts.cpp as compiled on the PC (generated; helper names translated)&lt;/span&gt;
&lt;span class="cp"&gt;#include "parts.h"&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="nf"&gt;bench_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// the scenario's value right now&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;  &lt;span class="nf"&gt;bench_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// logged with the simulated time&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt;  &lt;span class="nf"&gt;parts_begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="nf"&gt;read_co2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;bench_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"co2"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="nf"&gt;read_temperature&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;bench_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"temperature"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;  &lt;span class="nf"&gt;drive_buzzer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;bench_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"buzzer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mf"&gt;1.0f&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scenarios are written &lt;strong&gt;from your rules, not from the code&lt;/strong&gt;: a model reads the project's sentences and the list of&lt;br&gt;
things that can be measured and driven, and writes scripts like this one, from the diesel tank example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"V-01.over"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"rules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"A#0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"R-b8a7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"V-01"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"assumptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"fuel_level below 20 %: just beyond -&amp;gt; alarm"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"steps"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"t_ms"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="nl"&gt;"set"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"fuel_level"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;20.0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"t_ms"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;903000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"set"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"fuel_level"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;19.8&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"expect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"what"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alert"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"sent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"from_ms"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;903000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"to_ms"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1806000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"about"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fuel_level"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A quarter of an hour in, the level drops just below 20 %, and the alert must go out within the next 15 minutes. The model&lt;br&gt;
never sees the firmware, so it cannot copy its mistakes. Each scenario also states the assumptions it made, because those&lt;br&gt;
are what you might want to correct.&lt;/p&gt;

&lt;p&gt;The timing margin is set by the judge, not by the scenario: right after a value changes, the device gets the time it needs&lt;br&gt;
to read the sensor and react before anything counts as a failure.&lt;/p&gt;

&lt;p&gt;Besides the scenarios built from your rules, the same run checks a few things every device should do: outputs in a safe&lt;br&gt;
state at power-on, values kept inside their limits, no surprises under random sequences of inputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  A pass, and a fail
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pass.&lt;/strong&gt; The diesel tank levels example (three tanks, one level sensor each, data every 15 minutes): the firmware compiles,&lt;br&gt;
and &lt;strong&gt;10 of 10 scenarios pass&lt;/strong&gt; on the PC. One rule is listed as &lt;em&gt;not proven by any scenario&lt;/em&gt;: it describes the tanks'&lt;br&gt;
geometry and the router distance, which no behaviour test can check. The verdict says so instead of hiding it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fail.&lt;/strong&gt; The workshop air quality monitor. The scenario was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;at 0 s CO2 = 1500 ppm · at 3 s CO2 = 1515 ppm · at 6 s CO2 = 1350 ppm&lt;/p&gt;

&lt;p&gt;expected: buzzer &lt;strong&gt;off&lt;/strong&gt; from 6 s to 9 s&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The firmware's own assumption is that the alarm clears at or below 1450 ppm, and 1350 ppm is well below it. On the PC the&lt;br&gt;
buzzer &lt;strong&gt;stayed on&lt;/strong&gt;. The project page shows exactly this, with the verdict &lt;em&gt;"Firmware builds, some tests fail"&lt;/em&gt;. We did not&lt;br&gt;
re-run the generation until the verdict turned green and then show only that one: the example is public as it came out.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the verdict can be
&lt;/h2&gt;

&lt;p&gt;Every project shows one of four verdicts, with the reason:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;verdict&lt;/th&gt;
&lt;th&gt;what it means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Firmware passes its tests on the PC&lt;/td&gt;
&lt;td&gt;it compiles and every scenario that ran passes; rules no scenario can prove are listed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firmware builds, some tests fail&lt;/td&gt;
&lt;td&gt;it compiles, and at least one scenario fails: which one, with the script&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firmware builds, not tested yet&lt;/td&gt;
&lt;td&gt;it compiles, but some rules were not exercised by any scenario that ran&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firmware does not build&lt;/td&gt;
&lt;td&gt;the compiler's errors&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Does it catch real bugs?
&lt;/h2&gt;

&lt;p&gt;We measured it before turning it on. On a training glove we had checked by hand, the scenarios written by the model gave&lt;br&gt;
the same verdict as ours in &lt;strong&gt;12 of 12&lt;/strong&gt; cases, and the run showed that the exercise phase never started, although every&lt;br&gt;
code-reading check was green. Then on four projects from earlier runs it found a real defect in &lt;strong&gt;all four&lt;/strong&gt;, for example a&lt;br&gt;
gas valve that did not close from the phone, a compressor monitor that never counted its starts, and an oven that missed a&lt;br&gt;
short button press.&lt;/p&gt;

&lt;p&gt;And one lesson that changed how we fix things. A firmware once had six &lt;code&gt;write_heater(false)&lt;/code&gt; and no &lt;code&gt;true&lt;/code&gt;: the heater never&lt;br&gt;
turned on. The model had not made a mistake: the contract told it &lt;em&gt;"when temperature leaves its declared limits, turn the&lt;br&gt;
heater off"&lt;/em&gt;, and on a temperature &lt;strong&gt;range&lt;/strong&gt;, "leaves its limits" is true on both sides. The fix was the sentence, not the&lt;br&gt;
model. The check that saw it stays, so if the same mistake is born somewhere else, it is caught there too.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does not prove
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The wiring.&lt;/strong&gt; Pins, signal levels and the conversion from raw readings to ppm or °C belong to the driver, which the stub
replaces. Those are checked against the schematic and the parts' datasheets, not here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real hardware.&lt;/strong&gt; Timing on the real chip, noise and a sensor that lies are outside a PC run. When a simulator of the
board is available, the firmware also boots there; otherwise the verdict says it was not judged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rules without a measurable effect.&lt;/strong&gt; "The enclosure fits on a DIN rail" is not a behaviour. These rules are listed as
not proven, never counted as passed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you take home
&lt;/h2&gt;

&lt;p&gt;The firmware as a PlatformIO project (ZIP), the parts list as an Excel file or a KiCad-style CSV, and the KiCad files of the&lt;br&gt;
schematic and, when the project has one, of the board. You can open, build and change all of it without MCUcraft.&lt;/p&gt;

&lt;p&gt;The firmware uses the Arduino framework, built with PlatformIO (the ESP32 Arduino core, STM32duino on STM32). Native ESP-IDF&lt;br&gt;
projects or hand-written FreeRTOS tasks are not generated today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;The examples are public and open without an account: each one shows its parts list, board, firmware and verdict, green or&lt;br&gt;
not. If you think a scenario is wrong, that is useful too: the scenario's assumptions are written next to it, and you can&lt;br&gt;
correct them in the chat.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://mcucraft.com/?examples=1" rel="noopener noreferrer"&gt;See the examples&lt;/a&gt; · &lt;a href="https://mcucraft.com/compare" rel="noopener noreferrer"&gt;How MCUcraft compares&lt;/a&gt;&lt;/p&gt;

</description>
      <category>embedded</category>
      <category>firmware</category>
      <category>testing</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
