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
ESP32
board | processor | speed | flash | sram | logic | fpu |
ESP32 | Tensilica Xtensa LX6 | 240MHz | — | — | 3.3V | — |
LPC1768 / LPC1769
SAMD51
STM32
Teensy++ 2.0
Teensy 3.1 / 3.2
Teensy 3.5 / 3.6