- Git: https://github.com/espressif/esp-idf
- Supported Boards: ESP32, ESP32-C3, ESP32-C6, ESP32-S2, ESP32-S3, and more
- Documentation: https://docs.espressif.com/projects/esp-idf/en/latest/
- Additional Resources:
This is a project template for developing applications targeting ESP32-based microcontrollers using the micro-C target of Lingua Franca with the ESP-IDF framework.
You must use one of the following operating systems:
Linux— Officially supported are Debian & UbuntumacOSWindows— via WSL2
Your system must have the following software packages:
git— a distributed version control systemjava— Java 17python3— Python 3.8 or newercmake— Version 3.20 or newerninja— Build system
This template uses reactor-uc, the "micro C" target for Lingua Franca. Clone this repo with one of the following commands:
git clone https://github.com/lf-lang/reactor-uc.git --recurse-submodulesgit clone [email protected]:lf-lang/reactor-uc.git --recurse-submodulesAnd make sure that the REACTOR_UC_PATH environment variable is pointing to it:
export REACTOR_UC_PATH=/path/to/reactor-ucCreate a new repository based on this template, clone it recursively to your local machine and enter the directory from your favourite shell.
Make sure the esp-idf submodule is initialized:
git submodule update --init --recursiveIf you have Nix with flakes enabled, you can use the provided Nix configuration for a reproducible development environment:
# Enter development shell with default board (ESP32)
nix develop
# Or specify a different board
nix develop .#esp32c3
nix develop .#esp32
nix develop .#allThe Nix shell will automatically:
- Install all required dependencies
- Install ESP-IDF tools for your target board
- Set up the environment variables
Install the required packages for your system as per the ESP-IDF documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#manual-installation
After installing the ESP-IDF prerequisites, set up the ESP-IDF environment by running:
cd esp-idf
./install.sh esp32c6 # Replace with your board: esp32, esp32c3, esp32c6, all, etc.
source ./export.sh # Configure the development environment
cd ..You'll need to source export.sh every time you open a new terminal:
source ./esp-idf/export.shThis repository includes pre-commit hooks to automatically check your code before committing. To set up:
# Install pre-commit (if not already installed)
pip install pre-commit
# Install the git hook scripts
pre-commit install
# (Optional) Run against all files
pre-commit run --all-filesThe pre-commit hooks will automatically:
- Check for large files, merge conflicts, and private keys
- Validate JSON, YAML, TOML, and XML files
- Format CMake files
- Lint Markdown files
- Check shell scripts with shellcheck
- Format Nix files
- Check for common spelling mistakes
- Detect secrets and security issues
To skip pre-commit hooks temporarily (not recommended):
git commit --no-verifyIn this template we have integrated the Lingua Franca compiler lfc into
CMake. To build an application, first set the target board as an environment
variable:
export ESP_BOARD=esp32c6 # or esp32, esp32c3, etc.Then configure the project:
cmake -Bbuild \
-DESP_IDF_BOARD=$ESP_BOARD \
-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-$ESP_BOARD.cmake \
-GNinjaThis step will invoke lfc on the main LF application and configure the ESP-IDF
build system.
Build the application:
cmake --build build -j $(nproc)To rebuild the application after making changes, simply repeat the last command:
cmake --build build -j $(nproc)If CMake detects any changes to any files found in src/*.lf, the configure
step will be rerun automatically.
To flash the compiled binary to your ESP32 board:
cd build
ninja flashOr specify the serial port explicitly if auto-detection fails:
ninja flash -p /dev/ttyUSB0 # Linux/macOS
ninja flash -p COM3 # WindowsTo flash and immediately monitor the serial output:
ninja flash && ninja monitorPress Ctrl+] to exit the monitor.
To change build parameters, such as which LF application to build or the log level, we recommend that you modify the corresponding variable at the top of the CMakeLists.txt. Alternatively, you can override the variables from the command line:
cmake -Bbuild \
-DLF_MAIN=HelloEsp \
-DLOG_LEVEL=LF_LOG_LEVEL_DEBUG \
-DESP_BOARD=$ESP_BOARD \
-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-$ESP_BOARD.cmake \
-GNinjaAvailable parameters:
LF_MAIN— Name of the main LF file to compile (default:HelloEsp)LOG_LEVEL— Logging level (default:LF_LOG_LEVEL_WARN)- Options:
LF_LOG_LEVEL_ERROR,LF_LOG_LEVEL_WARN,LF_LOG_LEVEL_INFO,LF_LOG_LEVEL_DEBUG
- Options:
ESP_IDF_BOARD— Target board- Options:
esp32,esp32c3,esp32c6,esp32s2,esp32s3,esp32h2, etc.
- Options:
To delete all build artifacts from both CMake and LFC:
rm -rf src-gen buildlf-esp-idf-uc-template/
├── CMakeLists.txt # Main build configuration
├── esp-idf/ # ESP-IDF framework (submodule)
├── src/ # LF source files
│ ├── Blink.lf # LED blink example
│ ├── HelloEsp.lf # Hello world example
│ ├── Timer.lf # Timer example
│ └── lib/ # Reusable LF reactors
│ └── Led.lf # LED reactor library
├── sdkconfig # ESP-IDF configuration
├── flake.nix # Nix flake configuration
└── shell.nix # Nix shell environment
This template includes several example applications:
A hello world application that prints to the serial console.
cmake -Bbuild \
-DLF_MAIN=HelloEsp \
-DESP_BOARD=$ESP_BOARD \
-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-$ESP_BOARD.cmake \
-GNinja
cmake --build build -j $(nproc)Demonstrates timer usage with periodic events.
cmake -Bbuild \
-DLF_MAIN=Timer \
-DESP_BOARD=$ESP_BOARD \
-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-$ESP_BOARD.cmake \
-GNinja
cmake --build build -j $(nproc)A simple LED blink application that toggles the onboard LED.
cmake -Bbuild \
-DLF_MAIN=Blink \
-DESP_BOARD=$ESP_BOARD \
-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-$ESP_BOARD.cmake \
-GNinja
cmake --build build -j $(nproc)When using the Windows Subsystem for Linux on a Windows machine for development, there are a few extra steps to attach the ESP32 device to your WSL instance. The official instructions are reflected here. Install the required software and execute the following.
Open a PowerShell prompt as an administrator:
usbipd wsl listNote the busid of the ESP32 device. ESP32 boards typically show as
USB Serial Device or USB JTAG/Serial Debug Unit.
Attach the device using the following command:
usbipd wsl attach --busid <bus_id>This will mount the device to the WSL instance. In a WSL shell, check the device has been attached:
ls /dev/ttyUSB* # or /dev/ttyACM*