I have the Adafruit Feather with USB Host RP2040 board and cannot get everything setup in PlatformIO. Here’s my platform.ini:
[env:rpi2040]
platform = raspberrypi
board = pico
framework = arduino
lib_deps = https://github.com/sekigon-gonnoc/Pico-PIO-USB
build_flags =
-DUSE_TINYUSB_HOST
-DCFG_TUSB_CONFIG_FILE=\"tusb_config.h\"
I want my project to be able to connect to another Arduino board via the Host port and use a serial interface to talk to the board there.
When I compile my project, I get an error from the Pico SDK:
Processing rpi2040 (platform: raspberrypi; board: pico; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/pico.html
PLATFORM: Raspberry Pi RP2040 (1.14.0) > Raspberry Pi Pico
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, raspberrypi-swd)
PACKAGES:
- framework-arduino-mbed @ 4.1.5
- tool-rp2040tools @ 1.0.2
- toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 50 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Pico PIO USB @ 0.6.1+sha.fe9133f
|-- Adafruit TinyUSB Library @ 3.3.3
|-- SPI
Building in release mode
Compiling .pio\build\rpi2040\src\main.cpp.o
Compiling .pio\build\rpi2040\lib365\Pico PIO USB\pio_usb.c.o
Compiling .pio\build\rpi2040\lib365\Pico PIO USB\pio_usb_device.c.o
Compiling .pio\build\rpi2040\lib365\Pico PIO USB\pio_usb_host.c.o
In file included from .pio\libdeps\rpi2040\Pico PIO USB\src\usb_crc.h:4,
from .pio\libdeps\rpi2040\Pico PIO USB\src\pio_usb_device.c:16:
C:\Users\<user>\.platformio\packages\framework-arduino-mbed\cores\arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/common/pico_stdlib/include/pico/stdlib.h:11:10: fatal error: pico/stdio.h: No such file or directory
11 | #include "pico/stdio.h"
| ^~~~~~~~~~~~~~
I looked in that folder C:\Users<user>.platformio\packages\framework-arduino-mbed\cores\arduino/mbed and nowhere is there a “stdio.h” file anywhere!?
Have I missed an install somewhere? Am I doing something wrong?
This is ArduinoCore-mbed. Did you try it with the Arduino-Pico core instead? Just enable Win32 Long paths and Git long paths , then use the platformio.ini
[env:rpi2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipico
framework = arduino
lib_deps = https://github.com/sekigon-gonnoc/Pico-PIO-USB
build_flags =
-DUSE_TINYUSB_HOST
-DCFG_TUSB_CONFIG_FILE=\"tusb_config.h\"
Thank you! I guess I am not familiar enough with the various frameworks and options available.
This almost compiles now, errors are in my code now.
What I’m noticing now is that I can’t do either of these:
#include "Adafruit_USBH_CDC.h"
#include "Adafruit_TinyUSB.h"
since they are not found. Using <Adafruit...>
also doesn’t work. Instead I need this huge path:
#include "../../../.platformio/packages/framework-arduinopico/libraries/Adafruit_TinyUSB_Arduino/src/arduino/cdc/Adafruit_USBH_CDC.h"
#include "../../../.platformio/packages/framework-arduinopico/libraries/Adafruit_TinyUSB_Arduino/src/Adafruit_TinyUSB.h"
Do I need to update the PATH somehow? Or should I delete .pio
folder from my project and re-init, maybe there are old things in there from my previous attempts?
[Later]
Hmm, even after the long path includes, the linker fails with all the Adafruit references. I wonder if this library isn’t properly referenced…
You’re missing -DUSE_TINYUSB
to trigger the regular TinyUSB library inclusion. Otherwise it’s explicitly excluded.
The arduino/device_info/device_info.ino compiles fine for me.
Contribute to maxgerhardt/pio-rp2040-usbhost development by creating an account on GitHub.
Awesome! That was it, thanks you soooo much
OK, I have a new issue. So I had to reset the board by copying the blink.ino.elf.uf2 file
to the board as a storage device on my Win10 machine. Then it appears as COM10, but the LEDs don’t blink (not sure if that’s relevant). Then I successfully upload the rpi project, but after upload no COM port comes back. Even after pressing reset or unplugging and reconnecting. In fact, I have to hold down BOOT button while connecting for it to re-appear on my machine.
Any ideas why the sketch doesn’t make the board appear as a serial device after flashing?
It happens happens with your unmodified RP2040 USB Host
project as well, upload succeeds, but no port comes back.
When -DUSE_TINYUSB -DUSE_TINYUSB_HOST
is activated, the tusb_config.h
choses a configuration that does not have “USB Device” capabilities turned on, only “USB Host”. As thus, the firmware will not open a USB CDC Serial. The hardware serial (Serial1
) is still usable though. I’m not sure of the inner workings of this, or why it would not be possible for the Pico ot be a USB device on one set of pins and simulatenously be a USB host at other pins.
Frankly I’m not even sure why you need that library at all, if Adafruity_TinyUSB is working, you should be able to use that sketch without any additional libraries like that Pico-PIO-USB
. You can also see that they deliberately used Serial1
here to output to the hardware UART, they don’t try to be device and host at the same time.
/*********************************************************************
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
Copyright (c) 2019 Ha Thach for Adafruit Industries
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
/* This example demonstrates use of native controller as host (TinyUSB Host)
* Note:
* - For most mcu with only 1 native usb, Serial is not available. We will use Serial1 instead
*
* Host example will get device descriptors of attached devices and print it out as follows:
Device 1: ID 046d:c52f
Device Descriptor:
bLength 18
bDescriptorType 1
This file has been truncated. show original
I’m essentially trying to replicate what this project is doing:
So I tried removing PIC-PIO-USB
, but now it’s complaining about SPI.h
not being present.
In file included from .pio\libdeps\rpi2040\Adafruit TinyUSB Library\src\arduino\Adafruit_USBH_Host.cpp:36:
.pio\libdeps\rpi2040\Adafruit TinyUSB Library\src\arduino\Adafruit_USBH_Host.h:30:10:
fatal error: SPI.h: No such file or directory
I thought that was standard for Arduino?
Yes, but PIO’s LDF doesn’t recognize the dependency:
opened 05:32PM - 23 Jan 24 UTC
bug
ldf
What kind of issue is this?
- [X] **PlatformIO Core**.
If you’ve found… a bug, please provide an information below.
*You can erase any parts of this template not applicable to your Issue.*
------------------------------------------------------------------
### Configuration
**Operating system**: Windows 10 x64
**PlatformIO Version** (`platformio --version`): `PlatformIO Core, version 6.1.13`
### Description of problem
A Atmel SAM project that attempts to include Adafruit TinyUSB library of the latest version (2.3.2 down to and including 2.2.2) fails to properly compile, not finding the `SPI.h` header declared in the `Adafruit_USBH_Host.h` file. Version 2.2.1 compiles fine, because it did not have an include for SPI.h.
The LDF fails to find the dependency on SPI.h no matter the `lib_ldf_mode` setting (`deep+`, `deep`, `chain`, `chain+` tested and failed). This makes this library impossible to compile for the board in PlatformIO.
Per [community topic](https://community.platformio.org/t/spi-h-error-on-adafruit-neopixel-trinkey/38046).
#### Steps to Reproduce
1. Use `platformio.ini` and `src/main.cpp` provided below
2. Build
3. Observe build failure
4. Change version to `adafruit/Adafruit TinyUSB Library@2.2.1` and rebuild
5. Observe build success
### Actual Results
```
Compiling .pio\build\busylight\lib4ff\Adafruit_ZeroDMA\Adafruit_ZeroDMA.cpp.o
Compiling .pio\build\busylight\lib361\SPI\SPI.cpp.o
In file included from .pio\libdeps\busylight\Adafruit TinyUSB Library\src/Adafruit_TinyUSB.h:76,
from C:\Users\Max\.platformio\packages\framework-arduino-samd-adafruit\libraries\Adafruit_ZeroDMA\Adafruit_ZeroDMA.cpp:35:
.pio\libdeps\busylight\Adafruit TinyUSB Library\src/arduino/Adafruit_USBH_Host.h:30:10: fatal error: SPI.h: No such file or directory
```
### Expected Results
Compiles fine
### If problems with PlatformIO Build System:
**The content of `platformio.ini`:**
```ini
[env:busylight]
platform = atmelsam
board = adafruit_neotrinkey_m0
framework = arduino
lib_deps=
adafruit/Adafruit TinyUSB Library@2.3.2
lib_archive = no
build_flags=
-DUSE_TINYUSB
lib_ldf_mode = deep+
lib_ignore = USBHost
```
**Source file to reproduce issue:**
```cpp
#include <Arduino.h>
#include "Adafruit_TinyUSB.h"
void setup() {}
void loop() {}
```
### Additional info
Especially concerning are the messages in verbose mode that the LDF fail to evalute the TinyUSB macro `TU_CHECK_MCU` correctly.
>Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_TinyUSB_API.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_USBD_CDC.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_USBD_Device.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Warning! Classic Pre Processor is used for `C:\Users\Max\temp\trinkey\.pio\libdeps\busylight\Adafruit TinyUSB Library\src\arduino\Adafruit_USBH_Host.cpp`, advanced has failed with `Incorrect number of arguments to `TU_CHECK_MCU'`
Oh boy, so an 8 month old issue on PlatformIO… are there any workarounds? Sounds like going back to 2.2.2 might work?