Problems using lwIP and USB host together

Hi all, I’m trying to use lwIP and USB host together (LPC1768). The IP is from FreeRTOS sample CORTEXLPC168GCC_RedSuite, and the USB is from the lpcopen 2.10. Each task works fine if alone, but when they work together, I have problems on the enumerating devices when the USB is detached and reattached: sometimes I get an HardFault and sometimes the enumeration hangs in the function: static HCDSTATUS WaitForTransferComplete(uint8t EdIdx) { while ( HcdED(EdIdx)->status == HCDSTATUSTRANSFERQUEUED ) {} return (HCDSTATUS) HcdED(EdIdx)->status; } where the <HcdED(EdIdx)->status> should be updated by the USB’s ISR. It seems an interrupt problem, but I don’t understand more. Any help is greatly appreciated. Best regards, Paolo

Problems using lwIP and USB host together

Parts of the USB protocol have tight timing requirements, and it might be that the USB interrupt is being pre-empted by the lwIP interrupt. Try ensuring the USB interrupt has a much higher priority than the Ethernet interrupt. If the USB interrupt is not using the FreeRTOS API then you can even set it to the highest possible priority (which is zero on an LPC1768) to ensure its timing is not effected at all by anything else that is happening in the system – not even any critical sections that might be in the lwIP code. Remember that if the USB interrupt is using the [interrupt safe] FreeRTOS API [only API functions that end in ‘FromISR’ are intended for use in interrupt] then its priority must be at or below that set by configMAXSYSCALLINTERRUPT_PRIORITY: http://www.freertos.org/RTOS-Cortex-M3-M4.html – if you are using a recent version of FreeRTOS then ensuring configASSERT is defined will check this automatically for you at run time http://www.freertos.org/a00110.html#configASSERT Also make sure, if using the API in the interrupt, that you make use of the pxHigherPriorityTaskWoken parameter to ensure the interrupt returns directly to any unblocked tasks. Regards.