USB Component
Version 6.17.0
MDK Middleware for USB Device and Host Communication
|
Initialize and manage the USB Device Core statically and at run-time. More...
Content | |
User API | |
User API reference of the USB Device Core. | |
Configuration | |
Configuration of the USB Device Core. | |
Initialize and manage the USB Device Core statically and at run-time.
The Core of the USB Device has standard functions that are used to initialize and start the USB Device. These functions must be used before any class specific functions are called:
These two functions are accompanied USBD_Disconnect and USBD_Uninitialize. Use them to properly disconnect and uninitialize the device from the USB bus.
The USB Device Core is statically configured using the USBD_Config_n.c file. However, for mass-production it is often required to be able to configure some USB Device settings at run-time (for example the serial number which needs to be unique for every single device). To achieve this, the following device configuration functions are part of the USBD_User_Device_n.c user code template. They enable user specific USB Control Endpoint 0 request handling. This allows the user to intercept all Control Endpoint 0 requests and handle them overriding the default USB Library handling:
Setup packets sent to Control Endpoint 0 are received by the USB Device Core. The USB Device Core will call the USBD_Devicen_Endpoint0_SetupPacketReceived function and pass the setup packet to it. Depending on the return code of USBD_Devicen_Endpoint0_SetupPacketReceived, the USB Device Core either passes the processing to the Custom Class function if custom class is used and if message is addressed to a custom class by calling USBD_CustomClassn_Endpoint0_SetupPacketReceived function or continues to process the received setup packet itself. Depending on the return code of USBD_CustomClassn_Endpoint0_SetupPacketReceived, processing of the setup packet is either done or continues to be processed by USB Device Core.
USB Device Core will call USBD_Devicen_Endpoint0_SetupPacketProcessed and depending on return code it will call USBD_CustomClassn_Endpoint0_SetupPacketProcessed to inform the application that setup packet has been processed by USB Device Core.
If custom handling of request was used and request contains data stage, USB Device Core will call USBD_Devicen_Endpoint0_OutDataReceived and depending on return code it will call USBD_CustomClassn_Endpoint0_OutDataReceived after data expected by request was received, it will call USBD_Devicen_Endpoint0_InDataSent and depending on return code it will call USBD_CustomClassn_Endpoint0_InDataSent after data expected by request was sent.
User Code Templates
There are two user code templates available that help to configure the USB Device at run-time:
User Code Template USBD_User_Device_n.c
The following source code can be used to implement the application specific behavior of a USB Device.
User Code Template USBD_User_Device_SerNum_n.c
The following source code can be used to set an application specific serial number for the USB Device.