mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 13:01:10 +02:00
Page:
Compiling esp32 port with docker
Pages
Adding Board Profles
Board FreeSOC
Board Arduino Due
Board BLACK F407VE
Board BLACK F407ZE
Board BLACK F407ZG
Board Crazyflie2
Board Espruino Pico
Board FEZ Cerb40 II
Board FEZ Cerb40
Board FEZ Lemur
Board G30HDR
Board HydraBus V1.0
Board NUCLEO F401RE
Board NetduinoPlus2
Board Nucleo F767ZI
Board Olimex STM32 405STK
Board Olimex STM32 E407
Board OpenMV
Board STM32F401 Discovery
Board STM32F407 Discovery
Board STM32F429
Board STM32F746 Discovery
Board Teensy 3.1 3.5 3.6
Board Tiva TM4C123G Launchpad
Board VCC GND STM32F407VET6 Mini
Board profile configuration for RomFS
Boards Summary
Build Troubleshooting
Building Micropython Binaries
Building st flash
Bundling and deploying application code and files
Collections module
Compiling esp32 port with docker
ContributorGuidelines
CrossBranch
Developing on a microcontroller
Differences
ESP32 debugging
Examples
FAQ
Floating Point Support
Getting Started Compiling Micropython for Ubuntu 16.04
Getting Started STM
Getting Started
HY STM32F4xxCore144
Hardware API
Home
Improving performance with Viper code
Instrumenting code using GPIOs
LCD driver
LTO
Learn MicroPython
Memory Manager
MicroPython New Port Development Guide
MicroPython on Mac OSX
MicroPythonVsELua
Micropython Git Development Workflow
PPP on ESP32
PWM Timers
Performance
Programming Debugging the Pyboard using ST‐Link v2
ProjectsUsingMicroPython
Pyboard Firmware Update
STM32F405 Timer Triggering
STM32F405 pinouts
Securing a MicroPython System
Servos
Soft reset
Standard Library Coverage
Symbolic Debugging for STM32
Threads
Timebase calculation and Clock sources
Timer Implementation
Timer capture mode
Timer one shot
Tips and Tricks
VS Code
Watchdogs, Crash prevention, Crash recovery
Clone
5
Compiling esp32 port with docker
Andrew Leech edited this page 2024-07-25 16:04:24 +10:00
The esp32 port requires a configured ESP IDF development environment to compile. Espressif provide a docker container that has this all set up and ready to go which can be used to simplify building the firmware, particularly if you want to try building under different IDF versions.
This script can be used as a wrapper to automate the process of running the compile inside the appropriate docker container without needing any additional configuration of your pc. This works with Linux or Windows/WSL2 with the official docker tools installed.
If you're using Windows/WSL2 and want to flash the board directly the WSL USB Manager tool can simplify connecting your usb devices through to WSL.
cat << "EOF" > ~/.local/bin/esp-compile
#!/bin/bash
SCRIPTPATH=$(readlink --canonicalize-existing "${BASH_SOURCE[0]}")
# Wrapper script to build / flash esp32 boards inside the official ESP IDF docker container
# Usage: esp-compile <IDF_VER> <BOARD> <port if want to deploy> <extra args if needed>
# Examples
# esp-compile v5.0.4 ESP32_GENERIC /dev/ttyACM0
# esp-compile v5.2.2 ESP32_GENERIC
# esp-compile v5.2.2 ESP32_GENERIC_C3 /dev/ttyACM0
# esp-compile v5.2.2 ESP32_GENERIC_S3 clean
# esp-compile v5.2.2 ESP32_GENERIC_S3 /dev/ttyACM1 BOARD_VARIANT=FLASH_4M
if [ ! -f /.dockerenv ]; then
# If not running in docker container, parse arguments then re-run this same script inside a new esp idf container
if [ "$1" == "" ]; then echo "$0 IDF_VER BOARD <DEPLOY_PORT> <extra args>"; exit; fi
IDF_VER=$1
BOARD=$2
if [[ $3 == /dev/* ]]; then
DEPLOY_PORT=$3
shift
fi
shift;shift
ARGS="${@}"
CD=$(pwd)
docker run -it --rm \
-e BOARD=$BOARD -e ARGS="$ARGS" -e DEPLOY_PORT=$DEPLOY_PORT -e UID=$(id -u) \
-v "$CD":"$CD" -v"$SCRIPTPATH":"$SCRIPTPATH" -v /sys/bus:/sys/bus -v /dev:/dev \
--net=host --privileged -w "$CD" espressif/idf:$IDF_VER bash "$SCRIPTPATH"
else
# Now we're running inside the IDF container
if [ "$(id -u)" != "$UID" ]; then
# create new user with ID that matches the user who called this script (who should own the source tree)
useradd -ms /bin/bash -g root -G sudo -u $UID esp;
# now re-run this script as that new user
# this ensures that created binary files are owned by the calling user
su esp -m -c "$SCRIPTPATH"
else
# Now we're inside the container, running as the target user
. /opt/esp/entrypoint.sh
export HOME=/tmp
# inform git that we're in a trusted environemnt (container)
git config --global --add safe.directory '*';
if [ ! -e mpy-cross/build/mpy-cross ]; then
make -C mpy-cross
fi
echo_and_run() { echo -e "\n\$ $*\n" ; "$@" ; }
# Build the firmware
make -C ports/esp32 BOARD=$BOARD submodules
if [ "$DEPLOY_PORT" == "" ]; then
# Just build the firmware
echo_and_run \
make -C ports/esp32 BOARD=$BOARD $ARGS
else
# build and flash the firmware
echo_and_run \
make -C ports/esp32 BOARD=$BOARD $ARGS deploy PORT=$DEPLOY_PORT
fi
fi # end of user
fi # end of container
EOF
chmod +x ~/.local/bin/esp-compile