EmbeddedRelated.com
Forums

Modifying LPCUSB HID Example

Started by Border Patrol April 4, 2009
All,

I am currently using an LPC2148 based custom board with a
USB circuit similar to the Olimex devel board, and am rather new to USB
firmware. I successfully started with the LPCUSB HID example, and have the
following question:

Why can't I replace:

USBHwRegisterFrameHandler(HandleFrame);

with

USBHwRegisterEPIntHandler(INTR_IN_EP, Xmit);

where Xmit is a function defined roughly as:
void Xmit(U8 bEP, U8 bEPStatus)
{
/* Code to fill up abReport array */

USBHwEPWrite(INTR_IN_EP, abReport, REPORT_SIZE);
}
Doing this results in no activity from my device. I was assuming by using
the RegisterEP function with a function handle that that function would be
called only when an EP event had occurred. Using SnoopyPro, I can watch the
initial device handshaking operate correctly, but it stops when the host
starts to ask for IN reports. Works perfectly when I just modify the Frame
Handler function to fill the abReport array.

More questions to follow once this one's out of the way!

Thanks in advance,
Bob


An Engineer's Guide to the LPC2100 Series

USBHwRegisterEPIntHandler() surely register ISR for the endpoint.
However, the endpoint interrupt occurs just when a packet is sent to host.
Until you fill the endpoint buffer first, nothing is sent to host, then no interrupt occurs.

Usually, Set_Configuration handler is the place to initialize variables and flags for USB communication, which are added by you. Unfortunately, there is no hook for Set_Configuration on LPCUSB. The hook is indispensable to give a chance for stack users to initialize their USB communication, when bus reset - re-enumeration occurs.

- Add a hook for callback to Set_Configuration handler.
- In the callback, fill the endpoint buffer with a dummy report.
usbstdreq.c
https://lpcusb.svn.sourceforge.net/svnroot/lpcusb/trunk/target/usbstdreq.c

static Bool HandleStdDeviceReq( ... )
{
...
case REQ_SET_CONFIGURATION:
if (!USBSetConfiguration(pSetup->wValue & 0xFF, 0)) {
DBG("USBSetConfiguration failed!\n");
return FALSE;
}
// configuration successful, update current configuration
bConfiguration = pSetup->wValue & 0xFF;
callback_Set_Config(); // <--------- Add a hook for configuration
break;
void callback_Set_Config( void )
{
/* fill abReport array with a dummy report */

USBHwEPWrite(INTR_IN_EP, abReport, REPORT_SIZE); // put the report to EP buffer
}

Tsuneo

--- In l..., Border Patrol wrote:
>
> All,
>
> I am currently using an LPC2148 based custom board with a
> USB circuit similar to the Olimex devel board, and am rather new to USB
> firmware. I successfully started with the LPCUSB HID example, and have the
> following question:
>
> Why can't I replace:
>
> USBHwRegisterFrameHandler(HandleFrame);
>
> with
>
> USBHwRegisterEPIntHandler(INTR_IN_EP, Xmit);
>
> where Xmit is a function defined roughly as:
> void Xmit(U8 bEP, U8 bEPStatus)
> {
> /* Code to fill up abReport array */
>
> USBHwEPWrite(INTR_IN_EP, abReport, REPORT_SIZE);
> }
> Doing this results in no activity from my device. I was assuming by using
> the RegisterEP function with a function handle that that function would be
> called only when an EP event had occurred. Using SnoopyPro, I can watch the
> initial device handshaking operate correctly, but it stops when the host
> starts to ask for IN reports. Works perfectly when I just modify the Frame
> Handler function to fill the abReport array.
>
> More questions to follow once this one's out of the way!
>
> Thanks in advance,
> Bob
>
>