ARM-software / CMSIS-Driver

Repository of microcontroller peripheral driver implementing the CMSIS-Driver API specification
https://arm-software.github.io/CMSIS-Driver/
Apache License 2.0
167 stars 61 forks source link

Missing Readme and example usage for USB Drivers #33

Open zwvk opened 4 months ago

zwvk commented 4 months ago

I noticed that a little less than a month ago @MiloradCvjetkovic supplied a USB Host driver package. Specifically the EHCI driver.

I would appreciate some details on how to use this. I would like to determine if it would be a good fit for the SAMV71Q21B processor, but I don't see any examples to understand how this code is used, and how I might possibly target it to my processor.

I see there is an Interface layer, where I could supply customized code to initialize my hardware, but I only see such things as initialize, un-initialize, and power control. It isn't clear to me how the Transaction Translator is intended to interact with the USB hardware. I presume it is through the TT_Regs, and the microcontroller is supposed to glue these registers to the actual hardware through customized code in the microcontroller interrupts.

It seems this glue code is supposed to be laid out in the manner loosely described by the header "Driver_USBH.h", which appears to be a file in the ARM-software/CMSIS directory. Does it matter which CMSIS I use? (ARM-software/CMSIS_5 or ARM-software/CMSIS_6, etc).

Is there a working example of this driver in use on any processor/board that I can review?

Finally, the TT project also calls for the header "cmsis_os2.h" which presumably means the TT relies upon the RTOS in some manner. It would be nice to have a high level understanding of the expected interactions with the RTOS, threads, mutexes, timers, etc.

Thanks!

MiloradCvjetkovic commented 4 months ago

Hi @zwvk ,

let me start by saying that EHCI driver is unfortunately not a good fit for the MCU (SAMV71Q21B) that you are using.

The SAMV71Q21B has proprietary USB Host/Device controller which is not EHCI compliant.

The EHCI stands for Enhanced Host Controller Interface and is a standard specifying the functionality and you can find the document here: https://www.intel.com/content/www/us/en/products/docs/io/universal-serial-bus/ehci-specification-for-usb.html

Same thing applies for the OHCI which stands for Open Host Controller Interface and is also standardized.

So, EHCI driver will not be fit for your purpose as registers and functionality are different.

What you need is a custom driver for your particular USB Host controller.

Microchip seems to have some USB support in Atmel Software Framework (ASF) and you would probably use that to implement a CMSIS USB Host driver if that is what you want.

For your further questions here are short answer since that driver is not a good fit for your purpose:

Since EHCI standard already defines most of the USB Host functionality only parts that depend on actual hardware are related to Initialization, Uninitialization and Power Control and those are provided via the USBH_EHCI_HW.c which is also provided as a template.

The "TT" here denotes a deviation (extension) from the EHCI standard which is used by some embedded devices which adds support for also full- and low-speed devices, which are otherwise handled by the additional accompanying OHCI controller on the same bus.

What is described in the "Driver_USBH.h" is the API for CMSIS USB Host Driver, meaning control block containing functions used for interacting with USB Host Controller.

It is always best to use latest CMSIS since it might include any bug fixes or new features.

The hardware part is not specified in the "Driver_USBH.h", or better to say, previous hardware specific API has been deprecated (so called HCI API (ARM_DRIVER_USBH_HCI)).

A working example is not yet publicly available but should become available soon.

The only requirement of the EHCI driver from the RTOS is at the moment for timeout delays (osDelay function), so there are no other requirements for the RTOS functionality by the driver itself.