Building Meshtastic Firmware
Meshtastic uses PlatformIO, a development environment that enables easy multi-platform development and centralized tooling.
Setup the Build Environment
- Install PlatformIO
- Clone the Meshtastic Firmware repository
git clone https://github.com/meshtastic/firmware.git
- Update the repository's submodules
cd firmware && git submodule update --init
infoIf you want to build the RP2040 targets and get a 'Filename too long' error on Windows, please refer to the Platformio documentation for this toolchain
Build
- Open the newly cloned folder in Visual Studio Code. If you do this for the first time, this can take quite some while as PlatformIO will download all the necessary tooling and libraries. Also if platformio is not installed, VSCode will ask you to install it, probably requiring a restart of the program.
- To select the device you you wish to build, open your command palette:
- Windows:
Ctrl + Shift + P
- Mac:
command + Shift + P
- Windows:
- Enter:
PlatformIO: Pick Project Environment
and select your target. - To build the firmware, simply run
PlatformIO: Build
from your command palette. - Finally, flash the firmware to your device by running
PlatformIO: Upload
Adding Custom Hardware
The build system is modular. Adding a new board variant for an already supported architecture is straightforward.
Build with Custom Hardware
- Go to the
variants
folder in the firmware source code and make a new directory for your hardware, let's call itm5stack_atom
and copy an existing configuration you wanna modify:cd variants; mkdir m5stack_atom
cp heltec_v1/* m5stack_atom
cd m5stack_atom - Modify the
platformio.ini
in this subdirectory from the canonical define of the hardware variant (HELTEC_V1
in this case) toPRIVATE_HW
and make the-I
on thebuild_flags
point to the newly created dir.[env:m5stack-atom]
extends = esp32_base
board = m5stack-atom
monitor_filters = esp32_exception_decoder
build_flags =
${esp32_base.build_flags} -D PRIVATE_HW -I variants/m5stack_atom
lib_deps =
${esp32_base.lib_deps} - Edit the
variant.h
file in this subdirectory to reflect the defines and configurations for your board. The example is very well commented. - Build, run and debug until you are satisfied with the result.
Distribute / Publish Custom Builds
- Perform all of the steps building with custom hardware until your hardware runs fine.
- Send a proposal to add a new board.
- If approved, go to https://github.com/meshtastic/protobufs and send a Pull Request for the
mesh.proto
file, adding your board to theHardwareModel
Enum. - Change your define in
platformio.ini
fromPRIVATE_HW
toYOUR_BOARD
. Adjust any macro guards in the code you need to support your board. - Add your board identifier to
architecture.h
on the firmware repo in the folder of the platform you are using, and send in that Pull Request too. - Wait for the Pulls to be merged back into Master.
- Profit :-)
Alternative route: Gitpod
Gitpod offers an alternative method for compiling the firmware without installing Visual Studio Code. It is a web browser-based online IDE that can be used with a GitHub account. Gitpod provides a free tier suitable for light use, such as compiling custom firmware.
- Go to https://gitpod.io#https://github.com/meshtastic/firmware.
- Make the desired changes to the chosen variant.
- Build the firmware by running:
pio run -e <variant_name>
- Once complete, download
<variant_name>.bin
or<variant_name>.uf2
from/workspace/firmware/.pio/build/<variant_name>.
- As flashing directly to the device isn't possible using Gitpod, upload using either:
- Drag & Drop for NRF52/RP2040 devices.
- Web flasher for ESP32 devices.