LabWired The easy way to build hardware
RC circuit voltage trace beside a firmware GPIO edge on the LabWired oscilloscope.

Learn / Track 03

Test an STM32 firmware loop against an RC circuit

You can test an MCU without treating every analog input as a constant. The STM32F401 firmware toggles GPIO PA5. A 10 kΩ resistor and 100 nF capacitor filter the edge. ADC1 channel 0 on PA0 reads the voltage. The STM32 RC example has a native command-line test. The deployed Playground does not yet contain this exact lab.

The important result is not a screenshot of a curve. The firmware checks whether the measured RC time constant is near 1 ms and prints its verdict over USART2. The published example README, source firmware, system manifest, and five-assertion test define the workflow. These are inspectable source files, not an illustration of a possible future feature.

Circuit and firmware connections

ConnectionMeaning
STM32 PA5 → Vgpio → 10 kΩ resistor → outFirmware-driven step and RC input.
out → 100 nF capacitor → groundOne-pole low-pass filter.
out → STM32 PA0 / ADC1 channel 0Firmware reads the circuit response.
USART2Firmware prints measured time, ADC code and voltage.

The browser analog adapter accepts the same inline netlist as the native in-core solver:

Vgpio in 0 dc 0
R1 in out 10k
C1 out 0 100n

The manifest connects board.gpio.pa5 to source Vgpio and the v(out) probe to board.analog.pa0_volts. The model uses a 100 µs step and a 3.3 V high level. The circuit is linear. It does not use a vendor SPICE library or a nonlinear diode/transistor model.

What the firmware checks

The firmware uses TIM2 as a 1 MHz clock. It changes PA5 every 5 ms and samples PA0 every 500 µs. After a rising edge, it finds where the sampled voltage crosses 63.2% of 3.3 V (about 2.09 V). It interpolates between the two ADC samples around that crossing and writes tau_us=<number> to UART. It also writes rc_shape=ok if the samples rise monotonically and the crossing is in the configured interval.

For an ideal first-order RC step, the voltage is

Vout(t) = 3.3 V × (1 − exp(−t / (R × C)))
R × C   = 10,000 Ω × 0.0000001 F = 0.001 s
Vout(1 ms) ≈ 2.09 V

The example’s test.yaml asserts the UART banner, sample output, tau_us in the 800–1199 µs range, rc_shape=ok, and the expected maximum-step stop reason. The example README records a 5/5 result, with reported crossing times of 998–1006 µs. Those are native model-test results; they do not certify a physical PCB.

Test whether the electrical model responds to a changed part

The merged native analog-adapter regression test performs an executed negative control, not only a suggested test. It drives the same 3.3 V step through a 10 kΩ resistor and measures the modeled output after 1 ms. With a 100 nF capacitor, the expected output is approximately 2.09 V (1 ms time constant). With only the capacitor changed to 1 µF, the expected output is approximately 0.314 V (10 ms time constant). The test checks both results within 0.02 V and requires the first reading to exceed four times the second. This catches a model that ignores the capacitor value or returns a fixed curve. The regression PR #1840 merged on November 12, 2026 after its required CI checks passed.

To run the lower-level regression independently from the firmware CLI acceptance test:

cargo test -p labwired-core --test analog_adapter rc_capacitance_perturbation_changes_the_measured_response

This is analog-adapter model evidence. It is not a second run of STM32 firmware, not a verified browser execution of this STM32 lab, and not physical hardware acceptance.

A separate firmware-level negative control changes the capacitor in the full STM32 example to 200 nF. Keep the expected 800–1199 µs interval unchanged. Its ideal time constant becomes 2 ms. A valid test should now fail the original acceptance interval. This is a suggested fault-injection check, not a claim that the changed configuration has passed a separate CI test.

Browser availability and a working alternative

The STM32 RC example has a native integration test. It is not available as a bundled browser lab on November 11, 2026. The old link fell back to STM32F103 Blinky. Do not treat that screen as a simulated RC circuit.

For a different, working browser analog circuit, open the Arduino Nano capacitive-touch lab. This lab runs a CapacitiveSensor sketch against a 1 MΩ resistor and a touch pad. Its oscilloscope shows D2 pad voltage and D4 drive voltage. The deployed browser displayed both channels and sample data on November 11, 2026.

  1. Open the capacitive-touch lab and start the firmware.
  2. Inspect the D2 and D4 signals on the same scope.
  3. Press and hold the touch pad. Compare its response with the released state.

This is not a substitute for the STM32 RC test. Run the native test below for its 1 ms acceptance result. Browser analog circuits do not support nonlinear SPICE devices, vendor .include files or AC/DC sweeps. See the mixed-signal adapter guide for exact limits.

Run the acceptance test locally

From a clone of labwired-core, install the Cortex-M target and build the actual bare-register firmware:

rustup target add thumbv7em-none-eabi
cargo build -p rc-oscilloscope-lab --release --target thumbv7em-none-eabi
labwired test --script examples/rc-oscilloscope-lab/test.yaml --analog-trace out.csv

This uses the example’s system.yaml and asserts the result from the UART output. The optional out.csv shows the analog trace at the modeled 100 µs sample interval. The CLI integration test checks that the command returns a passing result.json and that its UART time constant is inside the interval. It requires the example firmware ELF to exist first.

An imported KiCad board needs more checks. Preserve source pad-to-net mapping. Resolve all required active component models. Prove that the imported system runs. Parsing a schematic is not evidence of a working full-board simulator. See the KiCad import and coverage guide for the separate import and model-status checks, or the circuit simulator overview to choose a starting point.

Andrii Shylenko
Andrii Shylenko

Founder, LabWired.