Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training



Posted by Tom Barclay on November 21, 2012
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 ?


Posted by Richard on November 21, 2012
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.



Posted by Tom Barclay on November 23, 2012
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.


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.


Posted by pugglewuggle on August 23, 2015

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


Posted by rtel on August 23, 2015

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



Posted by pugglewuggle on August 26, 2015

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

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists