1. Introduction

1.1 Overview

grblHAL is a comprehensive rewrite of grbl 1.1, specifically designed for 32-bit processors. The project introduces a Hardware Abstraction Layer (HAL) that completely separates the core grbl functionality from processor-specific and hardware-specific code. This innovative architecture addresses the fundamental limitations of traditional 8-bit GRBL while providing a scalable foundation for modern CNC control applications.

The project was initiated by Norwegian software developer Terje Io to solve the fragmentation issues that arose when multiple developers attempted to port GRBL to various 32-bit platforms. Instead of creating yet another incompatible fork, grblHAL establishes a unified codebase that can support multiple hardware platforms while maintaining feature consistency across all implementations.

1.2 Project Origins and Motivation

Traditional GRBL, while revolutionary for its time, faced several limitations as CNC technology advanced:

  • Performance Constraints: 8-bit Arduino processors could only achieve approximately 30kHz step pulse frequency, limiting machining speed and precision
  • Memory Limitations: Limited RAM and flash memory restricted the implementation of advanced features
  • Porting Challenges: Moving to 32-bit processors required extensive modifications to core code
  • Code Fragmentation: Multiple incompatible ports with varying feature sets and update cycles
  • Maintenance Issues: Bug fixes and improvements couldn’t be easily shared across different hardware implementations

1.3 Design Philosophy

grblHAL addresses these challenges through several key design principles:

  • Hardware Abstraction: Complete separation of core logic from hardware-specific implementation
  • Unified Codebase: Single core implementation shared across all supported platforms
  • Dynamic Capability Declaration: Hardware drivers announce their capabilities to the core
  • Extensible Architecture: Plugin system for adding custom functionality without core modifications
  • Modern Performance: Full utilization of 32-bit processor capabilities

2. System Architecture

2.1 Hardware Abstraction Layer (HAL) Concept

The HAL represents the core innovation of grblHAL. It creates a clean interface between the processor-agnostic core functionality and the hardware-specific driver implementations. This separation is achieved through a function pointer mechanism that allows dynamic binding of hardware operations to core logic.

Key Architectural Components:

  • Core Layer: G-code parsing, motion planning, safety monitoring, and state management
  • HAL Interface: Function pointer definitions and capability declarations
  • Driver Layer: Hardware-specific implementations for timers, GPIO, communication interfaces

2.2 Function Pointer Mechanism

The HAL uses function pointers to create a dynamic interface between core and driver code. This approach provides several advantages:

  • Runtime Flexibility: Drivers can change function pointers dynamically (e.g., switching from serial to SD card streaming)
  • Capability Adaptation: Core automatically adjusts behavior based on declared hardware capabilities
  • Zero Core Modification: New drivers can be implemented without touching core code
  • Stream Abstraction: Communication interfaces can be swapped transparently
// Example HAL structure typedef struct { // Core control functions void (*stepper_wake_up)(void); void (*stepper_go_idle)(void); void (*stepper_enable)(axes_signals_t enable); // Communication interface int16_t (*stream_read)(void); void (*stream_write)(const char *data); bool (*stream_write_char)(const char c); // Capability declaration driver_cap_t driver_cap; board_info_t *board_info; // Optional hooks for extensions void (*driver_setup)(void); bool (*driver_release)(void); } hal_t;

2.3 Plugin Architecture

grblHAL provides an extensible plugin system through optional HAL hooks. Plugins can:

  • Add custom settings without modifying source files
  • Implement additional M-codes
  • Extend real-time reporting
  • Subscribe to system events
  • Add custom user interfaces

2.4 Driver Implementation

Currently, over 15 drivers are available for different processor families, including:

  • STMicroelectronics STM32 series
  • Texas Instruments MSP432
  • NXP iMXRT1062 (Teensy 4.x)
  • Espressif ESP32
  • Raspberry Pi RP2040
  • Microchip SAM3X8E
  • Cypress PSoC

3. Core Features

3.1 Performance Improvements

grblHAL delivers significant performance improvements over traditional GRBL:

Feature Traditional GRBL (8-bit) grblHAL (32-bit) Improvement Factor
Step Pulse Frequency ~30kHz 300kHz+ 10x+
Supported Axes 3-4 axes Up to 9 axes 2-3x
RAM Capacity 2KB 64KB+ 32x+
Flash Memory 32KB 256KB+ 8x+
Look-ahead Buffer 16 segments 128+ segments 8x+

3.2 Enhanced Motion Control

grblHAL implements advanced motion control algorithms:

  • High-precision Timing: Maintains stable, jitter-free control pulses up to 300kHz
  • Advanced Look-ahead: Predicts future motion and plans velocity profiles for smooth acceleration
  • Multi-axis Coordination: Supports up to 9-axis simultaneous motion control (XYZABCUVW)
  • Jerk Control: Optional jerk limiting for ultra-smooth motion profiles

3.3 Network Connectivity

Modern connectivity options include:

  • WiFi: Station and Access Point modes with web interface
  • Ethernet: Wired network connectivity for industrial environments
  • Bluetooth: Mobile device connectivity
  • USB: High-speed CDC communication
  • Telnet/WebSocket: Multiple concurrent connections

3.4 File System Support

grblHAL supports various file storage options:

  • SD Card Support: Large G-code file storage and streaming
  • LittleFS: Embedded flash file system
  • Macro Storage: Custom machining cycles and programs
  • Configuration Files: Settings backup and restore

3.5 Safety Enhancements

Improved safety features over traditional GRBL:

  • Persistent Error States: Errors persist until explicit reset, preventing dangerous operations
  • Homing State Tracking: Individual axis homing status monitoring
  • Enhanced Limit Switches: Configurable normally-closed operation for safety
  • Emergency Stop: Multi-level safety stop mechanisms

4. Hardware Support

4.1 Supported Processor Families

4.1.1 ARM Cortex-M Series

  • STM32F4xx/F7xx: High-performance industrial-grade processors with extensive peripheral support
  • iMXRT1062: NXP’s high-performance processor used in Teensy 4.x development boards
  • SAM3X8E: Arduino Due compatible processor with advanced timer capabilities
  • LPC17xx: NXP low-power series with CAN bus support

4.1.2 ESP32 Series

  • Dual-core Processing: Dedicated core for real-time operations
  • Integrated WiFi/Bluetooth: Built-in wireless connectivity
  • Rich Peripheral Set: Multiple PWM, ADC, SPI, I2C interfaces
  • OTA Updates: Over-the-air firmware updates

4.1.3 Raspberry Pi RP2040

  • Dual ARM Cortex-M0+: 133MHz processors with hardware floating-point
  • Programmable I/O: Flexible pin configuration and timing
  • USB Native Support: Built-in USB device capability
  • Cost-effective: Low-cost option with high performance

4.2 Capability-based Hardware Adaptation

grblHAL automatically adapts to hardware capabilities through the driver capability declaration system:

// Driver capability declaration example driver_cap_t driver_cap = { .spindle_sync = On, // Spindle synchronization support .variable_spindle = On, // Variable speed spindle .wifi = On, // WiFi connectivity .bluetooth = On, // Bluetooth connectivity .ethernet = Off, // No Ethernet support .atc = On, // Automatic tool changer .probe = On, // Probe input .safety_door = On, // Safety door input .spindle_pid = On, // Spindle PID control .laser_ppi_mode = On, // Laser PPI mode .step_pulse_delay = On, // Step pulse delay .limits_override = On, // Limit override capability .home_unsafe = On // Unsafe homing support };

4.3 Network Capability Comparison

Connection Type Supported Platforms Data Rate Use Cases
WiFi (802.11) ESP32, selected STM32 1-54Mbps Wireless remote control
Ethernet STM32F7xx, iMXRT1062 10/100Mbps Industrial network integration
Bluetooth ESP32 1-3Mbps Mobile device control
USB CDC All platforms 12Mbps+ PC direct connection

5. G-Code and M-Code Extensions

5.1 Supported G-Codes

grblHAL supports an extensive set of G-codes, approaching LinuxCNC compatibility:

5.1.1 Motion Modes

G0 – Rapid positioning (maximum speed linear movement) G1 – Linear interpolation (work feed rate) G2 – Clockwise circular interpolation (supports multi-turn helixes) G3 – Counterclockwise circular interpolation (supports multi-turn helixes) G5 – Spline interpolation (NURBS splines) G5.1- B-spline interpolation G33 – Threading (spindle synchronized motion)* G38.2-G38.5 – Probing cycles G80 – Cancel canned cycle

5.1.2 Canned Cycles

G73 – High-speed peck drilling cycle G81 – Drilling cycle G82 – Boring cycle (with dwell) G83 – Peck drilling cycle (deep hole drilling) G85 – Reaming cycle G86 – Boring cycle (spindle stop) G89 – Boring cycle (manual feed) G98 – Return to initial plane G99 – Return to R plane

5.1.3 Lathe-specific Codes

G7 – Radius programming mode (lathe) G8 – Diameter programming mode (lathe) G76 – Threading cycle (lathe)* G96 – Constant surface speed control* G97 – Constant RPM mode*

5.2 M-Code Extensions

5.2.1 Spindle Control

M3 – Spindle clockwise M4 – Spindle counterclockwise M5 – Spindle stop

5.2.2 Coolant Control

M7 – Mist coolant on M8 – Flood coolant on M9 – Coolant off

5.2.3 Tool Management

M6 – Tool change* M61 – Set current tool number

5.2.4 Program Control

M0 – Program pause M1 – Optional pause M2 – Program end M30 – Program end and rewind M60 – Automatic pallet change

5.2.5 Input/Output Control

M62 P- – Digital output immediate on M63 P- – Digital output immediate off M64 P- – Digital output synchronized on M65 P- – Digital output synchronized off M66 P- L- Q- – Wait for input M67 E- Q- – Analog output control M68 E- Q- – Analog output synchronized

5.3 Coordinate Systems

grblHAL supports extended coordinate systems:

  • G54-G59.3: Nine work coordinate systems (traditional GRBL supports only six)
  • G92: Local coordinate system offset
  • G10 L2/L20: Coordinate system setup
  • G43/G43.1/G43.2: Tool length compensation

5.4 Expressions and Flow Control

grblHAL supports LinuxCNC-compatible parametric programming:

Parametric Programming Features:

  • Variables: Numbered parameters (#1-#5000) and named variables
  • Expressions: Mathematical operations, trigonometric functions, logical operations
  • Conditional Statements: if/else/endif constructs
  • Loops: do/while/repeat structures
  • Subroutines: G65 macro calls with parameter passing
// Parametric programming example #100 = 10.0 ; Set variable #101 = [#100 * 2 + 5] ; Expression calculation ; Conditional execution o if [#100 GT 5] G1 X#100 F500 o else G0 X0 o endif ; Loop machining o repeat [5] G1 X[#100] Y[#101] #100 = [#100 + 1] o endrepeat

6. Advanced Features

6.1 Tool Change Systems

grblHAL supports multiple tool change modes:

6.1.1 Manual Tool Change

  • Mode 0: Traditional manual tool change with jogging
  • Mode 1: Manual touch-off with automatic position return
  • Mode 2: Manual touch-off at G59.3 position
  • Mode 3: Automatic touch-off at G59.3 position
  • Mode 4: Ignore M6 commands

6.1.2 Tool Change Protocol

When an M6 command is executed:

  1. System enters “Tool” state
  2. Subsequent G-code commands are suspended
  3. Jogging remains enabled
  4. Sender must acknowledge tool change completion
  5. Cycle start resumes normal operation

6.2 Spindle Synchronization

Advanced spindle control features for precision machining:

  • Encoder Feedback: High-resolution position feedback
  • PID Control: Closed-loop spindle speed regulation
  • Threading Operations: Precise spindle-synchronized motion
  • Constant Surface Speed: Lathe mode CSS control

6.2.1 Configuration Parameters

$38 – Spindle Pulses Per Revolution (PPR) $90 – Spindle PID proportional gain $91 – Spindle PID integral gain $92 – Spindle PID derivative gain $340 – Spindle at-speed tolerance

6.3 Network Services

grblHAL provides comprehensive network services:

Service Port Description
Telnet 23 Terminal access for G-code streaming
HTTP 80 Web interface for control and monitoring
WebSocket 81 Real-time bidirectional communication
FTP 21 File transfer for G-code and configuration

6.4 Report Extensions

Enhanced status reporting provides comprehensive machine information:

  • Extended Status Codes: Additional machine states including “Tool”
  • Pin State Reporting: Real-time I/O status
  • Enhanced Parser State: Complete modal state information
  • Alarm Sub-states: Detailed error information
  • Custom Reporting: Plugin-extensible status information

7. Development and Compilation

7.1 Development Environments

7.1.1 Web Builder (Recommended)

The Web Builder provides a user-friendly interface for configuring and building grblHAL firmware:

  • No Local Setup Required: Browser-based configuration
  • Visual Feature Selection: Graphical interface for enabling features
  • Automatic Dependency Management: Handles complex configurations
  • Multiple Platform Support: ESP32, STM32, Teensy, and others

7.1.2 Arduino IDE

  • Beginner-friendly: Simple graphical interface
  • Library Management: Automatic dependency handling
  • Built-in Serial Monitor: Debugging and testing
  • Wide Platform Support: Most grblHAL drivers supported

7.1.3 Professional IDEs

  • STM32CubeIDE: Official STM32 development environment
  • Visual Studio Code: Modern editor with PlatformIO extension
  • Eclipse-based IDEs: Advanced debugging and profiling

7.2 Configuration Files

File Purpose Modification Frequency
my_machine.h Hardware platform selection and driver features Frequent
grbl/config.h Common configuration options Occasional
*_map.h Pin definitions and board-level configuration Rare
defaults.h Default setting values Rare

7.3 Compilation Example

// my_machine.h configuration example #define BOARD_CNC3040 // Select development board #define N_AXIS 4 // 4-axis configuration #define ENABLE_WIFI 1 // Enable WiFi #define ENABLE_BLUETOOTH 1 // Enable Bluetooth #define TRINAMIC_ENABLE 1 // Enable Trinamic drivers #define KEYPAD_ENABLE 1 // Enable keypad support #define SPINDLE_SYNC_ENABLE 1 // Enable spindle synchronization

7.4 Flashing Methods

Firmware flashing methods vary by microcontroller:

  • ESP32: Flash Download Tool, esptool.py, Arduino IDE
  • STM32: ST-Link debugger, DFU mode, serial ISP
  • Teensy: Teensy Loader application, $BL command
  • RP2040: BOOTSEL mode with drag-and-drop .uf2 files

8. Software Tools and Ecosystem

8.1 Official Tools

8.1.1 ioSender

Purpose-built G-code sender for grblHAL with advanced features:

  • Keyboard Jogging: Proper keyboard-based machine control
  • Advanced Probing: Automated workpiece and tool measurement
  • Multi-axis DRO: Up to 6-axis digital readout display
  • Lathe Mode: Conversational G-code generation
  • 3D Rendering: Real-time toolpath visualization
  • Macro Support: Custom operation sequences

8.1.2 Web UI v3

Browser-based control interface with comprehensive functionality:

  • Platform Independent: Works on any device with a web browser
  • Responsive Design: Optimized for mobile and desktop
  • Real-time Communication: WebSocket-based bidirectional data
  • File Management: Upload and manage G-code files
  • Advanced Settings: Complete configuration interface

8.2 Third-party Compatible Tools

Tool Platform Key Features Compatibility
Universal G-code Sender Java (Cross-platform) Visual operations, macro support Good
CNCjs Web application Modern web interface, plugin system Excellent
OpenBuilds CONTROL Cross-platform CAM integration, visual toolpaths Good
LaserGRBL Windows Laser engraving specialization Excellent

8.3 CAM Software Compatibility

grblHAL is compatible with G-code output from major CAM software packages:

  • Fusion 360: Autodesk’s professional CAM solution
  • Vectric Software Suite: Aspire, VCarve Pro, Cut2D
  • MeshCAM: Simple 3D machining software
  • EstlCAM: German professional CNC software
  • FreeCAD: Open-source CAD/CAM solution
  • CamBam: Economical CAM software

9. Comparison with Traditional GRBL

9.1 Detailed Feature Comparison

Feature Traditional GRBL grblHAL Advantage
Processor Architecture 8-bit ATmega328P 32-bit ARM/ESP32 10x+ performance improvement
Memory Capacity 2KB RAM, 32KB Flash 64KB+ RAM, 256KB+ Flash Support for complex features
Step Frequency ~30kHz 300kHz+ Higher precision and speed
Supported Axes 3 axes (XYZ) Up to 9 axes (XYZABCUVW) Complex machine support
G-code Support Basic G-code set LinuxCNC compatible Professional functionality
Network Connectivity None WiFi/Bluetooth/Ethernet Modern connectivity
File System None SD card/LittleFS Local file storage
Tool Management None Automatic/manual tool change Production efficiency
Spindle Control Basic PWM PID closed-loop + sync Precision machining
Extensibility Core code modification HAL + plugin system Modular expansion

9.2 Performance Benchmarks

Test GRBL (Arduino Uno) grblHAL (ESP32) grblHAL (STM32F4)
Maximum Step Frequency 30kHz 200kHz 300kHz+
G-code Parsing Speed Baseline 1x 5-8x 10-15x
Look-ahead Buffer 16 segments 64+ segments 128+ segments
Real-time Response ~1ms ~0.1ms ~0.05ms

9.3 Migration Considerations

When migrating from traditional GRBL to grblHAL:

Compatibility Levels:grblHAL provides compatibility levels to ease migration:

  • Level 1: Disables some extensions, reports as “Grbl 1.1”
  • Level 2: Additionally disables new $$ settings
  • Level 10: Disables extra coordinate systems and report extensions

9.4 Key Improvements Summary

  • Error Handling: Errors persist until reset, reducing dangerous operation risk
  • Homing Enhancement: Individual axis tracking with optional manual homing
  • Safety Features: Normally-closed switch default configuration
  • Configuration Flexibility: Runtime settings replace compile-time definitions
  • Extended Functionality: Native tool change and spindle synchronization

10. Conclusion

grblHAL represents a significant advancement in open-source CNC control technology. By introducing the Hardware Abstraction Layer architecture, it successfully addresses the fundamental limitations of traditional GRBL while establishing a foundation for future development.

10.1 Key Innovations

  • Architectural Innovation: HAL design enables true hardware independence
  • Performance Revolution: 32-bit processors deliver 10x+ performance improvement
  • Feature Completeness: Approaches LinuxCNC functionality in a embedded package
  • Ecosystem Development: Active community and comprehensive tooling support
  • Future-proof Design: Extensible architecture supports continued evolution

10.2 Target Applications

grblHAL is particularly well-suited for:

  • Small to Medium CNC Mills: Desktop to mid-size industrial machines
  • Laser Engraving Systems: CO2 and diode laser applications
  • 3D Printing: High-precision additive manufacturing systems
  • Lathe Conversions: CNC retrofitting of manual lathes
  • Educational Platforms: Teaching and training environments
  • Prototype Development: Rapid prototyping and small-batch production
  • Artistic Applications: Creative cutting and engraving projects

10.3 Future Outlook

grblHAL continues to evolve with regular updates and community contributions. The modular architecture ensures that new features can be added without disrupting existing functionality, making it a sustainable choice for long-term CNC control applications.

Project Status:grblHAL is actively maintained with regular updates. The current build version is 20250910, demonstrating ongoing development and improvement. The project maintains backward compatibility while continuously adding new features and platform support.

For organizations and individuals seeking a modern, capable, and extensible CNC control solution, grblHAL offers the perfect balance of performance, functionality, and accessibility that makes it an ideal choice for a wide range of applications.