Gas Sensor
STM32G431KB · Firmware v0.1.0
Overview

Project Overview

System summary, key specifications, and design goals.

Summary

This project implements embedded firmware for an electrochemical gas sensor running on an STM32G431KB microcontroller. The firmware is written in Rust using the RTIC 2.1 real-time framework with the Embassy HAL for async peripheral drivers.

The system reads sensor current via a Transimpedance Amplifier (TIA), digitises the signal with a 12-bit differential ADC, applies two-point digital calibration via the AD5545 multiplying DAC, and reports concentration in ppm over a UART JSON interface.

The key design contribution is replacing mechanical calibration potentiometers with a digitally-controlled analogue conditioning stage (AD5545 MDAC), while keeping the calibrated analogue output fully backward-compatible with the downstream host instrument.

Key Specifications

ParameterValue
MCUSTM32G431KB (UFQFPN-32)
CoreARM Cortex-M4F, 170 MHz
Flash / RAM128 KB / 32 KB
ADC12-bit differential, 8× oversampling
DACAD5545 16-bit dual MDAC (SPI)
UART baud rate9600, 8N1
Firmware size~96 KB flash, ~7 KB RAM

Design Goals

  1. Backward compatibility — the calibrated analogue output must remain hardware-compatible with the existing host gas analyser; software-only correction is not viable.
  2. Accuracy — VREFINT-compensated ADC readings, 8× hardware oversampling, and a simultaneous closed-form calibration solution to eliminate DAC coupling error.
  3. Reliability — RTIC’s static task model prevents stack overflow and priority inversion; an IWDG watchdog guards against firmware lockup.
  4. Digital calibration — zero and span points are stored in flash and applied as analogue offsets via the MDAC, replacing mechanical potentiometers.

Signal Chain

Electrochemical sensor (target analyte, current output ~nA–µA)


TIA (Transimpedance Amplifier)           0–2 V voltage


AD5545 Dual 16-bit MDAC
    ├── ChA: Gain control   (scales sensitivity)
    └── ChB: Offset cancel  (subtracts sensor baseline in hardware)


ADC1 (differential PA0⁺ / PA1⁻, 12-bit, 8× oversampling)


STM32G431KB firmware
    ├── Calibration state machine
    ├── PPM conversion
    └── UART JSON output → host instrument

Workspace Structure

fw/
├── bsp/          Board Support Package — ADC, DAC, SHT45, board init
├── protocol/     JSON command codec (serde_json)
└── main-app/     RTIC application — tasks, calibration logic, stability monitor

Last updated: March 2026