FreeRTOS and USB

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I've got a question concerning the use of FreeRTOS on the AT32UC3C.

I startet my custom-board project without the use of FreeRTOS. Among some other things I implemented a at45dbx-dataflash and the access to it via USB-MSC.
The Framework offered a lot of well usable functions and examples to get this working.

Now I have to implement the network interface. Therefore I adopted the FreeRTOS and lwIP-Example from the ASF (for UC3A on EVK1100) to my custom board, so i could access the web-server via ethernet-interface.

Now after integrating the FreeRTOS and lwIP-Files from the adopted Example-Project to my UC3C-Project it seems as if the USB-MSC-part isn't working anymore:
If I plug the device in my computer via usb, windows tells me that the device can't me recognized.
The use of the RTOS is strongly desirable, because the whole thing will get more and more complex on the application-layer.

So if anyone could give me a hint where and what to look for (for example that the USB_driver has to be handled differntly, when using RTOS), _please_ tell me... because I am pretty at a loss at the moment.

Greetings, and have a nice weekend...
jabba

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So windows tells you that the device can't be recognized? This is a very poor problem description. Provide more details in future if you really need help.

I'm deep into the theme so you're lucky. Maybe you did run into problems with the interrupt handling that ends up in an exception (where you may have a while(1) loop, so your system does not do anything anymore).

1. Make sure that you really use the latest version of the ASF. Older versions did not support FreeRTOS (make sure that the usb driver uses the ISR_FREERTOS macro)

2. FreeRTOS does not support nested interrups. Add the following lines to your conf_usb.h (I assume you're implementing a device since you connect your board to your pc) otherwise modify conf_usb_host.h:

#ifdef FREERTOS_USED
    #include "portmacro.h"
    #include "FreeRTOS.h"
    #include "projdefs.h"
/* make sure that we protect malloc and free
   use our patched version that disables interrupts */
    #define malloc(x) pvPortMalloc(x)
    #define free(x) vPortFree(x)

/* make sure that all interrupts use the same priority
   since FreeRTOS does not support nested interrupts */
    #define UDD_USB_INT_LEVEL 1
#endif

Make sure that all other interrupst that you use are registered with exactly the same INT_LEVEL. You may have noticed the comment about malloc/free. Since the stack uses malloc/free from an interrupt context it makes sense to protect those calls like this:

void *pvPortMalloc( size_t xWantedSize )
{
void *pvReturn;

	irqflags_t flags = cpu_irq_save();

	vTaskSuspendAll();

	{
		pvReturn = malloc( xWantedSize );
	}
	xTaskResumeAll();

	cpu_irq_restore(flags);

	#if( configUSE_MALLOC_FAILED_HOOK == 1 )
	{
		if( pvReturn == NULL )
		{
			extern void vApplicationMallocFailedHook( void );
			vApplicationMallocFailedHook();
		}
	}
	#endif

	return pvReturn;
}
/*-----------------------------------------------------------*/

void vPortFree( void *pv )
{
	if( pv )
	{
		irqflags_t flags = cpu_irq_save();
		vTaskSuspendAll();
		{
			free( pv );
		}
		xTaskResumeAll();
		cpu_irq_restore(flags);
	}
}

-sb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a old thread, I know :) But this was exactly my problem by adding USB_CDC to FreeRTOS.
Very big THANK YOU to sambrown for your replay!!!

#define UDD_USB_INT_LEVEL 1 

solves the problem and now it is running well.

But I would like to know why it is working now. Do I understand it right that the IRQ for USB now will be invoked before IRQ for FreeRTOS will be invoked (because the nested interrupt for USB becomes a higher priority to level=1)? So FreeRTOS would use a level=0 for nested interrupt (cannot see a level for FreeRTOS anywhere)?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://www.freertos.org/FAQISR.html

Can interrupts be nested?

the answer is NO for the AVR32 FreeRTOS port

-sb