SAM4 USB

Hi,
    I am developing on Atmel SAM4_Xplained board, with SAM4 processor and Atmel Studio6 GCC.  I have Free RTOS working OK. The current application has serial ports running under PDC and interrupt control, with inter-task messages for internal communications. So far so good. Now the problem. I am trying to get USB running. Everything I have tried gets the same result, the program hangs. It seems as if the global interrupts are disabled. 
So far I have tried
a) make stack bigger for each task (up to 512 bytes) in Free RTOS config
b) change ISR priority from 5 (as delivered by ASF) to 11 to be less than the FreeRTOS max interrupt priority.
(even though I do not make any FreeRTOS calls in the USB stack)
c) delay start up of the USB stack for 10secs by initializing from a delayed task. No good they all crash. I have built and  loaded the demo applications USB-CDC and USB-MSC-RTOS.  These seem to work OK and I cant see any code difference between those applications and mine. Tracing the crash seems to happen after the first interrupt to the USB handler. (I break then continue). No other interrupt is then hit after that point.  When I break the program manually I find it is then in the FreeRTOS ‘lists’ and I presume that it
will effectively loop forever as no tick or other stimulus is occurring. Given that the USB stack only runs from this one interrupt and uses callbacks to signal events then I believe it should run (but do nothing) if all the callbacks are do-nothing functions. I also find it difficult ton see what interactions there could be between FreeRTOS and the USB stack. Has any one successfully implemented the ASF(3.4.1) USB stack on and Atmel SAM 4 processor ? I would be grateful for any advice on what to do next ?

SAM4 USB

The latest ASF version (if it is not already available, it will be in the next couple of days) includes a direct FreeRTOS peripheral control integration.  This is the application note. Although this ASF version does not include a FreeRTOS USB peripheral control integration, the example applications that are included do use the existing ASF USB functionality.  For example, the USB is used in the SAM4S-EK peripheral control example as in interface to the command line interface (CLI). I am, right now, working on a FreeRTOS integration along the lines of those outlined in the application note highlighted above. Regards.

SAM4 USB

Hi,
Thanks for the info. I will read the note with interest. I eventually found the fix by trawling line by line through a USB example that worked,( but did use FreeRTOS.) 
It boils down to adding this line at initialization time in main().  Its part of the SAM NVIC support in ASF. irq_initialize_vectors(); Also I placed some real code (toggle a debug LED) into each of the empty callbacks to prevent the compiler from optimizing them out. Now it all works. I don’t yet fully understand … given that if the interrupt system was not running correctly then none of my other comms stuff (USARTS) should have worked, but they clearly did. I have not yet removed the debug calls from the callbacks but I anticipate that it will all still work OK. Since I use a circular buffer between the FreeRTOS tasks and the USB interrupt stack process I get by by placing the task read functions between ENTER_CRITICAL and EXIT_CRITICAL sections. This seems to work fine and I can leave the USB ISR priority at 5 (the default) as this mechanism complies with FreeRTOS config rules. Best regards.

SAM4 USB

Richard. has there been any FreeRTOS/USB upgrade on the Atmel SAM4S since this was written?

SAM4 USB

It is quite possible that Atmel have updated their drivers since then – but you would have to check their ASF code. Regards.

SAM4 USB

They did not. I managed to figure it out bit by bit. Ugh. Thank you as always!