I'm integrating the example USB module into my existing app and can only get it to work when I disable interrupts.
I'm working off the mla example installed at the path:
C:/microchip/mla/v2013_12_20/apps/usb/device/bootloaders/firmware/pic18fxxjxx
Details
- I'm implementing each of USB callback functions exactly as done in the example.
- USB clock is 48MHz
- CPU (f_osc) clock is 16MHz
- pic18f25k50
- one high-priority interrupt for Timer1 ticks every 250us, everything else happens about every 1s
- never go to sleep, yet this still seems to reset
Is microchip's USB stack not thread-safe?
Am I not running the USB task fast enough?
while (1)
{
// Clear the watchdog timer
ClrWdt();
// Run the USB task faster than xxxHz?
USBDeviceTasks();
// Do stuff
}
// high-priority foreground loop takes ~5us
void high_priority interrupt HighPriorityTasks(void)
{
// Do stuff quickly, clear sources of interrupts
}
// low-priority foreground loop takes ~5us
void low_priority interrupt LowPriorityTasks(void)
{
// Do stuff quickly, clear sources of interrupts
}
When it fails, I see device manager continue to refresh accompanied by one of these popups about every 5s in Windows 7:
Best Answer
Try using USB in interrupt mode. USB devices must respond to host requests within a certain time frame. You haven't detailed how long your timer tasks routine takes to execute but from this error it seems that it is taking too long and there is no way for the USB to respond in a timely fashion.
Without specific details of your application, I would suggest running USBDeviceTasks() as the only high priority interrupt task and set the timer and its tasks as lower priority.
This way when the host requests a response from the PIC when it is executing the timer tasks it will pause executing that routine, answer the host, and then return to that routine.