USB
  How to increase HID_Example In/Out packet size?

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   How to increase HID_Example In/Out packet size?
Tsuneo
Member
posted October 11, 2005 03:01 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
How to increase HID_Example In/Out packet size?

To increase the number of data IN/OUT up to 64,

version "HID_Example", "Last updated: 25 MAY 2005" in "ReadMe.txt"
C:SiLabs\MCU\Examples\C8051F32x\HID_Example\

Firmware


a)-d) is same as the modification of "USB_INT"

a) "USB_MAIN.h"
// Increase max packet payload size (up to 64 byte)
#define EP1_PACKET_SIZE 0x0040 // Can range 0 - 64
#define EP1_PACKET_SIZE_LE 0x4000 // IMPORTANT- this should be Little-Endian version of EP1_PACKET_SIZE
#define EP2_PACKET_SIZE 0x0040 // Can range 0 - 64
#define EP2_PACKET_SIZE_LE 0x4000 // IMPORTANT- this should be Little-Endian version of EP2_PACKET_SIZE

// Select memory specifier (idata / pdata / xdata) for buffers
typedef BYTE idata buf_t;

b) "USB_MAIN.c"
// Apply memory specifier and adjust buffer size
buf_t Out_Packet[EP2_PACKET_SIZE] = {0}; // Last packet received from host
buf_t In_Packet[EP1_PACKET_SIZE] = {0}; // Next packet to sent to host

// Set SYSCLK to 24MHz
// If SYSCLK (and USBCLK) is set in "STARTUP.A51", Delete Sysclk_Init() itself.
void Sysclk_Init(void)
{
#ifdef _USB_LOW_SPEED_
...
#else
...
while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
// CLKSEL = SYS_INT_OSC; // Select system clock
CLKSEL = SYS_4X_DIV_2; // Select system clock

CLKSEL |= USB_4X_CLOCK; // Select USB clock
#endif /* _USB_LOW_SPEED_ */
}

c) "USB_ISR.c"
// Apply memory specifier and bug fix (Out_Packet and In_Packet are all capital letter)
extern buf_t Out_Packet[];
extern buf_t In_Packet[];

// In Handle_In1(), replace "IN_PACKET" to "In_Packet"
Fifo_Write(FIFO_EP1, EP1_PACKET_SIZE, (BYTE *)In_Packet);
// In Handle_Out2(), replace "OUT_PACKET" to "Out_Packet"
Fifo_Read(FIFO_EP2, EP2_PACKET_SIZE, (BYTE*)Out_Packet);

d) Customize "STARTUP.A51"
Set SYSCLK to 24MHz and disable Watchdog in "STARTUP.A51"

- Copy "STARTUP.A51" from following folder to the project folder and rename it,
for example, "USBINT_STARTUP.A51".
(Keil) C:\Keil\C51\Lib\STARTUP.A51
(SiLabs) C:\Silabs\MCU\IDEfiles\C51\Lib\STARTUP.A51

- On the IDE, add "USBINT_STARTUP.A51" to project and include it to build.
"Project" menu > "Add Files to Project": Select "USBINT_STARTUP.A51"
Right click "USBINT_STARTUP.A51" on the "File View" pane,
and select "Add USBINT_STARTUP.A51 to build"

- Modify "USBINT_STARTUP.A51" as follows

; Standard SFR Symbols required in XBANKING.A51
ACC DATA 0E0H
B DATA 0F0H
SP DATA 81H
DPL DATA 82H
DPH DATA 83H

PCA0MD EQU 0D9H
CLKMUL EQU 0B9H
CLKSEL EQU 0A9H

...
RSEG ?C_C51STARTUP

STARTUP1:

Oscillator_Init:
mov CLKMUL, #080h ; Enable Clk Multiplier
clr A ; Wait 5us for initialization
djnz ACC, $
orl CLKMUL, #0C0h ; Initialize Clk Multiplier
Osc_Wait2: ; Wait for stabilization
mov A, CLKMUL
jnb ACC.5, Osc_Wait2
mov CLKSEL, #002h ; SYSCLK: 4xClk Mult/2
; USBCLK: 4xClk Mult
WDT_Init:
anl PCA0MD, #0BFh ; disable WDT

IF IDATALEN <> 0

e) "USB_DESCRIPTOR.c"
- Increase interval on the endpoint descriptors
// IN endpoint (mandatory for HID)
{
...
0x08 // bInterval
},
// OUT endpint (optional for HID)
{
...
0x08 // bInterval
}

- Increase the report size
const hid_report_descriptor HidReportDesc =
{
...
0x75, 0x40 // REPORT_SIZE (64)
...
}

Please see following topic for another performance optimization.
"FIFO read/write performance"
"Losing Out_packets! F320 Vs Labview" posted October 04, 2005 10:17 PM by Tsuneo

Host application
a) "USBHid.cpp"
#define PKT_SIZE (64)

b) "USBTestDlg.h"
//
// buffer to transmit/receive USB data
//
#define REPORT_SIZE 64

struct USB_iobuf {
...
unsigned char not_used[REPORT_SIZE - 5];
};

To recompile the host application, Windows DDK is needed.
Select the Win DDK version in "USBHid.cpp"

// Define on of these macros below to select the DDK version
//#define DDK_2000_DDK
//#define DDK_XP_SP1_DDK
#define DDK_SERVER_2003_DDK

Microsoft distributes the Win DDK (Windows Server 2003 SP1 DDK) only with shipping and handling fee.
"Order Windows Driver Development Kits" on Microsoft

Tsuneo

My USB topics
How to increase HID_Example In/Out packet size?
FIFO read/write performance
256000 bytes/sec Isochronous transfer
Isochronous test patch
Multi-thread and Overlapped example for USB_INT Host Application
Vendor Requests test code
USB_INT and USB_BULK on Cypress device driver

[EDIT]
Oct 18, 2005 Added the link to "FIFO read/write performance"

[This message has been edited by Tsuneo (edited November 05, 2005).]

IP: Logged

Tsuneo
Member
posted October 11, 2005 03:45 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
[Resources]
"The HID Page" from Jan Axelson's site http://www.lvr.com/hidpage.htm

"Interactive Input Devices" on MSDN http://msdn.microsoft.com/library/d efault.asp?url=/library/en-us/intinput/hh/intinput/iidhdr_246df406-1973-483e-9bf5-2a3acf8f0be9.xml.asp

"USB Complete, 3rd Ed." J. Axelson
Chapter 11, Human Interface Devices: Using Control and Interrupt Transfers
Chapter 12, Human Interface Devices: Reports
Chapter 13, Human Interface Devices: Host Application

[Tools]
UVCView from MS http://www.microsoft.com/whdc/device/stream/vidcap/UVCview.mspx
To confirm how Windows recognizes the descriptors of the device.

"HID Descriptor Tool" from USB.org http://www.usb.org/developers/hidpage/dt2_4.zip
This tool allows you to create, edit and validate HID Report Descriptors.

"USBCV R1.2.1" from USB.org http://www.usb.org/developers/tools/
To test the firmware on device enumeration and HID specific requests.
- The PC must equip a Hi-Speed port. An external USB2.0 Hub is required.
- Also, prepare PS2 keyboard/mouse before running this application, because this app. replaces Win USB driver. An USB keyboard/mouse doesn't work during this app. is running. A note PC is a good platform to run this app. because the built-in keyboard/mouse of note PC is connected to PS2 (or equivalent) ports.

[And the last resort: Specification]
"HID Information" from USB.org http://www.usb.org/developers/hidpage/
"USB 2.0 Specification" from USB.org http://www.usb.org/developers/docs/

[EDIT]
March 7, 2006 Add PC and hub requirement to USBCV description

[This message has been edited by Tsuneo (edited March 07, 2006).]

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b