Include-Path Problem with atmelsam Platform and Adafruit TinyUSB Library?

So I created a new project using the Adafruit TinyUSB library resulting in the following platformio.ini:

[env:samd21_xpro]
platform = atmelsam
board = samd21_xpro
upload_protocol = cmsis-dap
framework = mbed
lib_deps = adafruit/Adafruit TinyUSB Library@^1.0.3

Then I copied

<project_folder>.pio\libdeps\samd21_xpro\Adafruit TinyUSB Library\examples\CDC\no_serial\no_serial.ino

to

<project_folder>\src\no_serial.cpp.

When trying to compile I get this message:

Compiling .pio\build\samd21_xpro\src\no_serial.o
src/no_serial.cpp:12:10: fatal error: Adafruit_TinyUSB.h: No such file or directory
**************************************************************************
* Looking for Adafruit_TinyUSB.h dependency? Check our library registry!  
*
* CLI  > platformio lib search "header:Adafruit_TinyUSB.h"
* Web  > https://platformio.org/lib/search?query=header:Adafruit_TinyUSB.h
*
**************************************************************************
 #include "Adafruit_TinyUSB.h"
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.

The suggested web search sports this:

Indeed Atmel SAM is listed as a supported platform. So where is the problem?

By the way: #includes of <Arduino.h> or <mbed.h> are not found either.

The library is meant for Arduino, not mbed-os.

Using it will most likely not work.

You can force PlatformIO to include the library in the build by disabling the compatibility check of the library dependency finder, as documented, by adding

lib_compat_mode = off

to the platformio.ini.

Thank you for your quick help!

Following it I replaced the framework by arduino in platformio.ini and included <Arduino.h> in main.cpp. I then got these messages:

Tool Manager: Installing platformio/framework-arduino-samd @ ~1.8.11
Downloading [####################################] 100%
Unpacking [####################################] 100%
Tool Manager: framework-arduino-samd @ 1.8.11 has been installed!
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel SAM (6.1.0) > Atmel SAMD21-XPRO
HARDWARE: SAMD21J18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (atmel-ice, blackmagic, jlink)
Error: This board doesn’t support arduino framework!
PACKAGES:

  • framework-arduino-samd 1.8.11
  • framework-cmsis 1.40500.0 (4.5.0)
  • framework-cmsis-atmel 1.2.2
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)

So it seems that I am out of luck. :cry:

Thank you anyway!

There are 4 boards which have this same chip and support the Arduino framework, see here, e.g. this one.

But TinyUSB is very ubiquitous and has been ported to many systems. The question is for what exactly you need it. Mbed-os has good USB support from my point of view, see e.g. here (or the exact mbed-os version that is printed for the framework-mbed package)

Hi Max

Thank you for your “Steilpass”! In fact I intend to develop a converter board to link an oscilloscope (Siglent SDS1104X-E) with a function generator (Stanford Research Systems DS345). The scope is a USB host and expects a USB client following the USBTMC / USB488 standard. Being a newby to USB software in general and especially to USBTMC I intended to use that project as a training camp. Because I have some prior experience with Atmel’s SAMD family, I bought a SAMD21 Xplained Pro board as a development base. To flatten the learning curve I was looking for a USB library supporting the USBTMC class together with some example code, and that’s how I stumbled over TinyUSB, albeit pretty focused on Linux. I did not want to change my entire software development environment being Windows 10 & platformIO (or Atmel Studio 7.0 for that matter) I was glad to find that TinyUSB was ported to Arduino and platformIO, not realizing at first, that SAMD21 XPRO does not support Arduino. Is it a bootloader problem in the end?

So to come back to your Steilpass: Do you know of a suitable library, supporting USBTMC (client side) with one or several examples and working with SAMD21 XPRO?

Thank you in advance for your expertise
Peter

Hm I’ve actually looked a bit further into this and there are indeed problems.

First of all, treating your SAMD21 XPRO as a SARA AFF board, as supported by PlatformIO, works in general, meaning you should get basic basic blinky examples and USB CDC exaples working. On the other side, the SODAQ core implementation for this board is not designed for TinyUSB, as opposed to the Adadafruit SAMD core.

In the Adafruit core, all the USB functionality that is in the core is guarded by “if not defined TINYUSB”

which allows it so that if that macro is activated, the TinyUSB library implementation can ‘take over’ and not interfer with the alternate USB functionality in the core, which is then disabled. Compare this to the same file in the SODAQ core and you will see that there are no such guards.

Of course one can make this work by also adding the appropriate guards in the core code, but that then gets quite messy with having to modify Arduino core files, and there may be other caveats causing this to not work.

What you can do is ask for help in regards that

But even if you are able to get an Arduino core with Adafruit TinyUSB working, you will see that the Adafruit TinyUSB puts an abstraction layer only above certain USB classes, see here, and USBTMC is not one of them. Thus you will have the additional burden of either calling the ‘lower level’ TinyUSB APIs directly or figuring out how to make it work with this abstraction layer.

Thus, if you don’t mind not working with PlatformIO and Arduino or mbed-os, you can straight up use TinyUSB directly and compile the USBTMC example for the SAMD21 XPRO board, which is explicitly supported, as you can also see in the code. I can literally just clone the repo, navigate to the example and build it (arm-none-eabi-gcc toolchain is of course preinstalled)

max@DESKTOP-V4T9ITU:~/temp/tinyusb/examples/device/usbtmc$ make BOARD=atsamd21_xpro all
Submodule 'hw/mcu/microchip' (https://github.com/hathach/microchip_driver.git) registered for path 'hw/mcu/microchip'
Cloning into '/home/max/temp/tinyusb/hw/mcu/microchip'...
Submodule path 'hw/mcu/microchip': checked out 'f7087f04783c896627061fc151fa3527b73733c7'
CC dcd_samd.o
[..]
CC vendor_device.o
LINK _build/atsamd21_xpro/usbtmc.elf
CREATE _build/atsamd21_xpro/usbtmc.bin
CREATE _build/atsamd21_xpro/usbtmc.hex

   text    data     bss     dec     hex filename
   8776     288    9160   18224    4730 _build/atsamd21_xpro/usbtmc.elf

Max, you are absolutely amazing :clap: all this in-depth investigation and even on a Sunday!

I have to admit that I am not sure to have understood all the ramifications of your information, so let me try to put in a nutshell what I conclude:

  • The Adafruit version is a subset without USBTMC which makes all the hassle to get the underlying Arduino framework running on SAMD21 XPRO a bit pointless.
  • The same applies to the SARA AFF board plus the question of uploading the code to it. It probably does not have the same EDBG processor for it and for debugging.
  • The idea of asking Adafruit and/or Sodaq to enhance their libraries to include SAMD21 XPRO and include the USBTMC/488 class/subclass might work, if they are as helpful as you are :wink:. But then again I think that such an attempt would be “Verhältnisblödsinn” (ratio nonsense?) in view of my one-off project.
  • The fact that Adafruit have put a guard rail around their USB implementation confirms my conclusions taken from the study of Atmel ASF code: Working on SAMD21 USB register level is tricky and there are many pitfalls. (That is why I opted either for ASF code for the lower software layers or relying entirely on a “ready-made” library such as Arduino.
  • The “original” TinyUSB library seems to be the only one natively supporting USBTMC. But it is squarely meant for a UNIX / Linux development environment. Well then, “been there, done that” before, but I had lots of support by my former colleagues, and even then I was not always sure to know what I was doing.

So the abstract of the nutshell is: I have to think over the various options to find the easiest way to go.

In fact I do have another option: At MJB - Embedded Firmware Resources there is a well-written reference design for USBTMC running on an AT91SAM7S controller. The software is clearly layered and extensively commented, so replacing the hardware abstraction layer by some Atmel ASF drivers & middleware should be possible. The question remains: Is it possible for me, too?

Be it what it is - a great thank you for all your work!

This is just a brief update to maxgerhardt’s helpful post.

I finally managed to import the “original” TinyUSB from GitHub - hathach/tinyusb: An open source cross-platform USB stack for embedded system into Microchip Studio 7.0 and got the USBTMX example to compile and work, following the “Getting started” doc. So it is proven now that TinyUSB is not strictly Linux / gcc / make.

However I did not try importing it into the Platformio environment.

1 Like