Writing a USB stack The USB protocol stack can be laid out in 2 or three levels Hardware management (which may include low-level protocol) Optionally, common protocol procedures The actual device code (usb-serial, network, storage) Then, higher levels (UDP/IP, FATFS, whatever) will be generic The USB device driver will offer a non-usb API Most USB implementations are state machines with callbacks This can happen based on interrupts Or you can just poll the status bits