chepo92 thinkyhead

Hardware Abstraction Layer

The Hardware Abstraction Layer –”HAL” for short– allows Marlin to run on a wide variety of boards by providing a common interface for low-level resources like timers, serial ports, i2c and SPI buses, EEPROM, SDIO, and so on.

HAL Rationale

Marlin was originally derived in 2011 from Sprinter and GRBL. Initially, Marlin could only run on Arduino’s AVR boards, but it was quickly ported to DUE. Soon we saw boards based on the LPC1768/9 appearing, along with a Grbl-based firmware called Smoothieware.

Another ARM processor, the STM32, was poised to take over as the new frontrunner, so we put our heads together to pick a course for extended hardware support. We decided not to rebuild Marlin from the ground up, but to preserve the existing work by adding a layer to abstract away the platform.

HAL Alternatives

We could have chosen to use an RTOS to build this abstraction, but there are just too many points against:

  • We want to stay compatible with AVR and small boards. That rules out RTOS.
  • While possible to make the AVR version separate it’s much simpler to keep a single codebase so everyone gets the latest features, patches and all platforms can benefit from improvements. We also catch bugs much faster when we’re running the same code on more architectures.
  • Marlin was designed to use direct interrupts, so it requires the least work to keep the same design. The extra benefit is that Marlin continues to run hardware-direct. The aim is for Marlin to obtain the best performance possible on the board using the least amount of power.

Current Marlin HALs

AVR (8-bit)

board processor speed flash sram logic fpu
Arduino AVR ATmega, ATTiny, etc. 16-20MHz 64-256k 2-16k 5V no

DUE

boards processor speed flash sram logic fpu
Arduino Due, RAMPS-FD, etc. SAM3X8E ARM-Cortex M3 84MHz 512k 64+32k 3.3V no

ESP32

board processor speed flash sram logic fpu
ESP32 Tensilica Xtensa LX6 240MHz 3.3V

LPC1768 / LPC1769

boards processor speed flash sram logic fpu
Re-ARM LPC1768 ARM-Cortex M3 100MHz 512k 32+16+16k 3.3-5V no
MKS SBASE LPC1768 ARM-Cortex M3 100MHz 512k 32+16+16k 3.3-5V no
Selena Compact LPC1768 ARM-Cortex M3 100MHz 512k 32+16+16k 3.3-5V no
Azteeg X5 GT LPC1769 ARM-Cortex M3 120MHz 512k 32+16+16k 3.3-5V no
Smoothieboard LPC1769 ARM-Cortex M3 120MHz 512k 64k 3.3-5V no

SAMD51

boards processor speed flash sram logic fpu
Adafruit Grand Central M4 SAMD51P20A ARM-Cortex M4 120MHz 1M 256k 3.3V yes

STM32

boards processor speed flash sram logic fpu
Arduino STM32 STM32F1 ARM-Cortex M3 72MHz 256-512k 48-64k 3.3V no
Geetech GTM32 STM32F1 ARM-Cortex M3 72MHz 256-512k 48-64k 3.3V no
STEVAL-3DP001V1 STM32F401VE Arm-Cortex M4 84MHz 512k 64+32k 3.3-5V yes

Teensy++ 2.0

boards processor speed flash sram logic fpu
Teensy++ 2.0 AT90USB1286 16MHz 128k 8k 5V no

Teensy 3.1 / 3.2

boards processor speed flash sram logic fpu
Teensy 3.2 MK20DX256VLH7 ARM-Cortex M4 72MHz 256k 32k 3.3V-5V yes

Teensy 3.5 / 3.6

boards processor speed flash sram logic fpu
Teensy 3.5 MK64FX512VMD12 ARM-Cortex M4 120MHz 512k 192k 3.3-5V yes
Teensy 3.6 MK66FX1M0VMD18 ARM-Cortex M4 180MHz 1M 256k 3.3V yes