Python implementation of ST Microelectronics' Motor Control Protocol for STM32-based motor controllers. This project provides tools and utilities for communicating with STM32 ESCs (Electronic Speed Controllers) via serial over the ASPEP (Asymmetric Serial Packet Exchange Protocol).
Work in Progress - This project contains Python scripts for:
- ✅ Serial communication with STM32 motor controllers
- ✅ Motor start/stop commands
- ✅ Basic velocity control
- 🟡 Monitoring and data acquisition (partial)
- ❌ Full registry service (not implemented)
- ❌ Datalog service (not implemented)
pip install stm32-motor-control-protocolOr with uv (faster):
uv add stm32-motor-control-protocolgit clone --recurse-submodules [email protected]:shanemmattner/stm32_motor_control_protocol.git
cd stm32_motor_control_protocol
uv sync- STM32G431-based ESC board
- BLDC motor with hall sensors or encoder
- 24V DC power supply
- USB serial connection
from st_mcp.minimal_motor_control import MinimalMotorControl
# Connect to motor controller
controller = MinimalMotorControl(port="/dev/ttyACM0", baudrate=1843200)
controller.run()This will:
- Establish serial connection
- Perform beacon handshake
- Configure velocity mode
- Turn motor on
Press Ctrl+C to stop and exit safely.
.
├── st_mcp/
│ ├── minimal_motor_control.py # Working example script
│ └── commands/
│ ├── motor.py # Motor control commands
│ └── monitor.py # Real-time monitoring
├── PROTOCOL_DOCUMENTATION.md # Full project overview
├── MCP_PROTOCOL_NOTES.md # Protocol specification
└── README.md # This file
from st_mcp.commands.motor import StartMotorCommand, StopMotorCommand
# Start motor
start_cmd = StartMotorCommand(motor_id=0)
response = mcp.send_bytes(start_cmd.to_bytes())- Velocity Control: Speed-based motor operation
- Torque Control: Current-based motor operation
from st_mcp.commands.monitor import GetMonitor1Command, Monitor1Data
# Get motor data
monitor_cmd = GetMonitor1Command()
response = mcp.send_bytes(monitor_cmd.to_bytes())
data = monitor_cmd.parse_response(response)
print(f"Speed: {data.speed} RPM")
print(f"Torque: {data.torque} Nm")
print(f"Temperature: {data.temperature}°C")Available monitoring data:
- Monitor1: Speed, torque, flux, bus voltage, temperature
- Monitor2: Phase currents (Ia, Ib), D-Q currents, alpha-beta currents
All commands are sent over serial at 1,843,200 baud using the ASPEP protocol:
[Header: 4 bytes] [Payload: N bytes]
- Send beacon:
55 FF FF 77 - Receive beacon response
- Echo response back
- Receive confirmation
- Send connection request:
06 00 00 60
- 4 core services: Command, Registry, Datalog, Notification
- Currently implements: Command Service only
- Registry and Datalog services available in firmware but not yet exposed via Python
- Point-to-point serial protocol
- 3 communication channels: Synchronous, Asynchronous, Control
- Optional 16-bit CRC checksum
- Low-level transport for MCP
See MCP_PROTOCOL_NOTES.md for full specification.
The original electronics repository contains recorded serial traffic from the Windows Motor Pilot application for reference:
- Basic connect/disconnect sequence
- Motor start with velocity control
- Motor stop with ramp-down
These are useful for protocol validation and reverse engineering.
- Registry Service: Commands for reading/writing motor parameters not exposed
- Datalog Service: Real-time data logging configuration not implemented
- Error Handling: Limited error recovery in connection sequence
- Testing: No automated test suite (hardware-dependent)
- Implement Registry Service commands
- Implement Datalog Service with configurable sampling
- Add comprehensive error handling
- Create test harness with mock STM32 device
- Add parameter tuning utilities
- ST Motor Control SDK Community - Official MCSDK support and documentation
- ST Motor Workbench - Motor Control SDK tools and downloads
MCP_PROTOCOL_NOTES.md- Motor Control Protocol (MCP) specificationPROTOCOL_DOCUMENTATION.md- ASPEP protocol and project architecture
See individual file headers for licensing information.