meshtastic/docs/developers/Firmware/build.mdx

69 lines
3.4 KiB
Plaintext
Raw Normal View History

2021-05-25 14:12:57 -07:00
---
2022-03-09 04:10:04 -08:00
id: build
title: Creating a build environment
2021-05-25 14:12:57 -07:00
sidebar_label: Building Meshtastic
---
Meshtastic uses the [PlatformIO](https://platformio.org) development environment, that enables easy multiplatform development and centralized tooling.
2021-05-25 14:12:57 -07:00
## Setup
2021-05-25 14:12:57 -07:00
1. Install PlatformIO, following the instructions available [here](https://platformio.org/platformio-ide).
2022-03-09 00:09:03 -08:00
2. Clone the `meshtastic-device` repository located [here](https://github.com/meshtastic/meshtastic-device). ([Instructions on cloning](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository))
2022-03-09 00:09:03 -08:00
3. Clone the [Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules)
```shell
2022-03-09 00:09:03 -08:00
git submodule update --init
```
4. Some utilities and scripts use the Python programming language, Downloads available [here](https://www.python.org/downloads).
2021-05-25 14:12:57 -07:00
## Building
1. Open the newly cloned folder in [Visual Studio Code](https://code.visualstudio.com).
1. To select the device you you wish to build for, first open your [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (windows: `Ctrl + Shift + P` or mac: `command + Shift + P` ) and enter: `platformio: Switch Project Environment` and select your target.
1. To build the firmware, simply run `PlatformIO: Build` from your command palette.
1. Finally flashing the firmware to your device is as easy as running `PlatformIO: Upload`
## Adding your own Hardware
2022-04-08 07:29:34 -07:00
The build system is modular. Adding a new board variant for an already supported architecture is straigtforward.
### Building for your own DIY hardware or mod that you don't want to distribute
2022-10-27 12:59:35 -07:00
1. go to the `variants` folder in the Meshtastic-device sourcecode and make a new directory for your hardware, let's call it `m5stack_atom` and copy an existing configuration you wanna modify
2022-04-08 07:29:34 -07:00
```shell
2022-10-27 12:59:35 -07:00
cd variants; mkdir m5stack_atom
cp heltec_v1/* m5stack_atom
cd m5stack_atom
```
2022-04-08 07:29:34 -07:00
2. modify the `platformio.ini` _in this subdirectory_ from the canonical define of the hardware variant (`HELTEC_V1` in this case) to `PRIVATE_HW` and make the `-I` on the `build_flags` point to the newly created dir.
```shell
2022-10-27 12:59:35 -07:00
[env:m5stack-atom]
extends = esp32_base
2022-10-27 12:59:35 -07:00
board = m5stack-atom
monitor_filters = esp32_exception_decoder
2022-04-08 07:29:34 -07:00
build_flags =
2022-10-27 12:59:35 -07:00
${esp32_base.build_flags} -D PRIVATE_HW -I variants/m5stack_atom
2022-04-08 07:29:34 -07:00
lib_deps =
${esp32_base.lib_deps}
```
2022-04-08 07:29:34 -07:00
3. edit the `variant.h` file _in this subdirectory_ to reflect the defines and configurations for your board. The example is very well commented.
4. build, run and debug until you are satisfied with the result.
### Adding a new off-the-shelf or DIY hardware that you want to distribute (e.g. add a new canon board)
1. do all of the above until your hardware runs fine
2. [Send in a proposal to add a new board](https://github.com/meshtastic/Meshtastic-device/issues/new?assignees=&labels=enhancement%2Ctriage&template=New+Board.yml&title=%5BBoard%5D%3A+)
3. if approved, go to (https://github.com/meshtastic/Meshtastic-protobufs) and send a Pull Request for the mesh.proto file, adding your board to the HardwareModel enum.
4. change your define in `platformio.ini` from `PRIVATE_HW` to `YOUR_BOARD`. Adjust any macro guards in the code you need to support your board.
5. add your board identifier to `configuration.h` on the Meshtastic-device repo and send in that Pull Request too.
6. wait for the Pulls to be merged back into Master.
7. profit :-)