Implement application specific behavior of a Custom Class USB Device.
More...
|
| User API |
| User API reference of the Custom Device Class.
|
|
| Configuration |
| Configuration of the USB Device Custom Class.
|
|
Implement application specific behavior of a Custom Class USB Device.
The Custom Class in the USB Component may be used to implement any type of USB Device class.
Refer to:
The USB Component allows multiple instances of the Custom class. This feature may be used to create USB Composite Devices. Each Custom Class instance has separate files and interface functions:
- A configuration file USBD_Config_CustomClass_n.h.
- An application-specific user source code file which may be implemented with the USBD_User_CustomClass_n.c.
- Functions that start with the prefix USBD_CustomClassn_ are available for each instance of a Custom Class.
This documentation uses n as a placeholder for the instance number 0 - 3. Most applications require only one instance of a Custom Class. For the first Custom Class instance the instance number is 0:
- USBD_Config_CustomClass_0.h
- USBD_User_CustomClass_0.c
- The function prefix is USBD_CustomClass0_
Software Structure
The handling of the Custom Class endpoint events is implemented in an USBD_CustomClassn_Endpointx_Event for every endpoint. Each endpoint (or pair of IN/OUT endpoints with the same endpoint number) uses an own thread in order to allow a parallel functionality of every interface.
Setup Packets on Control Endpoint 0
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.
Implementation
To create an USB Device with a Custom Class:
User Code Templates
Two files are available to implement the application-specific behavior:
- USBD_User_CustomClass.c is used for custom handling of class requests to instances of a custom class.
- USBD_User_Device_n.c is used for custom handling of any request coming to the USB Device. Its primary use is to allow for custom handling of standard and vendor requests, for example overriding the serial number string. It allows to intercept all incoming requests and to override the default USB Component handling.
Both user code templates contain example code that can be used to demonstrate the features of the templates. Uncomment this code to see how it works on your target hardware.
USBD_User_CustomClass.c
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "Driver_USBD.h"
void USBD_CustomClass%Instance%_Initialize (void) {
}
void USBD_CustomClass%Instance%_Uninitialize (void) {
}
void USBD_CustomClass%Instance%_Reset (void) {
}
void USBD_CustomClass%Instance%_EndpointStart (uint8_t ep_addr) {
(void)ep_addr;
}
void USBD_CustomClass%Instance%_EndpointStop (uint8_t ep_addr) {
(void)ep_addr;
}
(void)buf;
(void)len;
case USB_REQUEST_TO_DEVICE:
break;
case USB_REQUEST_TO_INTERFACE:
break;
case USB_REQUEST_TO_ENDPOINT:
break;
default:
break;
}
}
void USBD_CustomClass%Instance%_Endpoint0_SetupPacketProcessed (
const USB_SETUP_PACKET *setup_packet) {
case USB_REQUEST_TO_DEVICE:
break;
case USB_REQUEST_TO_INTERFACE:
break;
case USB_REQUEST_TO_ENDPOINT:
break;
default:
break;
}
}
usbdRequestStatus USBD_CustomClass%Instance%_Endpoint0_OutDataReceived (uint32_t len) {
(void)len;
}
(void)len;
}
void USBD_CustomClass%Instance%_Endpoint1_Event (uint32_t event) {
if (event & ARM_USBD_EVENT_OUT) {
}
if (event & ARM_USBD_EVENT_IN) {
}
}
void USBD_CustomClass%Instance%_Endpoint2_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint3_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint4_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint5_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint6_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint7_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint8_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint9_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint10_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint11_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint12_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint13_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint14_Event (uint32_t event) {
(void)event;
}
void USBD_CustomClass%Instance%_Endpoint15_Event (uint32_t event) {
(void)event;
}
USBD_User_Device_n.c
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
void USBD_Device%Instance%_Initialize (void) {
}
void USBD_Device%Instance%_Uninitialize (void) {
}
void USBD_Device%Instance%_VbusChanged (bool level) {
(void)level;
}
void USBD_Device%Instance%_Reset (void) {
}
void USBD_Device%Instance%_HighSpeedActivated (void) {
}
void USBD_Device%Instance%_Suspended (void) {
}
void USBD_Device%Instance%_Resumed (void) {
}
void USBD_Device%Instance%_ConfigurationChanged (uint8_t val) {
(void)val;
}
void USBD_Device%Instance%_EnableRemoteWakeup (void) {
}
void USBD_Device%Instance%_DisableRemoteWakeup (void) {
}
(void)buf;
(void)len;
case USB_REQUEST_STANDARD:
break;
case USB_REQUEST_CLASS:
break;
case USB_REQUEST_VENDOR:
break;
case USB_REQUEST_RESERVED:
break;
default:
break;
}
}
void USBD_Device%Instance%_Endpoint0_SetupPacketProcessed (
const USB_SETUP_PACKET *setup_packet) {
case USB_REQUEST_STANDARD:
break;
case USB_REQUEST_CLASS:
break;
case USB_REQUEST_VENDOR:
break;
case USB_REQUEST_RESERVED:
break;
default:
break;
}
}
(void)len;
}
(void)len;
}