Skip to content

Instantly share code, notes, and snippets.

@KunYi
Last active April 30, 2026 08:13
Show Gist options
  • Select an option

  • Save KunYi/4dcff34cf870808be855c48356736213 to your computer and use it in GitHub Desktop.

Select an option

Save KunYi/4dcff34cf870808be855c48356736213 to your computer and use it in GitHub Desktop.
build meshtastic firmware for heltec LoRa 32 v2.0

Build meshtastic firmware (2.5.16.c3d60342) for Heltec LoRAa 32 v2

$ mkdir -p /tmp/pio
$ cd /tmp/pio
$ virtualenv .
$ source bin/activate
$ pip install -U platformio
$ git clone https://github.com/meshtastic/firmware.git --recurse-submodules # pull source code
$ cd firmware
$ pio run -e heltec-v2_0 # kick-off build process

...
Building in release mode
Using meshtastic platformio-custom.py, firmware version 2.5.16.c3d60342 on heltec-v2_0
Using flags:
-DAPP_VERSION=2.5.16.c3d60342
-DAPP_VERSION_SHORT=2.5.16
-DAPP_ENV=heltec-v2_0
-DUSERPREFS_TZ_STRING=\"tzplaceholder                              
...
Processing heltec-v2_0 (board: heltec_wifi_lora_32_V2; platform: platformio/espressif32@6.9.0; framework: arduino)
Indexing .pio/build/heltec-v2_0/libFrameworkArduino.a
Linking .pio/build/heltec-v2_0/firmware.elf
.pio/libdeps/heltec-v2_0/Crypto/AESEsp32.cpp:33:5: warning: type of 'esp_aes_setkey' does not match original declaration [-Wlto-type-mismatch]
 int esp_aes_setkey(unsigned char *ctx, const unsigned char *key,
     ^
/home/kunyi/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aes.h:184:5: note: 'esp_aes_setkey' was previously declared here
 int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
     ^
/home/kunyi/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/mbedtls/mbedtls/include/mbedtls/aes.h:184:5: note: code may be misoptimized unless -fno-strict-aliasing is used
Retrieving maximum program size .pio/build/heltec-v2_0/firmware.elf
Checking size .pio/build/heltec-v2_0/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  29.7% (used 97252 bytes from 327680 bytes)
Flash: [========  ]  84.5% (used 2048017 bytes from 2424832 bytes)
Building .pio/build/heltec-v2_0/firmware.bin
esptool.py v4.5.1
Creating esp32 image...
Merged 27 ELF sections
Successfully created esp32 image.
esp32_create_combined_bin([".pio/build/heltec-v2_0/firmware.bin"], [".pio/build/heltec-v2_0/firmware.elf"])
Generating combined binary for serial flashing
    Offset | File
 -  0x1000 | /tmp/pio/firmware/.pio/build/heltec-v2_0/bootloader.bin
 -  0x8000 | /tmp/pio/firmware/.pio/build/heltec-v2_0/partitions.bin
 -  0xe000 | /home/kunyi/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin
 - 0x10000 | /tmp/pio/firmware/.pio/build/heltec-v2_0/firmware.bin
Using esptool.py arguments: --chip esp32 merge_bin -o /tmp/pio/firmware/.pio/build/heltec-v2_0/firmware.factory.bin --flash_mode dio --flash_freq 40m --flash_size 8MB 0x1000 /tmp/pio/firmware/.pio/build/heltec-v2_0/bootloader.bin 0x8000 /tmp/pio/firmware/.pio/build/heltec-v2_0/partitions.bin 0xe000 /home/kunyi/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 /tmp/pio/firmware/.pio/build/heltec-v2_0/firmware.bin
esptool.py v4.5.1
Wrote 0x205a50 bytes to file /tmp/pio/firmware/.pio/build/heltec-v2_0/firmware.factory.bin, ready to flash to offset 0x0

$ cd .pio/build/heltec-v2_0
$ esptool.py --port /dev/ttyUSB0 --chip esp32 --baud 460800 write_flash 0x0 firmware.factory.bin # download into device flash

or to edit /variants/heltec_v2/platformio.ini and add the below context into the file

monitor_speed = 115200
upload_protocol = esptool
;upload_port = /dev/ttyUSB0
upload_speed = 460800

than run the below command

$ pio run -e heltec-v2_0 --upload-port /dev/ttyUSB0 --monitor-port /dev/ttyUSB0 --target upload # need add 
@jkedra
Copy link
Copy Markdown

jkedra commented Dec 12, 2025

Whow, thank you a lot for the recipe, it works flawlessly.

@szampardi
Copy link
Copy Markdown

still works on v2.7.22.96dd647-138-ge19f53105! thanks a lot

 1457  cd /usr/local/src/
 1458  paru -Ss platformio
 1459  paru -S platformio-core
 1460  paru -S platformio-core-udev
 1461  git clone https://github.com/meshtastic/firmware.git --recurse-submodules
 1462  cd firmware/
 1463  ls
 1464  pio run -e heltec-v2_0
 1465  paru -S python-pip
 1466  pio run -e heltec-v2_0
 1467  paru -Ss intelhex
 1468  paru -S python-intelhex
 1469  paru -Ss grpc
 1470  paru -Ss grpc|grep py
 1471  paru -S python-grpcio python-grpcio-tools
 1472  paru -Ss protob|grep py
 1473  pio run -e heltec-v2_0
 1474  grep erase ~/bash_history.backup.202*
 1475  ls /dev/ttyUSB1 
 1476  sudo esptool.py --port /dev/ttyUSB1 --baud 115200 erase_flash
 1477  sudo esptool --port /dev/ttyUSB1 --baud 115200 erase_flash
 1478  paru -Ss esptool
 1479  paru -S esptool
 1480  sudo esptool.py --port /dev/ttyUSB1 --baud 115200 erase_flash
 1481  sudo esptool.py --port /dev/ttyUSB1 --chip esp32 --baud 460800 write_flash 0x0 /usr/local/src/firmware/.pio/build/heltec-v2_0/firmware-heltec-v2_0-2.7.23.e19f531.factory.bin
 1482  sudo esptool.py --port /dev/ttyUSB1 --baud 115200 erase_flash
 1483  sudo esptool.py --port /dev/ttyUSB1 --chip esp32 --baud 460800 write_flash 0x0 /usr/local/src/firmware/.pio/build/heltec-v2_0/firmware-heltec-v2_0-2.7.23.e19f531.factory.bin  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment