A 3dprinter/cnc firmware framework powered by rust embassy

Related tags

Utilities printhor
Overview

Minimum Rust: Nightly crates.io License: MIT Discord Shield

Printhor: The highly reliable but not necessarily functional 3D printer firmware

If you are using this product or like the project, please this repository to show your support! 🤩

Overview

Printhor is a generic a hardware-agnostic firmware framework focused on FDM printers, CNC and Engravers implemented in Rust.

There are many productive firmwares in the community like gbrl, marlin, reprap, etc. Each single one have a concrete approach and guidelines. This one aims to provide a research environment for not strictly productive purpose, but a reliable platform with the following goals:

  • Robustness.
  • Numerical stability.
  • Efficient resources utilization and close-to-preemptive multitasking.
    • Leverage async multitasking.
    • Maintain busy waits to a minimum.
    • Ensure leverage of DMA transfers as much as possible.
    • Ensure of leverage of FPU when present.
  • Simplicity.
  • Clarity and readability.

Which means the principal short-term goal is not to develop a productive firmware for final user rather than providing an environment in which anyone can test and experiment any concrete approach to feed the community with good quality, state-of-the-art or innovative feature increments.

Features

  • "Clean" hardware abstraction.
  • Vector geometry / linear algebra calculus for kinematics
    • High precision and deterministic kinematics and computations.
  • Simple, secure and efficient resource and peripherals sharing.
  • Clean and simple async tasks coordination/intercommunication with event based primitives.
  • Wide GCode standard coverage.
  • Native simulation for development and benchmarking.
    • Smooth acceleration and jerk limited motion plan.
    • Precise thermal control.
    • Many others coming.

Overall status

Feature Status
Simulation Functional
I/O Functional
State and logic Incubation
Motion Planner Incubation
Kinematics Draft
Thermal Control Draft
Display Draft
Laser/CNC TODO

Help wanted

If you are interested in this project and want to collaborate, you are welcome. A Discord server has been created for informal discussions. Otherwise, Github Issues and Pull Requests are preferred.
Discord Banner 4

Checkout

git clone https://github.com/cbruiz/printhor
cd printhor

Build

The minimal toolset required to build and run is:

  • Rust, in order to compile
  • cargo binutils, to produce the image binary that you can flash via SD card as usual.
  • [Optionally] probe-run, if you are willing to use a SWD/Jlink debugger (https://github.com/knurling-rs/probe-run)
  • [Optionally] cargo-bloat and cargo-size utils are great to analyze the code size.
  • [Optionally] A Rust IDE, like VStudio Code (recommended), Jetbrains IDE (IntelliJ, CLion or RustRover (recommended)), or others

Prerequisites: Rust and toolchain

This crate requires Rust nighlty.

For official guide, please see https://www.rust-lang.org/tools/install

However, if your os is unix based:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup update

For microcontrollers (currently few stm32 only), the specific target toolchain and cargo binutils is also needed:

rustup target add thumbv7em-none-eabi
rustup target add thumbv7em-none-eabihf
rustup target add thumbv6m-none-eabi
cargo install cargo-binutils

Optionally, for debugging on baremetal microcontrollers (currently few stm32 only):

cargo install probe-run

Native simulator backend

The framework with a set of mocked peripherals (most of them without any logic). Provides a commandline GCode prompt on standard input

Note: A SDCard image in ./data/ is required to be open if sdcard feature is enabled in native :)

RUST_LOG=info cargo +nightly run --bin printhor

Integration tests

Native backend has a special feature called integration-test which is used to perform "some kind of" integration tests. Still pending to be matured.

RUST_LOG=info cargo +nightly run --features integration-test --bin printhor

SKR Mini E3 V3

This board (https://biqu.equipment/collections/control-board/products/bigtreetech-skr-mini-e3-v2-0-32-bit-control-board-for-ender-3) is quite functional

Firmware is around to 140Kb, and expecting to be around 100Kb with the core funtions and components (except, for instance: display, which is likely to increase it beyond the 110KB limit for 128KB flash size microcontrollers)

Binary image production (standard with defmt)

The firmware.bin file ready to be uploaded to the SD can be produced with the following commandline:

DEFMT_LOG=info cargo +nightly objcopy --release --no-default-features --features skr_mini_e3_v3 --target thumbv6m-none-eabi --bin printhor -- -O binary firmware.bin

Minimal-size binary image production

DEFMT_LOG=off RUST_BACKTRACE=0 cargo +nightly objcopy --profile release-opt --no-default-features --features skr_mini_e3_v3 --target thumbv6m-none-eabi --bin printhor -- -O binary firmware.bin

Extra utilery

A simple stand-alone std binary to experiment with motion plan (kind of playground):

cargo +nightly run --bin scurve_plot

Example output:

alt text

TODO

  • Code productivization. Mostly based on https://dl.acm.org/doi/pdf/10.1145/3519941.3535075 and https://jamesmunns.com/blog/fmt-unreasonably-expensive/:
    • Code size reduction.
    • Remove unwrap/panic calls.
    • Remove unsafe code (a little bit, but there it is)
    • Remove trivial/redundant computation but not compromising readability.
  • Unit test
  • CoreXY support
  • Display
  • I/O control
    • xonxoff
  • Adaptative planing cost measurement to take a decision on chaining or not and how much.
  • There is an issue activating USB together with SPI in SKR E3 Mini v3 :(
  • exfat support could be great.

Customization

For a single board, the high-level features (hotend, hotbed, fan, sdcard, ... ) can be activated/deactivated by cargo feature selection or directly editing the main cargo.toml In order to change pins, writing/adapting some code is required, as of now. There is not expected to be, at least in the short term any kind of configuration file.

Because of that limitation (Rust makes that hard to tackle because of the strict typing), a clean code organization it's crucial and pretty straightforward to assume slight customizations by editing code.

Architecture

printhor is composed by the following architectural blocks

Intentionally, traits are in general avoided when not strictly required in favour of defining a more decoupled and easy to evolve interface based on:

  • type aliases
  • module exports

Diagram is Work in Progress

Similar, related software and shout-outs

  • https://embassy.dev/ Rust Embassy; The next-generation framework for embedded applications. The most important and core framework conforming the pillars of this project.
  • https://github.com/nviennot/turbo-resin Exactly the same a printhor but focused in resin printers. The Project which inspired and motivated this one.
  • https://github.com/marcbone/s_curve A really appreciated know-how. The current selected motion profile is based on this work, but intense reinterpretation were performed to make this project work.The book referenced by the author of s-curve is a key reading considered to conduct the goals of the motion plan. Nevertheless, our implementation is still un-mature/unproven to ask for a merge.

GCode compliancy [Draft]

Gcode implementation status, as from https://reprap.org/wiki/G-code

  • WIP: Work In Progress
  • ILT: In the Long Term
  • TODO: To Do
M-Code Mode Description Status
M * List all supported m-codes DONE
M0 * Stop or Unconditional stop WIP
M1 * Sleep or Conditional stop WIP
M2 * Program End WIP
M3 CNC Spindle On, Clockwise WIP
LASER Laser On WIP
M4 CNC Spindle On, Counter-Clockwise WIP
LASER Laser On WIP
M5 CNC Spindle Off WIP
LASER Laser Off WIP
M6 * Tool change ILT
M7 CNC Mist Coolant On ILT
M8 CNC Flood Coolant On ILT
M9 CNC Coolant Off ILT
M10 CNC Vacuum On ILT
M11 CNC Vacuum Off ILT
M13 CNC Spindle on (clockwise rotation) and coolant on (flood) ILT
M16 CNC Expected Printer Check TODO
M17 * Enable/Power all stepper motors WIP
M18 * Disable all stepper motors WIP
M20 * List SD card WIP
M21 * Initialize SD card TODO
M22 * Release SD card TODO
M23 * Select SD file TODO
M24 * Start/resume SD print TODO
M25 * Pause SD print TODO
M26 * Set SD position ILT
M27 * Report SD print status TODO
M30 * Program Stop TODO
M31 * Output time since last M109 or SD card start to serial TODO
M32 * Select file and start SD print TODO
M33 * Get the long name for an SD card file or folder ILT
M37 * Simulation mode WIP
M73 * Set/Get build percentage TODO
M79 * Soft reset WIP
M80 * ATX Power On WIP
M81 * ATX Power Off WIP
M82 * Set extruder to absolute mode WIP
M83 * Set extruder to relative mode WIP
M92 * Set axis_steps_per_unit WIP
M104 FFF Set Extruder Temperature WIP
M105 FFF Get Extruder Temperature WIP
M106 * Fan On WIP
M107 * Fan Off WIP
M109 FFF Set Extruder Temperature and Wait WIP
M110 * Set Current Line Number WIP
M111 * Set Debug Level WIP
M112 * Full (Emergency) Stop WIP
M114 * Get Current Position WIP
M115 * Get Firmware Version and Capabilities WIP
M116 * Wait WIP
M117 * Display message WIP
M118 * Echo message on host WIP
M119 * Get Endstop Status WIP
M120 * Enable endstop detection WIP
M121 * Disable endstop detection WIP
M140 * Set Bed Temperature (Fast) WIP
M200 * Set filament diameter WIP
M201 * Set max acceleration WIP
M202 * Set max travel acceleration WIP
M203 * Set maximum feedrate WIP
M204 * Set default acceleration WIP
M205 * Advanced settings WIP
M206 * Offset axes WIP
M207 * Set retract length WIP
M208 * Set unretract length WIP
M209 FFF Enable automatic retract WIP
M210 * Set homing feedrates WIP
M211 * Disable/Enable software endstops WIP
M212 * Set Bed Level Sensor Offset WIP
M218 * Set Hotend Offset WIP
M220 * Set speed factor override percentage WIP
M221 * Set extrude factor override percentage WIP
M290 * Babystepping WIP
M302 * Allow cold extrudes WIP
M305 * Set thermistor and ADC parameters WIP
M350 * Set microstepping mode WIP
M360 * Report firmware configuration WIP
M400 * Wait for current moves to finish TODO
M401 * Deploy Z Probe TODO
M402 * Stow Z Probe TODO
M404 * Filament width and nozzle diameter WIP
M407 * Display filament diameter WIP
M410 * Quick-Stop TODO
M422 * Set a G34 Point WIP
M450 * Report Printer Mode WIP
M451 * Select FFF Printer Mode WIP
M452 * Select Laser Printer Mode WIP
M453 * Select CNC Printer Mode WIP
M500 * Store parameters in non-volatile storage TODO
M501 * Read parameters from EEPROM TODO
M502 * Restore Default Settings WIP
M503 * Report Current Settings WIP
M504 * Validate EEPROM TODO
M505 * Clear EEPROM and RESET Printer TODO
M510 * Lock Machine ILT
M511 * Unlock Machine with Passcode ILT
M512 * Set Passcode ILT
M513 * Remove Password ILT
M524 * Abort SD Printing ILT
M555 * Set compatibility ILT
M563 * Define or remove a tool ILT
M851 * Set Z-Probe Offset WIP
M862.1 * Check nozzle diameter ILT
M862.2 * Check model code ILT
M862.3 * Model name TODO
M929 * Start/stop event logging to SD card TODO
G-Code Mode Description Status
G * List all supported g-codes DONE
G0 * Rapid Move WIP
G1 * Linear Move WIP
G4 * Dwell TODO
G10 * Retract ILT
G11 * Unretract TODO
G17 * Plane Selection XY (default) TODO
G18 CNC Plane Selection ZX ILT
G19 CNC Plane Selection YZ ILT
G21 * Set Units to Millimeters WIP
G22 * Firmware Retract ILT
G23 * Firmware Recover ILT
G28 * Move to Origin (Home) TODO
G29 * Detailed Z-Probe TODO
G29.1 * Set Z probe head offset WIP
G29.2 * Set Z probe head offset calculated from toolhead position ILT
G30 * Single Z-Probe TODO
G31 * Set or Report Current Probe status TODO
G38.2 * Probe toward workpiece, stop on contact, signal error if failure ILT
G38.3 * Probe toward workpiece, stop on contact ILT
G38.4 * Probe away from workpiece, stop on loss of contact, signal error if failure ILT
G38.5 * Probe away from workpiece, stop on loss of contact ILT
G80 * Mesh-based Z probe ILT
G81 * Mesh bed leveling status ILT
G82 * Single Z probe at current location TODO
G90 * Set to Absolute Positioning WIP
G91 * Set to Relative Positioning WIP
G92 * Set Position WIP
G92.1 * Reset axis offsets (and parameters 5211-5219) to zero. (X Y Z A B C U V W) ILT
G92.2 * Reset axis offsets to zero ILT
G93 CNC Feed Rate Mode (Inverse Time Mode) ILT
G94 CNC Feed Rate Mode (Units per Minute) ILT

3DPrint Gcode sample

M73 P0 R87
M73 Q0 S87
M201 X1000 Y1000 Z200 E5000 ; sets maximum accelerations, mm/sec^2
M203 X200 Y200 Z12 E120 ; sets maximum feedrates, mm / sec
M204 P1250 R1250 T1500 ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2
M205 X8.00 Y8.00 Z0.40 E4.50 ; sets the jerk limits, mm/sec
M205 S0 T0 ; sets the minimum extruding and travel feed rate, mm/sec
M107
;TYPE:Custom
M862.3 P "MK3" ; printer model check
M862.1 P0.4 ; nozzle diameter check
G90 ; use absolute coordinates
M83 ; extruder relative mode
M80 ; Power on
G28 W ; home all without mesh bed level
G80 ; mesh bed leveling
G28 X Y; Park
M104 S235 ; set extruder temp
M140 S60 ; set bed temp
M190 S60 ; wait for bed temp
M109 S235 ; wait for extruder temp

G1 Z0.2 F720
G1 Y-3 F1000 ; go outside print area
G92 E0
G1 X60 E9 F1000 ; intro line
G1 X100 E12.5 F1000 ; intro line

G92 E0
M221 S95

; Don't change E values below. Excessive value can damage the printer.
M907 E430 ; set extruder motor current
G21 ; set units to millimeters
G90 ; use absolute coordinates
M83 ; use relative distances for extrusion
; Filament-specific start gcode
M900 K0.2
M107
;LAYER_CHANGE
;Z:0.2
;HEIGHT:0.2
;BEFORE_LAYER_CHANGE
G92 E0.0
;0.2


G1 E-3.1 F3000
G1 Z.4 F720
;AFTER_LAYER_CHANGE
;0.2
G1 X76.782 Y74.538 F13200
G1 Z.2 F720
G1 E3.1 F3000
M204 P800
;TYPE:Skirt/Brim
;WIDTH:0.42
G1 F1200
G1 X77.609 Y73.879 E.03317
G1 X90.788 Y67.532 E.45862
G1 X91.819 Y67.297 E.03317

Laser Gcode sample

G21
G90
M206 X-45. Y-10. Z-20.; Laser offset
G28; Homing
G1 F3000. Z7.
M107;svg#svg5 > g#layer89324 > path#rect2575
G0 X12.650835 Y109.995
M4 I S255
G1 X112.64085 Y109.995 F3000
G1 X112.64085 Y10.004999999999995 F3000
G1 X12.650835 Y10.004999999999995 F3000
G1 X12.650835 Y109.99499999999999 F3000
M5 I
You might also like...
Minimal, flexible framework for implementing solutions to Advent of Code in Rust

This is advent_of_code_traits, a minimal, flexible framework for implementing solutions to Advent of Code in Rust.

Rust implementation of the Edge IoT framework

A Rust-based implementation of Edge-rs for the Raspberry Pi Pico Getting started For more details see the following article on getting started for get

tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

tracing-appender Writers for logging events and spans Documentation | Chat Overview tracing is a framework for instrumenting Rust programs to collect

Examples of how to use Rust with Serverless Framework, Lambda, API Gateway v1 and v2, SQS, GraphQL, etc

Rust Serverless Examples All examples live in their own directories: project: there is nothing here, just a simple cargo new project_name with a custo

A rust `tracing` compatible framework inspired by log4rs.

trace4rs This crate allows users to configure output from tracing in the same way as you would configure the output of log4rs. Overview For a usage ex

A Rust framework to develop and use plugins within your project, without worrying about the low-level details.

VPlugin: A plugin framework for Rust. Website | Issues | Documentation VPlugin is a Rust framework to develop and use plugins on applications and libr

Framework is a detector for different frameworks in one projects

Framework is a detector for different frameworks in one projects Usage use

A new comfortable back end framework for rustaceans.

Black Tea is a new Rust back end framework based on hyper. We are enthusiastic to provide developers some enhanced features and comfortable coding experience.

A framework for iterating over collections of types implementing a trait without virtual dispatch
A framework for iterating over collections of types implementing a trait without virtual dispatch

zero_v Zero_V is an experiment in defining behavior over collections of objects implementing some trait without dynamic polymorphism.

Owner
Carlos Barrales
Carlos Barrales
A rust-based mechanical keyboard firmware

rumcake A rust-based mechanical keyboard firmware that aims to be decentralized, featureful, and easy to configure. ⚠ rumcake is still a work in progr

null 15 Oct 6, 2023
Functional testing framework for AVR binaries, powered by simavr.

Functional testing framework for AVR binaries, powered by simavr. tl;dr get your microcontroller's firmware black-box-tested in seconds!

Patryk Wychowaniec 14 Nov 16, 2022
A modular and blazing fast runtime security framework for the IoT, powered by eBPF.

Pulsar is a security tool for monitoring the activity of Linux devices at runtime, powered by eBPF. The Pulsar core modules use eBPF probes to collect

Exein.io 319 Jul 8, 2023
Extensions for x64dbg written in Rust: Telescope and Unicorn powered disassembly

This is the library that extends x64dbg with new features: Telescope. It's basically recursive dereferencerer of memory view which looks at the pointe

null 18 Sep 11, 2022
TaurApp is a WhatsApp desktop client powered by Tauri and Rust.

TaurApp TaurApp is a WhatsApp desktop client powered by Tauri and Rust. TaurApp is an experimental client and is initially created to test out Tauri i

Eray Erdin (&mut self) 22 Mar 19, 2023
A GPT-powered daily newsletter bot, written in Rust

AI Newsie 1. Introduction Meet AI Newsie - your personalized GPT-powered bot that delivers daily newsletters tailored to your interests. The bot is po

null 5 May 7, 2023
Fox Ear is a Linux process behavior trace tool powered by eBPF

Fox Ear Fox Ear is a Linux process behavior trace tool powered by eBPF. Banner image by Birger Strahl on Unsplash. Features Log process and its subpro

Rui Li 77 Dec 5, 2022
An asynchronous IO utilities crate powered by tokio.

An asynchronous IO utilities crate powered by tokio.

Harry 2 Aug 18, 2022
Web-wrapped Supabase desktop app for macOS, Windows & Linux powered by Tauri

Supabase Desktop App What is it? It's a cross-platform web-wrapped Supabase desktop app powered by Tauri. You can install it on your macOS, Windows (u

Abiel Zulio M 12 Jan 25, 2023
A dead-simple AI-powered CLI tool for effortlessly crafting meaningful Git commit messages

AI Commit Message acm A dead-simple AI-powered CLI tool for effortlessly crafting meaningful Git commit messages. Features Effortlessly create meaning

syeijs 3 Nov 5, 2024