Académique Documents
Professionnel Documents
Culture Documents
NuMicro@nuvoton.com
Agenda
Features
USB Block Diagram
Function Description
Buffer Control
Register Map
USB Driver Framework
Control Flow of Run a USB Device
HID Sample Code
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 )
Features (2/2)
Support 4 transfer types
Control
Bulk
Interrupt
Isochronous
Floating detect
USB_DP
RXDP
USB_DM
RXDM
S0
FLDET
DEBOUNCE
SIE
DPLL
NVIC
Wakeup
INT
SFR
ENDPOINT
CONTROL
BUFFER
CONTROL
S1
SRAM
512
BYTE
Transceiver
APB WRAPPER
APB Bus
BUS notifies users of some bus events, like USB reset, suspend,
time-out, and resume.
10
Buffer Control
USB SRAM Start Address USB_SRAM = USB_BASE + 0x0100h
BUFSEG2 = 0x88
BUFSEG3 = 0x100
512
Bytes
EP3 SA =USB_BASE + 0x200h
11
Register Map
Register
Offset
General Setting
R/W
Description
Reset Value
USB_BA = 0x4006_0000
USB_INTEN
USB_BA+0x000
R/W
0x0000_0000
USB_INTSTS
USB_BA+0x004
R/W
0x0000_0000
USB_FADDR
USB_BA+0x008
R/W
0x0000_0000
USB_EPSTS
USB_BA+0x00C
0x0000_00x0
USB_ATTR
USB_BA+0x010
R/W
0x0000_0040
USB_FLDET
USB_BA+0x014
0x0000_0000
USB_BUFSEG
USB_BA+0x018
R/W
0x0000_0000
USB_BUFSEG0
USB_BA+0x020
R/W
0x0000_0000
USB_MXPLD0
USB_BA+0x024
R/W
0x0000_0000
USB_CFG0
USB_BA+0x028
R/W
0x0000_0000
USB_CFGP0
USB_BA+0x02C
R/W
0x0000_0000
Endpoint Setting
12
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
14
15
IN
OUT
Token
1.
2.
3.
DATA0/
DATA1
Data
16
17
USB
Driver
USB
Descriptors
Endpoint
Configuration
Class Function
Handlers
USB
Initiator
Control Pipe
Handlers
USB Event
Handlers
USB
Controller
(un)Plug
Event
Wakeup
Event
Bus
Events
USB
Events
Endpoint
Events
18
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
20
Open USB
Class Driver
USB Plug-in
Detect
Dispatch USB
Events
Call USB
Function
Handlers
21
/* LOCKREG */
LOCKREG();
/* Update system core clock */
SystemCoreClockUpdate();
/* Execute HID process */
HID_MainProcess();
int32_t i32Ret = 0;
1. Open USB Driver
E_DRVUSB_STATE eUsbState;
i32Ret = DrvUSB_Open((void *)DrvUSB_DispatchEvent);
if(i32Ret != 0)
return i32Ret;
while(1)
{
/* Disable USB-related interrupts. */
_DRVUSB_ENABLE_MISC_INT(0);
/* Enable float-detection interrupt. */
_DRVUSB_ENABLE_FLDET_INT();
/* Start HID and install the callback functions to handle in/out report */
HID_Init();
/* Enable USB-related interrupts. */
_DRVUSB_ENABLE_MISC_INT(INTEN_WAKEUP | INTEN_WAKEUPEN
| INTEN_FLDET | INTEN_USB | INTEN_BUS);
/* Enter power down to wait USB attached. */
PowerDown();
23
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. */
_DRVUSB_ENABLE_MISC_INT(0);
}
24
NuvotonPlatform_Keil
Sample
USB
Smpl_HID
Smpl_HID.uvproj
25
26
NuvotonPlatform_Keil
Sample
NUC1xx-LB_002
Smpl_HID_IO
Smpl_HID_IO.uvproj
Software GUI
HID AP.exe
27
28
Q&A
Thank You
29