|
|
|
|
usbbulk-1-0-3-lpc214x.zip |
| This ZIP archive contains: |
|
| |
- A TNKernel USB bulk firmware source code (with TNKernel v.2.1)
- The examples for the Philips LPC
2146 microprocessor (includes the projects for the Rowley
CrossWorks Studio(GCC) 1.5, IAR ARM v.4.30, GCC 3.4
(4.10), ARM ADS 1.2, ARM RVCT
2.2, Keil RVC v.3
- The LPC2146 reference board's schematic.
|
|
|
|
usbio_demo.exe
|
This is a Thesycon(r)free USB Development Kit Demo for Windows
(The Demo package may freely be distributed or passed to third parties
according to Thesycon's License §1.3)
|
|
|
The TNKernel USB bulk
firmware is the USB bulk device driver for TNKernel real-time OS. Current
version of the USB bulk firmware supports Philips LPC214x ARM-based
microcontrollers.
There
are two main groups of operations in USB bulk
firmware - support USB Control (Endpoint 0) and support of the bulk data
reception/transmission.
1. Endpoint 0 Control
Requests Processing
The control
transfers processing (Chapter 9 of the USB specification) is a mostly independent of the hardware (see file
tn_usb_req.c).
The TNKernel USB firmware supports the 9 required requests. The
SYNCH_FRAME and SET_DESCRIPTOR requests are not supported (these put
device to the forced stall condition)
|
Request
|
Direction
for Data Stage |
Description of host request
|
| GET_CONFIGURATION |
IN |
The current device
configuration number.
Device responds during the data stage with a one byte info which
configuration was last selected. |
| GET_STATUS |
IN |
The current status of the device, an
interface, or an endpoint. The device responds during the data stage
with a two bytes, that contains a requested status. |
| GET_DESCRIPTOR |
IN |
A descriptor. The
device responds during
the data stage with the requested descriptor data. If the request is
for a configuration descriptor, all interface and endpoint descriptors
associated with that configuration are returned (up to the amount of
data requested by the host). |
| GET_INTERFACE |
IN |
The currently selected alternate for a
given interface. The device responds with the alternate number of the
currently selected alternate interface. |
| SET_ADDRESS |
no data stage |
Set the
address contained in the request. The device updates its
address to reflect the new address after the status stage of this
request. |
| SET_CONFIGURATION |
no data stage |
Set a device configuration. |
| SET_INTERFACE |
no data stage |
An alternate interface for the
selected interface number. |
| SET_DESCRIPTOR |
OUT |
This request is optional and is not
supported by the TNKernel USB bulk firmware. |
| SET_FEATURE |
no data stage |
Request to enable a device feature
(remote wakeup) or an endpoint feature (endpoint halt). |
| CLEAR_FEATURE |
no data stage |
Request to disable a device feature
(remote wakeup) or an endpoint feature (endpoint halt). |
| SYNCH_FRAME |
IN |
This request is optional and is not
supported by the TNKernel USB bulk firmware. |
2. Bulk Endpoints Transfer
processing
The
USB is a block device and
to reach maximal bulk data
transfer rate, the data have to be transferred by the 64-byte packets. The TNKernel
USB bulk firmware uses a fixed size 64-bytes packets only. For the variable
length data, you can use any of a well-known technologies for
a block device drivers.
2.1 Transfer without DMA (Philips LPC214x)
The each endpoint has an associated data queue and a fixed-sized memory pool
with the own task for the operations.
For the IN endpoints (transmission) the each data queue's
entry
contains a pointer to the memory block (64 bytes) with the data to
transmit. A memory blocks are managed by the fixed-sized memory pool.
An each IN token causes a hardware interrupt. In
the interrupt
handler, if the data queue's is not empty (there are data to
transmit) then the data is entered into the hardware transmitter and a memory block
is released. Otherwise, there are no a data for the writing
to
the transmitter and the hardware automatically sends the NAK answer to the host.
For the OUT endpoints (reception) the each data queue's
entry
contains a pointer to the empty memory block (64 bytes) to store
receiving data. A memory blocks are managed by the fixed-sized memory pool.
The each OUT request causes hardware interrupt. In
the interrupt
handler, if there is a free memory block for the reception, then the firmware
reads a data from the hardware receiver to the memory block. A pointer to the memory block is sent
into the data queue.
The reception task waits the data from the receiver data
queue by the TNKernel tn_queue_receive() function.
2.2 Transfer with DMA (Philips LPC2146/8)
The each endpoint has an associated data queue and a fixed-sized
memory pool with the own task for the operations.
For the IN endpoints (transmission) the each data queue's
entry
contains a pointer to the memory block (64 bytes) with the data to
transmit. A memory blocks are managed by the fixed-sized memory pool.
There are two DMA interrupts for each IN
transaction:
- end_of_transfer
(transmission of data block is finished)
- DD_request (descriptor_request)
- new DMA memory block should be set for transmission.
In the transmission's end_of_transfer
interrupt handler, the firmware just clears an interrupt flag for the normal
hardware operations.
In the transmission's DD_request
interrupt handler, the firmware checks a data queue. If a data queue is not
empty (there are data to transmit), the firmware selects a new DMA memory
block for the transmission and copies data from the queue's memory block to the DMA
memory. A queue's memory block is released.
If the data queue is empty (there are no data to
transmit), the firmware sets as active a special DMA memory block with the no_packet
parameters. When the DMA engine makes a processing for the
block, it sends the NAK answer to the host.
For the OUT endpoints (reception) the each data queue's
entry
contains a pointer to the empty memory block (64 bytes) to store
receiving data. A memory blocks are managed by the fixed-sized memory pool.
There are two DMA interrupts for each OUT request:
- end_of_transfer
(data is ready in DMA memory)
- DD_request (descriptor_request)
- new DMA memory block should be set for receiver
In the reception's end_of_transfer
interrupt handler, the firmware gets a free memory block from the fixed-sized
memory pool and the data is copied to this memory block from the DMA memory.
A pointer to the memory block is sent into the receiver's data queue.
The reception task waits the data from the receiver's
data queue by the TNKernel tn_queue_receive() function.
When a data arrives, a reception task makes the user data
processing. Then a memory block is released and the DMA
interrupt (actually, data reception) is enabled for this endpoint.
Until
a DMA endpoint interrupt is disabled, the hardware automatically sends the NAK
answer to the host for each OUT request.
In the reception's DD_request
interrupt handler, the firmware checks a free memory
block availability in the fixed-sized memory
pool. If there
is no free memory block, a DMA interrupt is not enabled (it means the NAK
answer to host). If there is free memory block, the firmware sets
a new
DMA memory block for the reception and enables a DMA endpoint interrupt (the data
reception).
3. USB VID and PID
For the TNKernel USB bulk firmware tests, a dummy VID = 1237(hex)
& PID = ABCD(hex) are used (see the file tn_usb_descr.c).
4. PC USB driver and test
software
The TNkernel USB has been
tested with the USBIO - USB host driver for
Windows from Thesycon(r) (http://www.thesycon.de).
The demo version of the driver can be used for 4
hours. Then all
function calls will be rejected and the computer must be rebooted in
order to use the demo again.
A free USBIO Development Kit Demo includes
Installation Wizard,
USBIO Cleanup Wizard and test application (it is used for all TNKernel
USB tests).
5. PC USB driver installation
5.1.
Install a demo version of USBIO – USB Development Kit for
Windows
*.exe file from Thesycon(r) (http://www.thesycon.de)
5.2.
Load the test firmware into the Philips LPC2146/48
FLASH - either with or without DMA
5.3.
Open the Windows Device Manager (Control
Panel -> System -> Hardware -> Device Manager or Start Menu -> Run and then type 'devmgmt.msc'
5.4.
Connect an USB cable from the PC to the development
board
A message 'Found New Hardware TNKernel USB' in the desktop tray
should
appear and in the Windows Device Manager's list the new record 'Other devices
-> TNKernel USB' should be added.
Close a Windows Driver Installation Wizard window (Windows invokes it automatically). It
is not used
here.
5.5.
From an USBIO installation directory,
run the USBIO's own
Installation Wizard - USBIOwiz.exe
Select the device '>>Unknown<<
| TNKernel USB' from the
list and press a button 'Next'.
After the finishing of
the process, in the Windows Device Manager's list you shell see
a record 'USBIO controlled devices -> USBIO Device VID=1237 PID=ABCD'.
Close the USBIO Installation Wizard application.
6.
TNkernel USB bulk firmware tests
There are two sets of the base test firmware:
- in the firmware's directory 'LPC2146'
- a test application without DMA.
- in the firmware's directory 'LPC2146_DMA' - a test
application with DMA.
The test firmware creates a 2 bidirectional bulk pipes
by the LPC214x's USB Endpoint 2 and Endpoint 5.
An each physical endpoint has the own task to operate.
6.1
Preparation of the tests
6.1.1
Load the test firmware into the Philips LPC2146/48 FLASH;
6.1.2 From the USBIO installation directory, run the USBIO test
application (it is used for all TNKernel USB firmware tests) - USBIOAPP.EXE.
In the main window on the page 'Device', select in the listbox 'Available Devices' device's entry (for the single USBIO device, it will be the entry 'Device 0') and
press a button 'Open'. Check all operations results by the messages in the 'USBIOAPP
Output Window'.
On the page 'Configuration' press a button 'Set Configuration'. the LED on Test Board should stop flickering.
On the page 'Pipes', the all four firmware endpoints have to be in the listbox 'Active Endpoints'.

6.2 Test N 1 - Checking speed of
'PC to USB device' data stream
In the firmware test N1, the Endpoint 5 RX (Bulk OUT Pipe 0x05) receives the data from the PC.
In the main window on the page 'Pipes', in the listbox 'Pipes' select the '0x05 Bulk OUT'
and press a button 'Read from File and Write to Pipe' - a new dialog window is opened.
In the dialog window 'USBIOAPP - Bulk OUT Pipe 0x05' open the page 'Buffers' and set 'Size of Buffers' - 4096, 'Number of Buffers'- 4.
On the page 'Write from File to Pipe' choose a source file (any, but it is
recommended to use a file with size of few megabytes) and press a button 'Start Writing'.
After a few seconds of transmission, the value of a transfer speed in the editbox 'Mean data rate' will be stable.
6.3
Test N 2 - Checking speed of 'USB device to PC' data stream
In the firmware test N2, the Endpoint 2 TX (Bulk IN Pipe 0x82) sends a data
in the text format by the 64-byte packets.
In the main window on the page 'Pipes', in the listbox 'Pipes' select the entry '0x82 Bulk
IN' and press a button 'Read from Pipe and Write to File' - a new dialog window is opened.
In the dialog window 'USBIOAPP - Bulk IN Pipe 0x82' open the page 'Buffers' and set 'Size of Buffers' - 4096, 'Number of Buffers'- 4.
On the page 'Read from Pipe to File' choose a destination file and press a button 'Start Reading'.
In the editbox 'Mean data rate' you shell see the transfer speed value. Do not
stop a reading immediately because the measurement takes a few seconds.
You can check a
destination data file's contents with any text viewer/editor. An each
text line in the file starts with the 12-digit ASCII
number and has following spaces up to the line end. A total line length
is
64 bytes - 62 bytes of the text + 2 bytes for the
'\r\n'.The ASCII
numbers must be in the '+1' sequence from line to line without dropping.
6.4 Test N 3 - Checking speed of loop-back data transfer
In the firmware test N3,
the Endpoint 2 (Bulk OUT pipe 0x02) and the Endpoint 5 (Bulk IN pipe
0x85) are used for the loop-back data transferring - the data, that the Endpoint 2
RX receives from the PC, are sent to the Endpoint 5 TX for
the transmission back to the PC (in the firmware, there is a separate data queue for
this purpose).
In the main window on the page 'Pipes', in the listbox 'Pipes'
select the entry '0x02 Bulk OUT' and press a button 'Read from File and Write to Pipe' - a new dialog window is opened.
In the main window on the page 'Pipes', in the listbox 'Pipes' select the entry '0x85 Bulk
IN' and press a button 'Read from Pipe and Write to File' - a new dialog window is opened.
In the both dialog windows open the page 'Buffers' and set 'Size of Buffers' -
4096, 'Number of Buffers'- 4.
In the dialog window 'USBIOAPP - Bulk IN Pipe 0x85', on the page 'Read from Pipe to File' choose a destination file.
In the dialog window 'USBIOAPP - Bulk OUT Pipe 0x05', on the page 'Write from File to Pipe' choose a source file (any, but it is recommended to use a file
with size of few megabytes ).
Uncheck the checkbox 'Rewind at and of file'.
Press a button 'Start Reading'.
Press a button 'Start Writing'.
After finishing of the transfer, press a button 'Stop reading'
(the writing is terminated automatically).
You can compare both files (the source and the destination) - they
must have the same length and contents.
7. Data transfer
performance tests
7.1. Environment:
|
Host computer: |
Pentium(R) 4 CPU 1.60 GHz, 256Mb RAM |
| |
Intel(r) 82801 BA/BAM USB Universal Host Controller |
| |
Windows XP Pro SP2 |
| |
|
| Host USB driver: |
Thesycon(r) USBIO.SYS v.2.31 Demo version |
| |
|
| Host application: |
USBIOAPP.EXE by Thesycon(r) |
| |
Buffers size - 4096 Number of buffers - 4 |
| |
|
| Device: |
Philips LPC 2146 (Fcore
= 60MHz, Fusb
= 48MHz) |
7.2.Raw data transfer (no OS, just send/receive dummy data)
| Speed for both direction (PC to device, device to PC) - KBytes/sec |
|
Without DMA |
1132 |
| With
DMA |
1136 |
7.3. TNkernel USB bulk firmware (with TNKernel v.2.1) examples
Firmware tests: - usb_test1 (without DMA)
- usb_test2 (with DMA)
| TNkernel USB bulk firmware examples - data transfer speed (in KBytes/sec) |
| Test |
PC to device |
Device to PC |
| Loop-back |
| PC to device |
Device to PC |
| With DMA |
1083 |
1083 |
565 |
565 |
| Total: 1130 |
| Without DMA |
1048 |
753 |
565 |
565 |
| Total: 1130 |
|