USB Host Shield examples don't compile in the Arduino IDE

Status
Not open for further replies.
Can someone please help me? I know this has to be something really stupid that I am missing.
All of the examples from USB_Host_Shield_2.0 And UHS30 never get to upload because they All fail compiling. All other sketches and examples compile and upload fine.

Teensy 3.1 and a Circuits@Home USB Host Shield:
Arduino 1.0.6, 1.6.2, or 1.6.3 on Win7
Arduino 1.6.2 or 1.6.3 on Ubuntu 14.04LTS
Teensydrino 1.22

Correctly located libraries:
spi4teensy3 (GitHub zip file from xxxajk)
USB_Host_Shield_2.0 (GitHub zip file from felis)
UHS30 (GitHub zip file from felis)

spi4teensy3 speedtest compiles and uploads without errors, (from the same library folder) results:

Start
Time to write 10485760 bytes: 3832 ms (4 sec)
2736.367432 Bytes/msec
2736367.500000 Bytes/sec


Example USBHIDBootKbdAndMouse from USB_Host_Shield_2.0 returns:

Arduino: 1.6.3 (Windows 7), TD: 1.22, Board: "Teensy 3.1, Serial, 96 MHz optimized (overclock), US English"

Build options changed, rebuilding all
Using library USB Host Shield Library 2.0 in folder: C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20
Using library spi4teensy3 in folder: C:\Program Files (x86)\Arduino\Arduino\libraries\spi4teensy3 (1.0.x format)
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI (1.0.x format)

C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=122 -DARDUINO=10603 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20 -IC:\Program Files (x86)\Arduino\Arduino\libraries\spi4teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI C:\Users\Frank\AppData\Local\Temp\build8167078760123349979.tmp\USBHIDBootKbdAndMouse.cpp -o C:\Users\Frank\AppData\Local\Temp\build8167078760123349979.tmp\USBHIDBootKbdAndMouse.cpp.o
In file included from C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/Usb.h:36:0,
from C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hid.h:20,
from C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hidboot.h:20,
from USBHIDBootKbdAndMouse.ino:1:
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/usbhost.h: In member function 'uint8_t MAX3421e<SPI_SS, INTR>::regRd(uint8_t)':
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/usbhost.h:257:9: error: 'SPI' was not declared in this scope
SPI.transfer(reg);
^
In file included from C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hidboot.h:20:0,
from USBHIDBootKbdAndMouse.ino:1:
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hid.h: In member function 'virtual HIDReportParser* HID::GetReportParser(uint8_t)':
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hid.h:159:63: warning: no return statement in function returning non-void [-Wreturn-type]
virtual HIDReportParser* GetReportParser(uint8_t id) {};
^
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hid.h: In member function 'virtual bool HID::SetReportParser(uint8_t, HIDReportParser*)':
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/hid.h:170:73: warning: no return statement in function returning non-void [-Wreturn-type]
virtual bool SetReportParser(uint8_t id, HIDReportParser *prs) {};
^
Error compiling.

Example USB_Host_Shield_2.0 board_qc returns:

Arduino: 1.6.3 (Windows 7), TD: 1.22, Board: "Teensy 3.1, Serial, 96 MHz optimized (overclock), US English"

Build options changed, rebuilding all
Using library USB Host Shield Library 2.0 in folder: C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20
Using library spi4teensy3 in folder: C:\Program Files (x86)\Arduino\Arduino\libraries\spi4teensy3 (1.0.x format)
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI (1.0.x format)

C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=122 -DARDUINO=10603 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20 -IC:\Program Files (x86)\Arduino\Arduino\libraries\spi4teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI C:\Users\Frank\AppData\Local\Temp\build8167078760123349979.tmp\board_qc.cpp -o C:\Users\Frank\AppData\Local\Temp\build8167078760123349979.tmp\board_qc.cpp.o
In file included from C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/Usb.h:36:0,
from C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/usbhub.h:20,
from board_qc.ino:6:
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/usbhost.h: In member function 'uint8_t MAX3421e<SPI_SS, INTR>::regRd(uint8_t)':
C:\Program Files (x86)\Arduino\Arduino\libraries\USB_Host_Shield_20/usbhost.h:257:9: error: 'SPI' was not declared in this scope
SPI.transfer(reg);
^
Error compiling.

Example UHS30 board_qc returns:

Arduino: 1.6.3 (Windows 7), TD: 1.22, Board: "Teensy 3.1, No USB, 96 MHz optimized (overclock), US English"

Build options changed, rebuilding all
Using library Wire in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire (1.0.x format)
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI (1.0.x format)

C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=122 -DARDUINO=10603 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_DISABLED -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI C:\Users\Frank\AppData\Local\Temp\build2842012493108537655.tmp\board_qc.cpp -o C:\Users\Frank\AppData\Local\Temp\build2842012493108537655.tmp\board_qc.cpp.o
board_qc.ino:28:21: fatal error: dyn_SWI.h: No such file or directory
compilation terminated.
Error compiling.
 
Last edited:
Got it??? All the examples compile fine, until Teensyduino 1.22 is installed and any Teensy Board is chosen (both Win7 & Ubuntu). Dose this mean that Teensydrino 1.22 no longer supports the examples in USB_Host_Shield_20? (And UHS30?) Is there a previous version that would work for a mouse/keyboard connected to a USB Host Shield?
 
I suggest trying Arduino 1.0.6 or 1.6.1 and Teensyduino 1.21. If that works, then you are seeing either a regression in Teensyduino 1.22 or, more likely, a regression due to refactoring and toolchain changes in Arduino 1.6.2/1.6.3
 
Nantonos, Thank you so much for that link!!! Being able to see the Windows installer on different versions was informative for an amateur like me:
Teensydrino 1.22 for Arduino 1.0.6, 1.6.1, 1.6.1j7, 1.6.2, 1.6.3
Teensydrino 1.21 for Arduino 1.0.5, 1.0.6, 1.6.0, 1.6.1, 1.6.1j7
Teensydrino 1.20 for Arduino 1.0.5, 1.0.6

Crossed with available for download from arduino.cc: 1.0.5r2, 1.0.6, 1.6.0, 1.6.1, 1.6.2, 1.6.3

UHS2.0 Example Code Compatibility for Windows 7:
Teensy> 1.20, 1.21, 1.22
1.6.3 n/a, n/a, Fail
1.6.2 n/a, n/a, Fail
1.6.1 n/a, Fail, Fail
1.6.0 n/a, Fail, na
1.0.6 Fail, Fail, Fail
1.0.5 Fail, n/a, n/a


The Good News:
1. All the Arduino examples and Teensy examples seem to compile and upload on the combinations above!
2. spi4teensy3 worked on all the combinations above when connected as a Teensy!
3. All of the UHS examples successfully compile when Not connected as a Teensy (example: Tools, Board, Arduino Uno, or anything not Teensy, then click Verify.)

A Pattern:
In every case above, as soon as I click Tools, Board, Teensy1.3, then ALL of the UHS examples (and only the UHS examples) all return an Error Compiling in the IDE. I suspect the same pattern for Ubuntu?

I don't have much of a project yet; I just got the UHS as a gift and wanted to see if I could get a USB mouse to squeak serial by borrowing USBHIDBootKbdAndMouse. Can anyone help?
 
Last edited:
This sounds like the UHS library does not have appropriate #defines for Teensy 3.1. So I would look at the code. Its common to see code which checks for AVR, and checks for the SAM processor used on Due, and then gives up. In some cases the SAM code is actually testing for ARM and would work. In some cases the AVR code would work because Teensy has some AVR emulation compatibility stuff. Or you may be unlucky and need to write a bunch of low-level register-acessing code specific to the Kinetis ARM chip.

If you haven't already, look at the UHS github
https://github.com/felis/USB_Host_Shield_2.0
and check for already open issues that may be relevant. The readme claims that Teensy 3.x is supported, so failure to compile is a bug.

One thing occurs to me. You added a #include <spi4teensy3.h> - is that instead of, or in addition to, the #include <SPI.h>?

I don't have the USB Host Shield or any experience with it, so others will need to help you past this point.
 
Lots of claims of support, that's why it feels like a stupid mistake on my part rather than a bug. What you say makes a lot of sense. Seriously, thank you for your help! :) In the hope that others might also help, I will try to answer the questions you left open for me.

It would be nice if someone could reproduce the error, you wouldn't even need a USB Host Shield or a Teensy, just the renamed USB_Host_Shield_20 library, open any USB Host Shield 2.0 example, and click Verify. If you get an Error Compiling, but not when the board is changed to to Arduino Uno in the IDE, then you have the same problem. Then I would feel a lot more comfortable that I was the first one to stumble on this.

Yes, I have been snooping around at GitHub repositories for felis, PaulStoffregen, xxxajk, and also the many articales at pjrc.com and circuitsathome.com, but it sounds like a great idea to also report it at GitHub.
I know I shouldn't be poking around at UHS30 Alpha files because of my noob status, but It is also really really hard to believe that this happens with all of those files as well, or that every UHS on a Teensy suddenly stopped working on every version of Teensydrino. Since there are no immediately obvious issues with UHS 2.0 at Git, and the UHS30 readme says
“Freescale Kinetis native full-speed host support! NOTE! To use the Teensy 3.0/3.1/LC in host mode, select "No USB" from the tools menu for USB Type”
leads me to believe many others have this working, and its just something stupid I missed on my end.
I don't mind slowly picking away at reworking some code for this, but I don't think reworking all the examples is the problem.

Re: USBHIDBootKbdAndMouse.ino (stolen UHS 2.0 example)
Funny you mentioned it after I did this. I was also curious about the double include. 39 of the 42 UHS examples have this in the beginning:
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif
I know nothing about code, so I chopped it out and tried it with one or the other spi. Of course there was no success. I was under the impression it needs both, unless there is no teensy, then it only uses SPI.h.
BTW: Oleg's “MAX3421E USB Host controller SPI test” has the same error compiling (on my system) when cut and pasted from https://www.circuitsathome.com/mcu/arduino-usb-host-part-2-classes

Does anyone here have a USB Host Shield working with a Teensy (or at least just the software)?
Can anyone help me get this loaded right? It kind of seemed like a Teensydrino problem to me, but I don't know.
Any help is greatly appreciated :)
 
Last edited:
I do not have a host shield to test, but the example code compiled for me as long as "No USB" is selected in Tools-> USB Type and the CPU speed was bumped down to 16mHz. Also, made sure each individual library within UHS30-master is dragged into libraries folder, not contained within a UHS30-master subfolder.
 
Status
Not open for further replies.
Back
Top