Hello!
I'm going to walk you through setting up the ESP-IDF inside of VSCode with Devcontainers.
This worked for me with the immutable fedora-based distro Aurora, though the steps should be similar for any distro.
For non-immutable (mutable?) linux distros you don't have to install the base ESP-IDF in a devcontainer, though I would still recommend it.
- Install VSCode. In Aurora this is easy, just enable dev mode:
ujust devmode. - Devmode should set up Dev Containers in vscode automatically. If it does not, or you're not using aurora, install Dev Containers.
- Open up vscode and head to the Dev Containers extension. Add a new dev container and select
ESP-IDF. - Let it download/setup the container. This will take a while.
- Vscode should now open a new window with no extensions except
esp-idf. - Click on the
esp-idfextension icon on the left. It might complain you don't have an active project. ClickActivate Anyway.
At this point if you click detect at the bottom (The Serial Port selection button), you're going to get a wonderful spawn udevadm ENOENT error. Not great.
Let's fix it.
- Inside your dev container's
.devcontainer/Dockerfile, add the following line before the finalRUNcommand:
RUN apt-get update -y && apt-get install udev -y
- Now open up your
.devcontainer/devcontainer.json. Add this to the json config file:
"privileged": true,
- After you save these two files a prompt should appear asking you to rebuild the dev container. Select Rebuild. (If you don't see this prompt, rebuild it manually.)
I hate having all my important code stored inside of Docker volumes. It just feels bad.
I'd much rather these files live somewhere in my home directory where I can read, modify, source control and just general manage them without having to open up a container.
- Inside of
devcontainer.json, add the following:
"mounts": [
"source=<some local directory>,target=/projects,type=bind"
],
Note: Replace <some local directory> with the location where you'd like all your esp-idf projects to live. I chose /home/codezombie/code/esp-idf-projects.
- Rebuild the container.
Now when you create a project with the ESP IDF new project wizard, make sure you select /projects when it asks you to Enter Project directory.
- Now, with the container rebuilt and with the ESP-IDF
commandsbar open, clickAdvancecd->New Project Wizard.
Follow the wizard through to create a project for your desired board. If you're using a custom projects mount from the previous section, enter your target directory in Enter Project Directory.
- In the New Project Wizard I chose the
hello worldtemplate. You can choose whatever you want, buthello worldwill be the simplest way to get console output, so I'm going with that. - After the project creates you should be able to build and flash the esp32 at this point. Try that, then open up the serial monitor. If it connects and you see a bunch of output from the esp32, you're done! If not, keep reading...
If after flashing you're not getting serial output, or your esp is not even being detected by your system any more, fear not:
- At the bottom of vscode, click the little gear icon
SDK Configuration Editor - Search for
console. You should see a categoryESP-STDIOshow up with the parameterChannel for console output. Set this toCDC USB. - Click
save - Now, find the
CMakeLists.txtfile in the root of your project folder. (NOTE: there is anotherCMakeLists.txtfile inmain/. That's not the one.) - Inside this file you'll see the line:
idf_build_set_property(MINIMAL_BUILD ON). Comment it out with an octothorpe (#). - Rebuild The project, flash it, and open the serial monitor.
You should see serial output!
Congrats, it's all set up. glhf.