Extending MicroPython with Rust: Two Worlds Collide
summary
MicroPython firmware (≈65,000 lines) on STM32-class devices with ~192–256KB RAM meets Rust to regain speed and reduce allocations; proto codec rewritten in Rust gives ~5× speedup, UI moved to a custom Rust embedded toolkit, crypto stays in C. Key engineering pieces: a GCBox owner wrapper, an owned st buffer for safe string slices, and an unsafe get_buffer API for mutable memory views; exceptions use a C trampoline with NLR jumps and a planned VM-lifetime token to encode safety.
AI-written summary · about
chapters (13)
- 0:00MicroPython and Rust integration
- 3:40Memory safety challenges
- 13:23Rust ownership vs Python pointers
- 15:58Rust wrappers for MicroPython objects
- 21:07GCBox for garbage-collected references
- 23:32Safe strings and byte buffers
- 27:03Mutable byte types challenges
- 28:07Wrapping Python lists and dicts
- 31:47Python exceptions to Rust errors
- 35:04Catching Python exceptions
- 41:06Python iterators in Rust
- 44:16Safer Rust integration
- 46:23Q&A
related talks
04mUsing the Rust Standard Library on High-End MCUs
36mPumping up Python modules using Rust
31mPumping up Python modules using Rust
26mIntroducing Rust into a Legacy Embedded System
34mRust for the Python dev
31mReally Small Rust
39mReal-Time Rust in Robotics
01h 04mExtending MicroPython: Using C for good!
