Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
TinyUSB: Open-source cross-platform USB Host/Device stack for embedded systems (tinyusb.org)
150 points by homarp on May 23, 2022 | hide | past | favorite | 18 comments


This seems like a really great project; it's well-designed and supports quite a variety of different MCUs (although host mode seems to be "not implemented" in anything except the rPi).

I wonder how much work it would be to create a no_std sys crate to use this from a rust context. (I see some interest from Tock users in the GitHub issue discussions.)

The github repo for the TinyUSB project: https://github.com/hathach/tinyusb

EDIT:

I spoke too soon, there's already a tinyusb-sys crate here [0]!

[0]: https://lib.rs/crates/tinyusb-sys


I've used TinyUSB to turn a Raspberry Pi 2040 (the very cheap microcontroller) into a USB keyboard that you plug your morse key into and send morse which the RPI 2040 converts into key presses and sends to the computer.

TinyUSB was very easy to use. It was my first foray into USB devices and adapting the example code was straight forward.

I wrote the code in C but I could have done it in python also but I didn't as you need ms accuracy for decoding morse code and I wasn't sure it would be fast enough.

There are examples for pretty much any usb peripheral you can think of here: https://github.com/hathach/tinyusb/tree/master/examples/devi...


Intro for those who aren't familiar:

TinyUSB allows a programmable chip (e.g. ESP32, SAM, STM32) to read USB flash drives, or behave as a keyboard and mouse.

A similar library for Arduino is V-USB.

https://hackaday.com/tag/tinyusb/

Question for the experts: is it possible to do USB pass-through monitoring?

Specifically, I have an Apple Magic Keyboard connected to the Dell work PC. I'd like to capture the F7-F12 keys, and use them to control the music on my iPod. Currently I use an AutoHotKey script to send serial commands from the PC, but having 2 FTDI cables plugged in sometimes causes issues.

Yes, I'm effectively suggesting a keylogger, but without trying to record the keystrokes, just use them to trigger another UART. It could also be really nice to remap the Command key to Ctrl (again, I work around this with AutoHotKey, but it's imperfect).


> is it possible to do USB pass-through monitoring?

I fear it would need something a little bit more complex than just an Arduino on the hardware side. For some options, you could take a look at some recent versions of Facedancer [0] and their HW requirements.

[0]: https://github.com/greatscottgadgets/Facedancer


> but having 2 FTDI cables plugged in sometimes causes issues

As long as you have genuine FTDI cables or at least ones that expose an unique serial number, you can use udev rules to have clean reproducible device names: https://askubuntu.com/a/165262/777894


I swear there was a HN post about someone who made a KVM alternative on this principal (pass KB/M through a microcontroller or something and have it act as downstream KB/M to multiple devices) but for the life of me I can't find it. That or I dreamed the whole thing up.


Are you thinking of the display-switch[0] script? Achieves K/V/M-switching with only a cheap USB-switch for hardware K/M-switching, and then this script detects such peripheral switching and emits DDC-commands for monitors to switch accordingly.

I saw it posted here on HN[1], and have been using it since then with great success.

[0] https://github.com/haimgel/display-switch [1] https://news.ycombinator.com/item?id=29608967


https://pikvm.org may be? Not exactly microcontroller though.


Also related is V-USB from obev for AVR devices which don't have built-in USB transceivers. Impressively, they bit bang low speed USB (1.1) using two regular GPIO pins. [1]

[1] https://www.obdev.at/products/vusb/index.html


> Impressively, they bit bang low speed USB (1.1)

You're not kidding, that is very impressive. I always find it fascinating what some people manage to achieve with bit-banging.

This is one I remember being quite impressed with back in the day:

https://hackaday.com/2011/05/10/bit-banging-vga-from-an-sd-c...


There's also the library for the 'Digispark' project (ATTINY85-based). This seems derived from AVR USB code and can be used via the Arduino IDE:

http://digistump.com/products/1

https://github.com/digistump/DigisparkArduinoIntegration/tre...

https://github.com/linker3000/Digiprank


It will not work when plugged into an USB3 port. It is marginal for USB ports following older standards and may occasionally not work. Putting an old USB hub between the computer and the AVR device can help with the connection. It's a neat hack though: https://www.obdev.at/articles/implementing-usb-1.1-in-firmwa...

The utility of it diminished with the availability of AVR devices with integrated USB peripherals. There's LUFA to help with their use: http://www.fourwalledcubicle.com/LUFA.php


One of the more annoying aspects of vendor supplied USB stacks is they are frequently only designed to work in a mainloop and have a monolithic interrupt handler that runs too much code to work well in an RTOS.


85 kLoC of C and 95 kLoC of headers. Is it hard to implement necessary part of USB from the scratch? Like if I only need USB Serial.


I'm using arduino-pico [1], which has support for the Adafruit fork [2] of this project. I haven't used anything other than the serial port and MIDI out, but it's nice so far.

[1] https://github.com/earlephilhower/arduino-pico [2] https://github.com/adafruit/Adafruit_TinyUSB_Arduino



Also: https://www.obdev.at/products/vusb/index.html which works on AVR devices without hardware USB support.


Anyone used it for MIDI? I'm mainly interested in drum triggering, so it'd have to be really low latency and reliable while the uC is also reading values from piezo sensors during fast rolls.

ps. I'm aware of megadrum (.info) and Mios (ucapps.de), just wanted to see if I could make something similar, albeit much smaller, by myself.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: