BeagleBoard/GSoC/2022 Proposal/PRU-based USB stack

=Proposal Template= About Student: Seak Jian De Mentors: Jason Kridner, giuliomoro Code: [N/A] Wiki: https://elinux.org/index.php?title=BeagleBoard/GSoC/2022_Proposal/PRU-based_USB_stack GSoC: PRU-based USB stack

=Status= This project is currently just a proposal.

=Proposal= Completed all the requirements listed on the ideas page. the code for the cross-compilation task can be found here submitted through the pull request #158.

About you
IRC: Jian De Github: https://github.com/Fred-JD School: Universiti Teknologi Malaysia Course: 3rd Year Electronics Engineering Country: Malaysia Language: English, Mandarin, Malay Typical work hours: 4PM - 11PM UTC +8 Previous GSoC participation: First year apply gsoc.

Project Name
PRU-based USB stack

Description
Why develop PRU-Based USB stack? As we know, Linux wasn’t designed as a real-time operating system that can guarantee a rate of data transfer with a peripheral. With multi-tasking, multiple programs run at the same time, and the OS grants a portion of the valuable time to each thread. Different threads can have different priorities. RPU is a solution of this which TDA4VM device can be beneficial of minimize the latency for USB peripherals.

Features

 * Implement USB Host Controller for PRU
 * Implement USB Host Core for PRU
 * Support USB class driver for (MIDI, HID, AUDIO)
 * Providing detailed Documentation for USB Host API

USB Concept
Transfer Types
 * Control Transfers
 * Bulk Transfers
 * Interrupt Transfers
 * Isochronous Transfers

USB Protocol Descriptors
 * Each device contains Descriptors which contain information about the device.

Interfaces
 * USB devices publish their endpoints as part of an Interface.

Endpoints
 * USB pipes are opened to Endpoints. Devices publish Endpoint descriptors to enable clients to query what endpoint are available and what characteristics they have. Endpoint descriptors contain information about the I/O direction (IN which is from the device to the host or OUT which is from the host to the device), the transfer type (Control, Bulk, Interrupt, or Isochronous) and the maximum supported packet size.

Pipes
 * Communication between the host and a USB device is performed through Pipes.

PRU Access USB Peripheral
PRU Memory Access In order to read/write to an memory address external to the PRU subsystem, the OCP master port need to be enabled in the PRU‐ICSS CFG register space, SYSCFG[STANDBY_INIT].

USB Host Controller
The USB Host Controller Driver is the layer between the USB Host Controller Hardware and the USB Host Core. This layer handles hardware specific interfaces.

Enumeration
The host enumerate the device by issuing control transfers containing standard USB requests to the device. All USB devices must support control transfers, standard requests, and endpoint zero.

Descriptors
USB descriptors are the data structures that enable the host to learn about a device. Each descriptor contains information about the device as a whole or an element of the device. Types of descriptor:-
 * Device Descriptors
 * Configuration Descriptors
 * Interface Descriptors
 * Endpoint Descriptors
 * String Descriptors

USB Host Core
The USB Host Core is a hardware independent layer and contains the functions to manage USB peripherals and the USB bus. This layer is an interface between the USB Host Controller Driver and the USB Host Class Driver.

Elements of a Control Transfer

 * Setup Stage
 * Consists of a Setup Transaction. Device must return ACK for every Setup Transaction received without a error
 * Data Stage
 * IN or OUT transaction
 * Status Stage
 * The status stage completes the transfers.

Error Handling

 * Timeout conditions after a host-transmitted token or packet. These errors occur when the addressed endpoint is unresponsive or when the structure of the transmission is so badly damaged that the targeted endpoint does not recognize it.
 * Data errors resulting in missing or invalid transmissions:
 * The Host Controller is unable to completely send or receive a packet for host specific reasons, for example, a transmission extending beyond EOF or a lack of resources available to the Host Controller.
 * An invalid CRC field on a received data packet.
 * Protocol errors:
 * An invalid handshake PID, such as a malformed or inappropriate handshake
 * A false EOP
 * A bit stuffing error

Standard Requests

 * Get Status
 * Clear Feature
 * Set Feature
 * Set Address
 * Get Descriptor
 * Set Descriptor
 * Get Configuration
 * Set Configuration
 * Get Interface
 * Set Interface
 * Synch Frame
 * Set SEL
 * Set Isochronous Delay

USB Host Device Class
USB defines class code information that is used to identify a device’s functionality and to nominally load a device driver based on that functionality.

Audio (MIDI)
Device Class Definition for MIDI

HID
Device Class Definition for HID

Experience and approach
In 5-15 sentences, convince us you will be able to successfully complete your project in the timeline you have described.


 * In my first year of University I have passed the 3 month junior training program by ROBOCON UTM which include basic programming, basic electronics and basic Mechanisms.
 * I have built a line following robot with dsPIC30f4011 microcontroller. Solder and design my own hardware with the PIC microcontroller. Understand about GPIO, PWM, UART, ADC/DAC. I have experience in C programming and know how circuit connection with breadboard. photo.
 * I have build a custom PCB to control robotic pneumatic valve with Altium designer. photo
 * I have build a flutter mobile app which read and display sensor value from Bluetooth module with Maker Uno (similar with Arduino Uno). Then store the value on AWS with MQTT protocol.\
 * I have build Footfall Counter with openCV github
 * In order to successfully to complete the projects, I will start it early which start to work with the technology before official code period so I have extra time for debug and testing.

Contingency
What will you do if you get stuck on your project and your mentor isn’t around?
 * I will refer PRU documents [PRU-ICSS / PRU_ICSSG Getting Starting Guide https://www.ti.com/lit/sprace9] [PRU Optimizing C/C++ Compiler User's Guide http://www.ti.com/lit/pdf/SPRUHV7].
 * I will also refer PRU Cookbook.
 * USB host controller refer Driver_USB.h Driver_USBH.h.
 * For USB concept like Enumeration, Control Transfer, Standard Request, Interface will refer USB Complete: The Developer's Guide
 * For USB class definition will refer https://www.usb.org/
 * USB concept here

Benefit
"Also, the pay-off for doing this for Bela users is the ability to have low-latency audio rendering." ~ jkridner

Misc
Completed all the requirements listed on the ideas page. the code for the cross-compilation task can be found here submitted through the pull request #158.

Suggestions
Is there anything else we should have asked you?