AN1886 - APPLICATION NOTE
10/54
Table 7.
shows that μPSD32xxA devices support three types of Endpoint: Control Endpoint0 for IN and
OUT packets; and alternative interrupt Endpoint1 and Endpoint2 for IN packets only (a user can send data
only to host, which means to the PC in the most of cases).
Table 7. Supported Endpoints
The appropriate endpoint is selected by bit-6 (
EP12SEL
) in the
UCON1
register before the USB Endpoint
cache is filled by writing data to
UDT1
register. The appropriate endpoint must be also enabled in
UCON2
register (bits
EP1E
and
EP2E
).
Data Structures and Data-flow
In between the application and the top-level firmware routines, data structures are broken up into HID re-
ports and USB packets.
Table 8.
illustrates which application and firmware routines conceptually commu-
nicate with each other using the same structures.
Table 8. USB Demonstration Program Data Structures
USB Bus Level Interface
Low speed HID devices, such as the μPSD32xxA, can pass a maximum of eight bytes per bus transaction.
The USB host controller driver, on the Windows side, and the firmware, on the μPSD32xxA side, must
break up HID reports, when necessary, into 8-byte USB packets.
Since the input report for the example was defined to be eight bytes in length, there are no complications
in passing the LCD mirror data to the application. Mirror data is passed in the
OnTransmitEP1
routine, in
Firmware\main.c
. Whenever one packet is successfully transmitted on
EP1 IN
,
OnTransmitEP1
prepares
the next packet with the next segment of the LCD mirror buffer.
Since the Output and Feature reports are used to pass command data, they are larger than eight bytes.
The firmware must deal with the complication of assembling and disassembling reports into 8-byte setup
packets to or from the control endpoint. The firmware
OnReportSegmentReceived
routine handles the
process of accumulating the multiple segments of an Output report. When the complete report has been
assembled in the buffer, the
OnReportReceived
routine is called to handle the MCU_CMD command
Function
Maximal packet
size
Maximal traffic
Supported
directions
Registers
Endpoint 0
Control
8 Bytes
Any time
Both IN and OUT
UCON0,UDR0,
UDT0,USTA
Endpoint 1
Interrupt endpoint
8 Bytes
1 per 10-255ms
IN only,
device
→
host (PC)
UCON1,
UDT1,UCON2
Endpoint 2
Interrupt endpoint
8 Bytes
1 per 10-255ms
IN only,
device
→
host (PC)
UCON1,
UDT1,UCON2
Host Routine(s)
Data Structure(s)
Firmware Routine(s)
High level button handlers such as
OnReadFlash, OnWriteFlash, OnErase, etc.
MCU_CMD
OnReportReceived,
PrepareTransmitSegment
HidD_GetFeature
Feature Report
PrepareTransmitSegment
WriteFile
Output Report
OnReportReceived
ReadFile
Input Report
OnTransmitEP1
USB Host Controller
Max. 8 bytes length control and
interrupt endpoint packets.
OnTransmitEP1,
PrepareTransmitSegment,
OnReportSegmentReceived