Triggering SD Wav playback from USB Host HID keyboard locks Teensy

Status
Not open for further replies.

iancole

New member
We recently built a Bumblebee Transformer Magic Wheelchair using Teensy 3.6 and the Audio Shield, and now we are sharing our knowledge with another Magic Wheelchair build. We have a problem that arose during the Bumblebee build and are now encountering with the new build.

We are using a USB presentation remote which is an HID keyboard device. We are then triggering audio playback from the Teensy 3.6 SD card from those key press events.

When the Teensy receives rapid key press events resulting in audio playback, the Teensy will emit a specific tone, and then hard lock. Power must be cycled to resume use of the Teensy.

In order to duplicate the issue with minimal code, I blended the USB Host "Test" with the Audio Tutorial "Playing Music". We've verified this happens on multiple Teensy setups and with a standard USB keyboard as well as the presentation remote. Triggering with buttons connected to pins does not cause this behavior.

Note that the behavior differs if we switch from using the Teensy 3.6 SD Card to the Audio Shield SD Card (playback is interrupted, but it does not lock)

I'm open to any ideas on how to test & resolve this...

View attachment audio_locking.ino
 
More testing - PART 1

I enabled debugging output in the USBHost_t36 library.

With all my output debugging turned off, and only the USBHost debugging, this is what you see for a normal press:

Code:
KeyboardController Callback (member)
  KB Data: 00 00 4B 00 00 00 00 00 
  press, key=75
  unicode = 211
KeyboardController Callback (member)
  KB Data: 00 00 00 00 00 00 00 00 
  release, key=75

When the Teensy locks, you only see a portion of the message:
Code:
KeyboardController Callback (member)
  KB Data: 00 00 4B 00 00

The output above is most typical, but I've also seen it get more debug out before the lock - like this instance (I was trying the other SD Card slot and a different USB device:
Code:
KeyboardController Callback (member)
  KB Data: 00 00 3E 00 00 00 00 00 
  press, key=62
  unicode = 198

More Testing - PART 2

Moving to to the Audio Shield SD Card will occasionally lock as above, but more commonly, playback stops and cannot be restarted. I still see my keyboard messages, but I have to reboot the Teensy to get playback again​

I'm open to additional testing ideas...
 
Last edited:
We implemented a workaround (Thanks Mark & John) which stores the name of the audio file to play, the USB event handler finishes, and then on a subsequent loop, the filename is seen and played. By NOT starting the audio playback during the USB event handler, the lock condition is averted.
 
Oh, looks like we're still calling the user function from interrupt context, which isn't safe for the user's function to call the functions of most Arduino libs. Not good!

This really needs to be changed to use EventResponder or some other mechanism to later call the user function from main program context. Adding to my list of bugs to fix...
 
Status
Not open for further replies.
Back
Top