Elixir Support
Relevant source files
The following files were used as context for generating this wiki page:
AtomVM provides comprehensive support for the Elixir programming language, allowing developers to target resource-constrained microcontrollers using Elixir's modern syntax and tooling. As an implementation of the Bogdan Erlang Abstract Machine (BEAM), AtomVM executes the bytecode compiled from Elixir source code, enabling features like actor-based concurrency and functional programming on devices such as the ESP32 and STM32.
Sources: doc/src/index.rst:11-14, doc/src/welcome-to-atomvm.md:12-16
Overview of Elixir Integration
Elixir support in AtomVM is integrated into the core virtual machine and supported through specialized tooling. The VM handles major Elixir types including Enums and Maps, and provides a memory-managed environment with per-process heap allocation.
Supported Language Features
- Concurrency: Process spawning, monitoring, and message passing.
- Data Types: Integers, strings, lists, maps, binaries, and Enums.
- Standard Library: A subset of the Elixir/OTP standard libraries optimized for microcontrollers.
- Peripherals: APIs for GPIO, I2C, SPI, and UART accessible via Elixir.
Sources: doc/src/welcome-to-atomvm.md:19-27, doc/src/index.rst:13-16
Tooling and Workflow
Elixir developers use the standard Elixir mix build tool alongside the ExAtomVM plugin to compile, package, and deploy applications.
ExAtomVM Plugin
ExAtomVM is a mix plugin that simplifies the development lifecycle. It manages the creation of AtomVM "packbeam" (.avm) files and handles the flashing process to various hardware platforms.
| Tool | Purpose |
|---|---|
mix deps.get | Fetches dependencies, including ExAtomVM. |
mix atomvm.packbeam | Compiles Elixir code and bundles it into an .avm file. |
mix atomvm.esp32.flash | Deploys the application to ESP32 hardware. |
mix atomvm.stm32.flash | Deploys the application to STM32 hardware. |
Sources: doc/src/atomvm-tooling.md:275-290, doc/src/atomvm-tooling.md:323-328, doc/src/atomvm-tooling.md:339-342
Development Workflow
The following diagram illustrates the path from Elixir source code to execution on hardware:
The workflow utilizes standard Elixir compilers to generate BEAM files, which are then packaged for the AtomVM runtime.
Sources: doc/src/atomvm-tooling.md:295-317, doc/src/getting-started-guide.md:113-120
Hardware Deployment Specifics
Deployment of Elixir applications requires specific memory considerations and flash offsets, particularly on the ESP32 platform.
ESP32 Flash Layout
For Elixir support, the ESP32 uses a specific partition map to accommodate the Elixir modules and standard library.
| Partition Component | Start Address (Offset) |
|---|---|
| Boot Loader | 0x0, 0x1000, or 0x2000 (varies by chip) |
| AtomVM VM Image | Following Boot Loader |
| Elixir Data Partition | 0x250000 |
On the ESP32, Elixir applications are typically flashed to address 0x250000, whereas thin Erlang-only images may start at 0x210000.
Sources: doc/src/getting-started-guide.md:61-75, doc/src/getting-started-guide.md:113-120, doc/src/atomvm-tooling.md:364-365
Deployment Logic
Standards and Contribution
Elixir code within the AtomVM project follows the standard Elixir formatter style. Contributions to the Elixir components of the repository are expected to adhere to these formatting rules.
Sources: CONTRIBUTING.md:104-106
Summary
Elixir support in AtomVM enables modern high-level programming on microcontrollers. By leveraging the ExAtomVM mix plugin, developers can maintain a familiar Elixir development environment while targeting hardware like the ESP32. The system handles the translation of Elixir BEAM files into the optimized PackBEAM format and manages specialized flash requirements for the Elixir runtime environment.
Sources: doc/src/welcome-to-atomvm.md:44-55, doc/src/atomvm-tooling.md:275-280