October 30, 2023
Let's learn USB! -- a manifesto
I want to learn the low level details of USB programming.
This is the kind of thing few people stick their noses into.
I want to start with a datasheet and write code that will
implement a working USB device.
Here are some basic ideas up front:
- I will use a Fedora linux system for development
- I will use the arm-eabi-none C compiler and toolchain
- I will work with the Pi Pico (RP2040 chip)
- I will work with the STM32F103 "blue pill" board
- I will work only on a full speed (12 Mbps) device.
- I will work only on device code (not host code).
- I will use the C language exclusively
- I will program "bare metal" with no support libraries
I am purposely excluding many interesting topics to keep this
relatively simple. There is still plenty to tackle.
Consider these subdivisions of labor:
- Understanding the USB protocol
- Understanding one or more specific hardware devices
- Cooperating with the system on "the other side"
Like network programming, USB programming is done within the context
of well defined standards and protocols. This will lead to a
portable USB stack. Working with two different devices will
help guide the project towards a clean division between the
portable stack and hardware specific code.
This will end up being a USB support library for a microcontroller.
That library will need to present itself as some kind of API to
code that will use the library. This API will depend somewhat on
just what sort of device is being implemented.
The first device I intend to aim for is a serial over USB device
that could act as a console. On unix, the device would appear
as /dev/ttyUSB0 or /dev/ttyACM0 or such and a terminal emulator
like "picocom" should be able to talk to it.
On the controller side, we would expect to have calls like:
usb_serial_open ()
usb_serial_putc ()
usb_serial_getc ()
Feedback? Questions?
Drop me a line!
Tom's Computer Info / tom@mmto.org