284
AMD Alchemy Au1550 Security Network Processor Data Book
USB Device Controller
30283D
9.2.6
Programming Examples for USB Device
9.2.6.1
Initialization
1)
Configure 48 MHz USB device clock from AUX PLL.
sys_auxpll = 16;
// set the AUX PLL to 192 MHz (12 MHz x 16)
sys_freqctrl0 |= 0x3;
// enable FREQ0 and select
AUX PLL as the FREQ0 source
sys_clksrc |= 0xB;
// divide FREQ0 by 4 to obtain
48 MHz, and select FREQ0 as the USB clock
2)
Enable USB Device Controller.
usbd_enable = 0x02;
// enable USBD clocks
wait at least 1us;
usbd_enable = 0x03;
// remove reset from USBD Controller
wait at least 1us;
3)
Write 25-byte configuration data to the Configuration Register.
for( i = 0; i < 25; ++i )
{
usbd_config = (unsigned int) config_data_bytes[i];
}
wait at least 1us;
4)
Set up Endpoint Control Registers (example).
usbd_ep0cs = 64 << 1;
// set endpoint 0 MAXPACKET
usbd_ep1cs = 8 << 1;
// set endpoint 1 MAXPACKET
usbd_ep2cs = 8 << 1;
// set endpoint 2 MAXPACKET
usbd_ep3cs = 8 << 1;
// set endpoint 3 MAXPACKET
usbd_ep4cs = 8 << 1;
// set endpoint 4 MAXPACKET
5)
Clear FIFO Status Registers.
//
clear Overflow Flag, Underflow Flag, Flush FIFO
usbd_ep0rdstat = 0x70;
usbd_ep0wrstat = 0x70;
usbd_ep1wrstat = 0x70;
usbd_ep2wrstat = 0x70;
usbd_ep3rdstat = 0x70;
usbd_ep4rdstat = 0x70;
6)
Configure DMA channels.
// assign a DMA channel for endpoint 0 receive and build
multiple buffer descriptors
// assign a DMA channel for endpoint 0 transmit and build
multiple buffer descriptors
// assign a DMA channel for endpoint 1 transmit and build
multiple buffer descriptors, if necessary
// assign a DMA channel for endpoint 2 transmit and build
multiple buffer descriptors, if necessary
// assign a DMA channel for endpoint 3 receive and build
multiple buffer descriptors, if necessary
// assign a DMA channel for endpoint 4 receive and build
multiple buffer descriptors, if necessary
7)
Configure the interrupt type for the USB device request (interrupt controller 0, number 24) as high-level.
8)
Configure the interrupt type for the USB device suspend (interrupt controller 0, number 25) as rising-edge.
9)
Start the Endpoint 0 receive DMA.
10) Enable USB Interrupts.
usbd_inten = 0x0000003f;// enable transfer-complete interrupts