How stmicroelectronics/stmems_finite_state_machine works
Project type and purpose
• This is an open-source example/tutorial repository, demonstrating how to configure and use the Finite State Machine (FSM) feature built into various STMicroelectronics MEMS sensors.
• It is not a monolithic application but a collection of “application_examples” (C headers + .ucf files you compile into MCU firmware) and “configuration_examples” (.ucf snippets you load into sensors with ST tools).
File structure
• Top level
• README.md, CONTRIBUTING.md, LICENSE
• application_examples/…
• configuration_examples/…
• application_examples/:
• One folder per sensor (e.g., asm330lhbx, lsm6dso, st1vafe3bx, etc.)
• Within each, subfolders for individual use-cases (Motion-Stationary, Shake, Freefall, etc.), each containing a C header (example code snippet) and a .ucf file (FSM configuration)
• configuration_examples/:
• Several FSM design examples, each with a utils subfolder of .ucf files
README insights
• Explains FSM concept: you offload simple motion-pattern detection to the sensor’s on-chip FSM
• Host CPU loads .ucf into the sensor, then reads results or handles interrupts from the sensor
Main components
a. Host MCU or application processor
– Running ST sensor driver library + example code (from application_examples/*.h)
– FSM config loader module (reads .ucf files, writes config registers over bus)
– Main application logic (polls or responds to sensor interrupts)
b. Communication bus
– I²C or SPI link connecting MCU ↔ sensor
c. ST MEMS Sensor
– On-chip elements:
• Sensor data block (accelerometer, gyroscope)
• FSM block (user-defined states/transitions loaded via .ucf)
• Interrupt generator or status registers
d. Configuration tool (optional external component)
– ST’s Unico GUI or MLC/FSM tool that prepares .ucf files
Relationships and data flow
• Startup: MCU loads .ucf into sensor FSM via I²C/SPI
• Sensor FSM block continuously processes raw accelerometer/gyro data internally
• When a pattern is detected, FSM sets a status bit and/or fires an interrupt line to MCU
• MCU reads status registers or handles interrupt → runs host logic (e.g., toggles LED, sends message)
Architectural patterns and design principles
• Push-down FSM: shift repetitive sensor-data processing out of host into sensor to save power
• Separation of concerns:
• Configuration layer (.ucf files in configuration_examples/)
• Application layer (example C code in application_examples/)
• Hardware abstraction (sensor driver library)
• Reusability: a single bus-driver + config-loader module supports all sensor folders
Technologies/frameworks/libraries
• C header files (.h) for snippet examples
• UCF (Universal Configuration Format) files for FSM definitions
• ST sensor driver library (I²C/SPI bus abstraction)
• External FSM/MLC tool (Unico)
Elements
• Host MCU (software modules: Bus Driver, Config Loader, Main App)
• Communication Bus (I²C/SPI)
• MEMS Sensor (Sensor Core, FSM Core, Interrupt Line)
• External FSM Configuration Tool (optional)
• Config upload (.ucf → sensor registers)
• Sensor data flow (accelerometer → FSM Core)
• Event notification (FSM → MCU via interrupt/status read)
• Blue for host-side software components
• Green for on-chip sensor blocks
• Gray for configuration files/tools
• Orange for physical connections (bus, interrupt line)