When working with devices like the ESP32 family of development boards, which are widely used in IoT projects, configuring udev becomes essential to ensure smooth operations. In this article, we’ll look into what udev is, why it’s crucial for ESP32 development, and how to configure it effectively, including creating a group for device access.

Understanding udev:

udev is a device manager for the Linux kernel. Its primary function is to manage device nodes in the /dev directory dynamically. When a new device is connected to a Linux system or when existing devices are modified or removed, udev dynamically creates, removes, or modifies the device nodes, ensuring that userspace applications can access and interact with them.

Importance of udev for ESP32 Development:

ESP32 development boards requires user interaction with the development environment for tasks like flashing firmware and monitoring output. Without proper udev configuration, developers will almost certainly encounter permission issues or difficulty in recognizing the connected ESP32 device, hampering the development workflow.

Configuring udev for ESP32 Development:

To configure udev for ESP32 development boards, follow these steps:

1. Identify the device:

First, connect your ESP32 development board to your Linux system via USB. Check if the device is detected using the lsusb command.

lsusb

Looking at my results you can see that I have 3 different ESP32 devices connected. The red device is an ESP32-S2 Saola board. This board utilizes and external USB to UART bridge from Silicon Labs. The yellow device is a ESP32-C6 DevKitM board. This board has the USB to UART bridge on the SoC. You’ll also notice that it has a JTAG transceiver also. Finally I have an ESP32-S2 Mini by WEMOS. This board doesn’t have a USB to UART bridge instead it uses Device Firmware Upgrade (DFU) to flash and monitor the board. Read my article “Using Device Firmware Upgrade” to learn more about DFU.

DeviceidVendoridProduct
ESP32-S2 Saola board10c4ea60
ESP32-C6 DevKitM board303a1001
ESP32-S2 Mini303a0002
Devices with their vendor and product IDs.

2. Create a group for device access:

It’s recommended to create a group specifically for devices like Espressif boards to manage permissions efficiently. Use the following command to create a group named “espressif” (you can replace “espressif” with your preferred group name):

sudo groupadd espressif

Now we need to add our user to the group so that we can access it’s resources. This is the command to add a user to a group “sudo usermod -aG <username>” where <username> is the name of the user being added. For this example I will add my Fedora user “fuser”:

sudo usermod -aG espressif fuser

We added our user to the espressif group, but if they are currently logged in they still will not be able to access the espressif groups resources. In order for that change to take effect you need to log out and back in. If you do not want to log out at this time you can use the “newgrp” command to temporarily change your primary group to the espressif group.

newgrp espressif

3. Setting the udev rules

First, you’ll need to create a udev rule to allocate the necessary permissions to the ESP32 device. To do this, generate a new file in the /etc/udev/rules.d directory. The filename should follow the format of PP-descriptive-name.rules, where PP denotes the priority, and the remainder of the name serves as a descriptive label. Priorities can range from 00 to 99, with lower numbers taking precedence over higher ones. For this example, let’s create a file named “99-espressif.rules” and insert the following rule:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="????", GROUP="espressif", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="espressif", MODE="0666"

Notice that we have three devices, but only two rules are provided. This is because two of the devices share the same idVendor. Therefore, we can use wildcards in the idProduct field to enable one rule to handle multiple devices with the same idVendor.

4. Reload the udev rules:

After creating the udev rule, reload the udev rules using the following command to apply the changes:

sudo udevadm control --reload-rules
sudo udevadm trigger

The first command ‘sudo udevadm control –reload-rules’ instructs udev to reload all the rules from the rules directory. This allows the new rule to take effect without requiring a reboot. The second command ‘sudo udevadm trigger’ triggers udev to reapply it’s rules based on the current device configurations.

Read more

Introduction

The ESP-IDF (Espressif IoT Development Framework) is a

Prerequisites

Before we begin ensure that you have the following prerequisites:

  • A computer running Fedora 39.
  • Access to the internet.
  • A basic familiarity with using the Linux command line interface (CLI).
  • An ESP32 development board to test our setup.

Step 1: Install Required Dependencies:

Open a terminal window and execute the following command to install the dependencies required for building ESP-IDF projects:

sudo dnf -y update && sudo dnf install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache dfu-util libusbx

Step 2: Download ESP-IDF:

Next, we’ll download the ESP-IDF git repository. We’ll start by going to the GitHub repository, as there are several releases to choose from.

Once we get to the the github page we can see the available releases by clicking on the tags link. For this example we will be using the v5.1.3 release. Once you click on the tag we will find instructions for cloning the release.




mkdir -p ~/development/SDKs/esp/
cd ~/development/SDKs/esp/
git clone -b v5.1.3 --recursive https://github.com/espressif/esp-idf.git esp-idf-v5.1.3
cd esp-idf-v5.1.3/

Now that we’ve cloned the repository we need to install tools. The tools are dependent on the board we will be developing on. We can install tools for specific boards or all boards supported by this version of the esp-idf. For ease and simplicity we wlll install the tools for all supported boards.

./install.sh all

Step 3: Set Up Environment Variables:

Now that we have the dependencies, ESP-IDF, and the tools installed we can started developing. In order to build and flash our binaries we need our environment variables setup properly. Luckily ESP-IDF has a script for that. We need to be in the ESP-IDF directory to source the script.

. ./export.sh

We can verify that everything so far is working by running the idf.py script. If we have the environment setup correctly it should be in our path so we can run it from anywhere.

idf.py --version

If everything went well we should see something like the following:

Step 4: Configure udev

When working with ESP32 boards and similar hardware, configuring udev becomes essential. The udev rules ensure that the systems recognizes the connected devices correctly and grant the necessary permission to flash and monitor your development board. For more information about configuring udev read my article, “Configuring udev for development devices” to learn more.

Step 5: Building Our First Project:

For a quick test of your setup we will copy one of the examples included with ESP-IDF.

cd ~/development/
cp -rf $IDF_PATH/examples/get-started/hello_world/ .

Once we have our project we need to set the target and build it. With ESP-IDF v5.1.3 we have several targets available:

Usage: idf.py set-target [OPTIONS] {esp32|esp32s2|esp32c3|esp32s3|esp32c2|esp32c6|esp32h2|linux}

I will be using an ESP32S2 Saolo board. I’ll set the appropriate target and then build.

cd hello_world
idf.py set-target esp32s2
idf.py build

Step 6: Flash and Monitor:

We will flash and monitor our newly built application using the UART bridge on the ESP32S2 Saolo board. The idf.py script will try to automatically connect to your esp32 board. If you have more than one UART bridge connected to your development machine you can specify which one use the “-p” option for idf.py.

idf.py -p /dev/ttyUSB0 flash
idf.py -p /dev/ttyUSB0 monitor

Alternatively you can issue both commands with on the same command line.

idf.py -p /dev/ttyUSB0 flash monitor

When you’re done monitoring the serial output you can exit by pressing “CTRL + ]”

Read more