nxpUSBLib issues

boscodog wrote on Thursday, August 23, 2012:

I have nxpUSBLib working on a LPCExpresso LPC1769. I modified the generic HID example for my VID/PID and descriptors.
The device enumerates using this framework
I want to use an RTOS and I have a thread that replaces the for(;:wink: loop. This thread runs every 10ms and it is running.

The issue is that the device does not work at all. The USB reset causes the Host to send GetDescriptor but the stack does not ACK

I am seeing an interrupt upon connection, but the device just does not send anything.
So I an wondering what could be the difference between the standard CMSIS startup and the one provide by FreeRTOS?

rtel wrote on Thursday, August 23, 2012:

Before we get into how you have integrated the USB - do you have FreeRTOS running on your hardware stand alone?  That is, can you run the standard demo, or create a couple of tasks that just increment variables and see that both tasks are executing?


boscodog wrote on Friday, August 24, 2012:

I create the project using the built in wizard in LPCExpresso 4.2.3
the example has tow threads and was working fine, so the LPC1769 is working fine with FreeRTOS.

I did find some problems in the USB stack.  One is the port.pin for the revB board is 2.9 and that fixed the pull up issue.
I also found that the HID endpoint descriptor must be FIXED_CONTROL_ENDPOINT_SIZE which is 64.  I ported the descriptors from another project it the device only had a 32 byte endpoint 0.

I also found a hardcoded #define __REDLIB so I changed the build to include these

The nxpUSBLib has a very weird build structure.

so now, the stack is now partially enumerating a HID device with my descriptors.
sometimes it will fully enumerate.

the thread is simple
xTaskCreate( vUserTask1, ( signed portCHAR * ) “Task1”, USERTASK_STACK_SIZE, NULL, 3, NULL );
stack size is 512
void vUserTask1(void *pvParameters)
while (1) {

since neither of these functions call any RTOS API I should not have to worry about ISR/RTOS issues, correct?

#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 119000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 512 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 9 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_CO_ROUTINES 0
#define configUSE_MUTEXES 1

#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

#define configUSE_ALTERNATIVE_API 0
#define configQUEUE_REGISTRY_SIZE 10

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1

boscodog wrote on Friday, August 24, 2012:

I’ll have to check to see that this part is running at the right clock speed and that the ticks are correct.
It is either that, or nxpUSBLib is telling fibs.  I change the thread vTaskDelay(1) and it starts to enumerate ok.
the doc says that these callback functions can be called at 30-50ms for USB Device. 

boscodog wrote on Friday, August 24, 2012:

interesting update.
The doc says that the the calls

can be called every 30ms. Doesn’t seem to be the case.
I was calling every 10ms but the device fails to enumerate. I change to 5ms and found that it gets farther into the enumeration
changed it to 1ms and it enumerates fine.

All the provided code examples user a super loop so I am wondring if this should be explained in the nxpUSBLib  doc if someone wants to use a RTOS.

Since my device enumerates with 10ms polling rate, I can set the wait time to 1ms for enumeration, and then back it off to 10ms for normal operation.

rtel wrote on Friday, August 24, 2012:

USB has very strict timing requirements during the enumeration process, and less strict after that.  It might be best to raise the priority of the task and use short delays (or use an interrupt) to enumerate, then lower the priority and use longer delays after that.

You might also consider using vTaskDelayUntil() in place of vTaskDelay() to get less jitter in your timing.