Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
NuMicro@nuvoton.com
1
Agenda
Features
USB Block Diagram
Function Description
Buffer Control
Register Map
USB Driver Framework
Control Flow of Run a USB Device
HID Sample Code
2
Features (1/2)
One set of USB 2.0 full-speed device controller and
transceiver.
Compliant with USB 2.0 Full-Speed device specification.
Provide 1 interrupt vector with 4 different interrupt
events.
WAKEUP ( wake up the system clock)
FLDET ( Floating detect interrupt )
USB ( USB events, like IN ACK, OUT ACK )
BUS ( Bus events, like reset, suspend, resume )
3
Features (2/2)
Support 4 transfer types
Control
Bulk
Interrupt
Isochronous
Provide 6 endpoints for configurable
Control/Bulk/Interrupt/Isochronous transfer types
Include 512 bytes internal SRAM as data buffer.
4
USB Block Diagram
DPLL use the 48MHz
CLKGEN NVIC
Floating detect
FLDET Wakeup
DEBOUNCE DPLL INT
SFR
USB_DP RXDP
ENDPOINT
USB_DM RXDM CONTROL SRAM
SIE 512
S0 BUFFER
BYTE
CONTROL
S1
Transceiver
APB WRAPPER
APB Bus
5
Function Description (1/5)
SIE (Serial Interface Engine)
The front-end of the device controller and handle most of the USB
packet protocol.
The function could include:
Packet recognition, transaction sequence
SOP, EOP, RESET, RESUME signal detection / generation.
Clock / Data separation
NRZI Data encoding / decoding and bit-stuffing
CRC & Packet ID generation / checking
Serial-Parallel / Parallel-Serial conversion.
6
Function Description (2/5)
Endpoint Control
There are 6 endpoint
All the operations including Control, Bulk, Interrupt and
Isochronous transfer are implemented in it.
DPLL (Digital Phase Lock Loop)
Use 48MHz to lock the input data from RXDP and RXDM.
The bit rate of USB is 12MHz. It is converted from DPLL
7
Function Description (3/5)
Floating De-bounce
A USB device may be plug-in or unplug from USB Host.
Provide hardware de-bounce for USB floating detect interrupt to
avoid bounce problems. (10ms)
8
Function Description (4/5)
Interrupt
Provide 1 interrupt vector with 4 interrupt events (WAKEUP,
FLDET, USB and BUS)
WAKEUP is only present after stop wakeup.
After the chip enters power down mode, any change on D+, D- and
floating detect pin can wake up this chip.
FLDET is for USB plug-in or unplug.
USB is to notify user to any USB event on the bus.
Acknowledge what kind of request is to which endpoint and take
necessary response.
BUS notifies users of some bus events, like USB reset, suspend,
time-out, and resume.
9
Function Description (5/5)
Power Saving
USB turns off PHY automatically to save power while this chip
enters power down mode.
Furthermore, user can write 0 to register ATTR[4] to turn off
PHY under special conditions like suspend to save power.
10
Buffer Control
USB SRAM Start Address USB_SRAM = USB_BASE + 0x0100h
11
Register Map General Setting
Register Offset R/W Description Reset Value
USB_BA = 0x4006_0000
USB_ATTR USB_BA+0x010 R/W USB Bus Status and Attribution Register 0x0000_0040
USB_CFGP0 USB_BA+0x02C R/W Endpoint 0 Set Stall and Clear In/out ready Control Register 0x0000_0000
12
Endpoint Setting
Register Function (1/4)
General Setting:
USB_INTEN
Enable / Disable USB related interrupt.
USB_INTSTS
Any USB event will cause an interrupt, and user just needs to
check the related event flags.
USB_FADDR
A 7-bit value uses as the address of a device on the bus.
USB_EPSTS
User can check related bits to know what kind of USB event was
occurred.
13
Register Function (2/4)
General Setting:
USB_ATTR (Bus Status & Attribution Register)
Acknowledge BUS events.
Pull-up register on USB_DP enable.
Enable and disable PHY transceiver.
USB_FLDET (Floating Detected Register)
Acknowledge USB plug-in / unplug by reading this register.
USB_BUFSEG (Setup Token Segmentation Register)
User needs to set the effective starting address of USB buffer for
setup token only.
14
Register Function (3/4)
Endpoint Setting:
USB_BUFSEGx, x=0~5 (Endpoint x Buffer Segmentation
Register)
User needs to set the effective starting address of USB buffer for
each endpoint (0~5) buffer.
MXPLDx, x=0~5 (Endpoint x Maximal Payload Register)
Once MXPLD is written, the data packets will be
transmitted/received immediately after IN/OUT token arrived.
15
USB_BUFSEGx & USB_MXPLDx Register
Idle
IN OUT
Token
USB host has requested data from device USB host wants to transmit data to device
controller controller
DATA0/ DATA0/
Data
DATA1 DATA1
1. Prepare related data into the specified Hardware will buffer theseIdle
1. data to
endpoint buffer. specified endpoint buffer.
2. The start address of endpoint buffer is 2. The start address of endpoint buffer is
Host Device
defined in USB_BUFSEGx. defined in USB_BUFSEGx.
3. Need to write the actual data length in 3. Hardware will record the data length in
USB_MXPLDx. USB_MXPLDx.
16
Register Function (4/4)
Endpoint Setting:
USB_CFGx, x=0~5 (Endpoint x‟ s Configuration Register)
Each endpoint needs to be configured properly in advance for its
attribution (IN, OUT or ISO state) and endpoint number.
USB_CFGPx, x=0~5 (Endpoint x‟ s Set Stall and Clear In/Out
Ready Control Register)
User can force device to respond STALL.
User can write „1‟ to clear the IN / OUT token had ready to
transmit / receive the data.
17
USB Driver Framework (1/3)
USB Class (HID / UAC / UDC ...)
USER/USB
Class USB Endpoint Class Function
Descriptors Configuration Handlers
18
USB Driver Framework (2/3)
USB Controller
The USB controller can issue SETUP or IN/OUT event when
getting relative tokens.
USB Driver
Initialize the USB control according to the USB endpoint
Process the standard requests of control pipe of USB
Call the relative USB event handlers.
19
USB Driver Framework (3/3)
USB Class
In this layer, user should define the all descriptors, such as
device descriptor, configuration descriptors, interface descriptors,
endpoint descriptors and class descriptors and etc.
An endpoint configuration to define the USB buffer usage of
each endpoint is also required.
The relative device/class function handler also needs to be
implemented here.
20
Control Flow of Run a USB Device
Open USB
Driver
Dispatch USB
Events
Open USB
Class Driver
Call USB
Function
USB Plug-in
Handlers
Detect
21
HID Sample Code (1/3)
/********************************** Main.c *****************************************/
/* UNLOCKREG */
UNLOCKREG();
/* Enable PLL */
DrvSYS_SetPLLMode(0);
Delay(1000);
23
HID Sample Code (3/3)
/* Poll and handle USB events. */ 3. USB Plug-in Detect
while(1)
{ eUsbState = DrvUSB_GetUsbState();
if (eUsbState == eDRVUSB_DETACHED)
{
DBG_PRINTF(“USB Detached!\n”);
break;
}
if (eUsbState == eDRVUSB_SUSPENDED)
{ /* Enter suspend here */
PowerDown();
}
else
{ /* Set HID IN report for interrupt IN transfer */
HID_SetInReport();
}
}
/* Disable USB-related interrupts. */
4. Dispatch USB events
_DRVUSB_ENABLE_MISC_INT(0); 5. Call USB Function Handler
}
24
Run “Smpl_HID” Code
Customer_CD
NUC100SeriesBSP
NuvotonPlatform_Keil
Sample
USB
Smpl_HID Smpl_HID.uvproj
25
Run “Smpl_HID” Code
Customer_CD
NUC100SeriesBSP
NuvotonPlatform_Keil
Sample
NUC1xx-LB_002
Smpl_HID_IO.uvproj
Smpl_HID_IO
27
Run “HID AP.exe” Result
28
Q&A
Thank You
29