PlatformIO can not install the tinyUSB depenency

Hello Community I bought an RSP32S2 devboard and would like to use it with PlatformIO. Since there is no Ardoino Support currently I decided to try the Espress IDF. Which worked for the first test programm too. Now I tryed to load the USB example but it can not comple due to a permission error (I guess phyton?) which prevents PlatformIO to install the TinyUSB dependency.
This is the code which I am using: https://github.com/espressif/esp-idf/blob/master/examples/peripherals/usb/tusb_serial_device/main/tusb_serial_device_main.c

This is my error which I get while trying:
Executing task: platformio run --environment esp32-s2-saola-1 <

Processing esp32-s2-saola-1 (platform: espressif32; board: esp32-s2-saola-1; framework: espidf)
-------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s2-saola-1.html
PLATFORM: Espressif 32 (3.4.0) > Espressif ESP32-S2-Saola-1
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf 3.40301.0 (4.3.1) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.30100.210531 (3.1.0) 
 - tool-ninja 1.7.1 
 - toolchain-esp32s2ulp 1.22851.191205 (2.28.51) 
 - toolchain-riscv32-esp 8.4.0+2021r1 
 - toolchain-xtensa-esp32s2 8.4.0+2021r1
Installing ESP-IDF's Python dependencies
Collecting cryptography<35.0.0,>=2.1.4
  Using cached https://files.pythonhosted.org/packages/96/07/4d23f8e34e56d8eeb2c37cd5924928a01c3dd756a1d99e470181bc57551e/cryptography-3.4.8-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Collecting future>=0.15.2
  Using cached https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz
Collecting pyparsing<2.4.0,>=2.0.3
  Using cached https://files.pythonhosted.org/packages/de/0a/001be530836743d8be6c2d85069f46fecf84ac6c18c7f5fb8125ee11d854/pyparsing-2.3.1-py2.py3-none-any.whl
Collecting kconfiglib==13.7.1
  Using cached https://files.pythonhosted.org/packages/2a/a2/a046c1fd8f83c611d8610f2188b66ac3fdf0b64ca0b2b47563e9446d0031/kconfiglib-13.7.1-py2.py3-none-any.whl
Collecting cffi>=1.12
  Using cached https://files.pythonhosted.org/packages/e5/fe/1dac7533ddb73767df8ba26183a9375dde2ee136aec7c92c9fb3038108e3/cffi-1.15.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Collecting pycparser
  Using cached https://files.pythonhosted.org/packages/62/d5/5f610ebe421e85889f2e55e33b7f9a6795bd982198517d912eb1c76e1a53/pycparser-2.21-py2.py3-none-any.whl
Installing collected packages: pycparser, cffi, cryptography, future, pyparsing, kconfiglib
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Keine Berechtigung: '/usr/local/lib/python3.8/site-packages/pycparser-2.21.dist-info'
Consider using the `--user` option or check the permissions.

*** Error 1
Reading CMake configuration...
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/esp32-s2-saola-1/src/main.o
src/main.cpp:203:10: fatal error: tinyusb.h: No such file or directory

*****************************************************************
* Looking for tinyusb.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:tinyusb.h"
* Web  > https://platformio.org/lib/search?query=header:tinyusb.h
*
*****************************************************************

 #include "tinyusb.h"
          ^~~~~~~~~~~
compilation terminated.
Generating project linker script .pio/build/esp32-s2-saola-1/esp32s2.project.ld

How can I fix that problem?

PlatformIO should not attempt to install a Python package in the global Python packages site, but in its own isolated Python environment (e.g. ~/.platformio/penv/Lib/site-packages). Did you install PlatformIO globally via e.g. sudo -H pip3 install platformio or did you use the recommended installer script and appended your PATH as is recommended since it gives you the isolated envrionment?

What is the output of pio system info in a CLI?

I installed PlatformIO as Visual Studio Code extension. So I didn´t had to do anything else. Do I need to change something there?

This is my output of the pio system info command:


PlatformIO Core 5.2.3
Python 3.8.10-final.0
System Type linux_x86_64
Platform Linux-5.11.22-100.fc32.x86_64-x86_64-with-glibc2.2.5
File System Encoding utf-8
Locale Encoding UTF-8
PlatformIO Core Directory /home/djpx/.platformio
PlatformIO Core Executable /usr/local/bin/platformio
Python Executable /usr/bin/python3
Global Libraries 0
Development Platforms 3
Tools & Toolchains 24


It is clearly installed globally since that is not in ~/.platformio. When you do cd ~/.platformio and find . -name "pio", what does that return?

It only returns this:
./penv/bin/pio

This is the content:
#!/home/djpx/.platformio/penv/bin/python
# -- coding: utf-8 --
import re
import sys
from platformio.main import main
if name == ‘main’:
sys.argv[0] = re.sub(r’(-script.pyw|.exe)?$’, ‘’, sys.argv[0])
sys.exit(main())

The PlatformIO installer does not create ~/usr/local/bin/platformio, it must come from another installation method. What does sudo dpkg list | grep plat and apt list --installed | grep plat and pip3 list | grep plat output?

Sorry that you had to wait i can not execute that command since I am on a fedora system. So I am not able to use the dpkg command

Then use either dnf list installed | grep plat or rpm -qa | grep plat.

It seems it only finds the KDE platform
First command: kde-platform-plugin.x86_64
Secound command: kde-platform-plugin-4.11.22-27.fc32.x86_64

Well, last try, what does rpm -qf /usr/local/bin/platformio output?

The pip3 command returend nothing?

Sorry I over looked the pip3 list | grep plat command the output is:
platformdirs 2.4.0
platformio 5.2.3

And rpm -qf /usr/local/bin/platformio returned:
The file /usr/local/bin/platformio does not belong to a package
( I translated that since it was in my mainlanguage

Aha so it was installed via the global pip3 program.

It’s highly not-recommended to do that – you should do the following

  1. Go to the VSCode PlatformIO extension settings and make sure the checkboxes “Use Builtin PIOCore” is on, “Use Builtin Python” is on
  2. Uninstall your global PlatformIO installion (/usr/local/bin/platformio) – try sudo -H pip3 uninstall platformio or pip3 uninstall platformio
  3. Restart VSCode and check if you can still compile basic projects (builtin core is working)
  4. Use the CLI to check that pio system info now returns a PlatformIO Core Executable within /home/djpx/.platformio.
  5. Execute a pio platform update espressif32 while you’re at it to update the Espressif 32 platform.
  6. Check if that makes the “Could not install packages” error disappear now that it’s using the builtin-Python and builtin-core
  7. If you want PlatformIO to be globally accessible from the CLI, see docs.

And regarding

Using the master branch is generally incorrect since PlatformIO may use a different version. Per releases, the latest platform-espressif32 uses ESP-IDF 4.3.1 – you must use the same, which is esp-idf/examples/peripherals/usb/tusb_serial_device/main/tusb_serial_device_main.c at v4.3.1 · espressif/esp-idf · GitHub
.
Further it is most critical that the sdkconfig is correct. The project commands

to be set. Make sure you either

  1. Copy the sdkconfig.defaults file inside the PlatformIO project, delete the old sdkconfig.<environment name> file and re-run compilation to regenerate the sdkconfig.<environment name> from the defaults file
  2. or, use menuconfig to search and enable the CONFIG_USB_ENABLED and CONFIG_USB_CDC_ENABLED oiptions – CONFIG_IDF_TARGET should be set up automatically.

This should take care of the compilation error “tinyusb.h not found”.

1 Like

Should I do a backup before I do that or does it not touch my project files?

Well if your project files are exactly just the ESP-IDF example (esp-idf/examples/peripherals/usb/tusb_serial_device at v4.3.1 · espressif/esp-idf · GitHub), the no need to backup – everything is online. If you have already added custom code, you can ofc do a backup.

There should be no need to backup anything (e.g. ~./platformio/) as it can be reinstalled from scratch at anytime, and no personal data is stored therein.

I got already alot projects with the ESP8266 and ESP32 which I don´t like to lose since I spend alot time on them. So I am currently doing an update on all of the just to be sure. :grinning:

If you did no custom changes to files within ~/.platformio, everything is recoverable. In fact, the extension is programmed to recover from a completely deleted ~/.platformio folder through automatic reinstallation as if it were nothing.

Thank you alot. It seems to compile now and i finally can do some testing when I assemble the USB-port on my ESP32S2.

Are you interessted in steams games or some Avast BreachGuard/Avast AntiTrack Premium I still have them here unused and would like give it to you if you are interested as thank you for your time.