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];
};