ESP-IDF: Difference between revisions
imported>Mirrexagon Add easy setup with nixpkgs-esp-dev |
Updated the requirements path to reflect ESP-IDF v5.0 removal of the root requirements.txt file. This still needs updating, as it doesn't currently result in a working ESP-IDF environment. |
||
| (4 intermediate revisions by 4 users not shown) | |||
| Line 6: | Line 6: | ||
<syntaxhighlight lang="sh"> | <syntaxhighlight lang="sh"> | ||
nix --experimental-features 'nix-command flakes' develop github:mirrexagon/nixpkgs-esp-dev# | nix --experimental-features 'nix-command flakes' develop github:mirrexagon/nixpkgs-esp-dev#esp-idf-full | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 22: | Line 22: | ||
== The manual way == | == The manual way == | ||
If you want to set up the environment yourself, here is one way to do it. | If you want to set up the environment yourself, here is one way to do it. | ||
{{Warning|As of ESP-IDF v5.0, the following guide does not work properly and results in errors. Any contributions toward a fix would be appreciated.}} | |||
=== Setting up the toolchain === | === Setting up the toolchain === | ||
ESP-IDF uses the Xtensa ESP32 GCC toolchain. Espressif hosts the official [https://github.com/espressif/crosstool-NG/releases prebuilt binaries] on GitHub. Sadly, these are not statically compiled, and do not work on NixOS without the use of a FHS environment. I will use <code>buildFHSUserEnv</code> to make the binaries work. Let's make a derivation out of this: | ESP-IDF uses the Xtensa or risc-v32 ESP32 GCC toolchain. Espressif hosts the official [https://github.com/espressif/crosstool-NG/releases prebuilt binaries] on GitHub. Sadly, these are not statically compiled, and do not work on NixOS without the use of a FHS environment. I will use <code>buildFHSUserEnv</code> to make the binaries work. Let's make a derivation out of this: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 40: | Line 42: | ||
stdenv.mkDerivation rec { | stdenv.mkDerivation rec { | ||
pname = "esp32-toolchain"; | pname = "esp32-toolchain"; | ||
version = "2021r2"; | version = "2021r2-patch3"; | ||
src = fetchurl { | src = fetchurl { | ||
# url = "https://github.com/espressif/crosstool-NG/releases/download/esp-${version}/riscv32-esp-elf-gcc8_4_0-esp-${version}-linux-amd64.tar.gz"; | |||
# hash = "sha256-F5y61Xl5CtNeD0FKGNkAF8DxWMOXAiQRqOmGfbIXTxU="; | |||
url = "https://github.com/espressif/crosstool-NG/releases/download/esp-${version}/xtensa-esp32-elf-gcc8_4_0-esp-${version}-linux-amd64.tar.gz"; | url = "https://github.com/espressif/crosstool-NG/releases/download/esp-${version}/xtensa-esp32-elf-gcc8_4_0-esp-${version}-linux-amd64.tar.gz"; | ||
hash = "sha256- | hash = "sha256-nt0ed2J2iPQ1Vhki0UKZ9qACG6H2/2fkcuEQhpWmnlM="; | ||
}; | }; | ||
| Line 87: | Line 91: | ||
pkgs.mkShell { | pkgs.mkShell { | ||
name = "esp-idf-env"; | name = "esp-idf-env"; | ||
buildInputs = with pkgs; [ | buildInputs = with pkgs; [ | ||
(pkgs.callPackage ./esp32-toolchain.nix {}) | (pkgs.callPackage ./esp32-toolchain.nix {}) | ||
| Line 98: | Line 101: | ||
bison | bison | ||
gperf | gperf | ||
pkg-config | |||
cmake | cmake | ||
| Line 120: | Line 123: | ||
python -m venv $IDF_PYTHON_ENV_PATH | python -m venv $IDF_PYTHON_ENV_PATH | ||
. $IDF_PYTHON_ENV_PATH/bin/activate | . $IDF_PYTHON_ENV_PATH/bin/activate | ||
pip install -r $IDF_PATH/requirements.txt | pip install -r $IDF_PATH/tools/requirements/requirements.core.txt | ||
else | else | ||
. $IDF_PYTHON_ENV_PATH/bin/activate | . $IDF_PYTHON_ENV_PATH/bin/activate | ||
| Line 145: | Line 148: | ||
* [https://github.com/bgamari/esp32.nix esp32.nix] provides nix expression for building the esp32 sdk as well as micropython. | * [https://github.com/bgamari/esp32.nix esp32.nix] provides nix expression for building the esp32 sdk as well as micropython. | ||
* [https://github.com/taktoa/esp32-baremetal esp32-baremetal] has an example how to build esp32 firmware without relying on an sdk. | * [https://github.com/taktoa/esp32-baremetal esp32-baremetal] has an example how to build esp32 firmware without relying on an sdk. | ||
* [https://specific.solutions.limited/projects/hanging-plotter/electronics tutorial] for setting up the prebuilt toolchain with vscode | * [https://web.archive.org/web/20240621182952/https://specific.solutions.limited/projects/hanging-plotter/electronics tutorial] for setting up the prebuilt toolchain with vscode | ||
[[Category:Guide]] | [[Category:Guide]] | ||