H₂S 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 H₂S (hydrogen sulfide) 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 linear calibration, and reports concentration in ppm over a UART ASCII interface.

Key Specifications

ParameterValue
MCUSTM32G431KB (UFQFPN-32)
CoreARM Cortex-M4F, 170 MHz
Flash / RAM128 KB / 32 KB
Target gasH₂S (Hydrogen Sulfide)
Measurement range0 – 25 ppm
ADC resolution12-bit differential, 8× oversampling
UART baud rate115200, 8N1
Firmware size~96 KB flash, ~7 KB RAM

Design Goals

  1. Accuracy — VREFINT-compensated ADC readings, hardware oversampling to reduce noise floor, two-point calibration to account for sensor-to-sensor variation.
  2. Reliability — RTIC’s static task model prevents stack overflow and priority inversion; Embassy async drivers avoid blocking the executor.
  3. Simplicity — ASCII UART protocol with human-readable commands; external controller drives the calibration procedure.
  4. Size efficiencyopt-level = "z" + LTO; no serde, no telemetry watch channel; 512-byte heap only for format strings.

Signal Chain

H₂S Sensor (electrochemical, current output ~nA–µA)


TIA (Transimpedance Amplifier)     → 0–2 V voltage


AD5545 DAC
    ├── ChA: Gain control (scales TIA feedback, default 100%)
    └── ChB: Offset cancellation (subtracts sensor baseline)


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


Firmware (CalibrationState → ppm conversion)


UART → Host (PC / MCU)

Workspace Structure

gas-sensor-fw/
├── bsp/          Board Support Package — ADC, DAC, SHT45, board init
├── protocol/     ASCII command definitions (Command parser)
├── main-app/     RTIC application — 5 tasks, calibration logic, stability monitor
└── _legacy_src/  Reference — original monolithic firmware

Last updated: February 2026