How darderik/relay_matrix_edsp works
Project Type and Purpose
• This is an embedded firmware project for an STM32F401 microcontroller that implements a SCPI‐like command interface over USB-serial to control a 4×4 relay matrix via TPL9201 SPI-driven MOSFET arrays, with ATX power-supply integration and basic power management.
Main System Components
a. Hardware Blocks:
• ATX Power Supply (12 V for relays, PS_ON & PWR_OK GPIO lines)
• TPL9201 Driver ICs (Groups A–D, each with NCS & NRST lines)
• Relay Matrix (4×4 crosspoint relays)
• STM32F401XE MCU with UART and SPI peripherals
b. Software Modules (inside MCU):
• HAL/CMSIS Layer (drivers for clock, GPIO, SPI, UART, interrupts)
• “Callbacks” module (UART RX/TX interrupt handlers)
• Parser component (SCPI-like command parsing)
• Command Queue (buffered commands)
• Interpreter (executes parsed commands)
• Actions module (high-level relay control logic)
• NanoTimer (for time-outs and scheduling)
• FSM (system state management: PASSIVE/ACTIVE/ERROR)
• Status Monitor & Response Queue
Relationships & Data Flow
• Serial data arrives on UART → UART RX callback → Parser → command enqueued in Command Queue
• Interpreter dequeues commands → invokes Actions → via STM32 SPI driver → TPL9201 → Relay Matrix
• FSM observes power state (PWR_OK) and interpreter events to switch PSU on/off (via PS_ON GPIO)
• Status Monitor reads current matrix state → enqueues status messages in Response Queue → UART TX callback → PC
Architectural Patterns & Design Principles
• Layered architecture: HAL/CMSIS low-level drivers at bottom, device-specific “components” above, application logic at top
• Modular components: each function (parser, queue, interpreter, actions, FSM) encapsulated in its own folder
• Producer–consumer queues for decoupling parsing, execution, and status reporting
• Finite State Machine controlling global power and error handling
Relevant Technologies & Frameworks
• STM32Cube HAL / CMSIS for peripheral abstraction
• C modules for each “component” (Core/Src/components/*)
• Makefile / VS Code tasks for build and flash
• SCPI-style commands over USB-serial (115200 baud)