English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (282/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
11.5 PIC32MX Implementation
Specifics
This section details how the USB specification require-
ments are implemented in the PIC32MX USB module.
11.5.1 BUS SPEED
The PIC32MX USB module supports the following
speeds:
• Full-speed operation as a host and a device
• Low-speed operation as a host
11.5.2 ENDPOINTS AND DESCRIPTORS
All USB endpoints are implemented as buffers in RAM.
The CPU and USB module have access to the buffers.
To arbitrate access to these buffers between the USB
module and CPU, a semaphore flag system is used.
Each endpoint can be configured for TX and/or RX, and
each has an ODD and an EVEN buffer.
Use of the Buffer Descriptor Table (BDT) allows the buf-
fers to be located anywhere in RAM, and provides sta-
tus flags and control bits. The BDT contains the
address of each endpoint data buffer, as well as infor-
mation about each buffer (see Figure 11-2, Figure 11-3
and Figure 11-4). Each BDT entry is called a Buffer
Descriptor (BD) and is 8 bytes long. All endpoints, rang-
ing from endpoint 0 to the highest endpoint in use, must
have four descriptor entries. Even if all of the buffers for
an endpoint are not used, four descriptors entries are
required for each endpoint.
The USB module calculates a buffer’s location in RAM
using the BDT. The base of the BDT is held in registers
U1BDTP1 through U1BDTP3. The address of the
desired buffer is found by using the endpoint number,
the type (RX/TX) and the ODD/EVEN bit to index into
the BDT. The address held by this entry is the address
of the desired data buffer. Refer to Section 11.4.3.1
“A-Device, the Default Host”.
Note:
The contents of the U1BDTP1-U1BDTP3
registers provide the upper 23 bits of the
32-bit address; therefore, the BTD must
be aligned to a 512-byte boundary (see
Figure 11-2). This address must be the
physical (not virtual) memory address.
Each of the 16 endpoints owns two descriptor pairs:
two for packets to transmit, and two for packets
received. Each pair manages two buffers, an EVEN
and an ODD, requiring a maximum of 64 descriptors
(16 * 2 * 2).
Having EVEN and ODD buffers for each direction
allows the CPU to access data in one buffer while the
USB module transfers data to or from the other buffer.
The USB module alternates between buffers, clearing
the UOWN bit in the buffer descriptor automatically
when the transaction for that buffer is complete (see
Section 11.4.3 “OTG Dual Role”). The use of alternat-
ing buffers maximizes data throughput by allowing
CPU data access in parallel with data transfer. This
technique is referred to as ping-pong buffering.
Figure 11-2 illustrates how the endpoints are mapped
in the BDT.
11.5.2.1 Endpoint Control
Each endpoint is controlled by an Endpoint Control reg-
ister, U1EPn, that configures the transfer direction, the
handshake, and the stalling properties of the endpoint.
The Endpoint Control register also allows support of
control transfers.
11.5.2.2 Host Endpoints
Note: In Host mode, Endpoint 0 has additional
bits for auto-retry and hub support.
The host performs all transactions through a single
endpoint (Endpoint 0). All other endpoints should be
disabled and other endpoint buffers are not be used.
11.5.2.3 Device Endpoints
Endpoint 0 must be implemented for a USB device to
be enumerated and controlled. Devices typically imple-
ment additional endpoints to transfer data.
11.5.3 BUFFER MANAGEMENT
The buffers are shared between the PIC32MX and the
USB module, and are implemented in system memory.
So, a simple semaphore mechanism is used to distin-
guish current ownership of the BD, and associated buf-
fers, in memory. This semaphore mechanism is
implemented by the UOWN bit in each BD.
The USB module clears the UOWN bit automatically
when the transaction for that buffer is complete. When
the UOWN bit is clear, the descriptor is owned by the
PIC32MX – which may modify the descriptor and buffer
as necessary.
Software must configure the BDT entry for the next
transaction, then set the UOWN bit to return control to
the USB module.
A BD is only valid if the corresponding endpoint has
been enabled in the U1EPn register. The BDT is imple-
mented in data memory, and the BDs are not modified
when the USB module is reset. Initialize the BDs prior
to enabling them through the U1EPn. At a minimum,
the UOWN bits must be cleared prior to being enabled.
In Host mode, BDT initialization is required before the
U1TOK register is written, triggering a transfer.
DS61143E-page 280
Preliminary
© 2008 Microchip Technology Inc.