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


Interrupt handling in FreeRTOS

Posted by Bart on June 6, 2010

I'm wondering if there is a special mechanism for handling
interrupts in FreeRTOS? I wanted to write a simple interrupt
routine that would toggle a led when I press a button. But sadly,
when I add the interrupt initialization code, the task won't start.
Here's the code:

void initInterr()

void vStartLEDFlashTasks()
xTaskCreate( vLEDBlink, ( signed char * ) "LEDtaskC", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL );


void ChangeFlashRate()
int status;
status = AT91C_BASE_PIOA->PIO_ISR;
vParTestToggleLED( 0 );

As you can see it's very simple. I'm using SAM7-P64 dev board. Am i doing it wrong?

RE: Interrupt handling in FreeRTOS

Posted by Bart on June 6, 2010
It seems like the line :


is the problem. If I comment it, the task is running and everything is ok. How should I handle the interrupt then?

RE: Interrupt handling in FreeRTOS

Posted by Rohit Grover on June 6, 2010
Try enabling your interrupt only after the freeRTOS scheduler gets started.
In your FreeRTOS port, isn't there a sample serial driver using interrupts which can help as a reference?

RE: Interrupt handling in FreeRTOS

Posted by Bart on June 8, 2010
Hi, I bought the manual and changed my code, but interrupts still don't work. Everything seems to be ok. Is the ISR written correctly?

void ToggleLedISR()
int status;
static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

status = AT91C_BASE_PIOA->PIO_ISR;
xSemaphoreGiveFromISR(xSemafor, &xHigherPriorityTaskWoken);

if(xHigherPriorityTaskWoken == pdTRUE) {


Here's the task that takes the semaphore:

void ToggleLedTask(void *pvParameters) {

while(1) {
xSemaphoreTake(xSemafor, portMAX_DELAY);

vParTestToggleLED( 0 );


RE: Interrupt handling in FreeRTOS

Posted by Richard Damon on June 8, 2010
Not familiar with this processor, but the line
would be my guess at the error. I presume this is an end of interrupt control, and probably doesn't want to be conditioned on xHigherPriorityTaskWoken. I would suggest placing it before the if statement.

RE: Interrupt handling in FreeRTOS

Posted by Bart on June 8, 2010
I got it working. It seems that an interrupt handler that gives a token to a semaphore needs to be called from a wrapper that copies the context. I got it working with:

void vLed_ISR_Wrapper( void )
/* Save the context of the interrupted task. */

/* Call the handler itself. This must be a separate function as it uses
the stack. */
__asm volatile ("bl vLed_ISR_Handler");

/* Restore the context of the task that is going to
execute next. This might not be the same as the originally
interrupted task.*/

Now, correct me if I'm wrong, but that is the only way I managed to get it done. Without the wrapper the processor "hangs" itself. And of course both the wrapper and the handler must be compiled in ARM mode. Or is there a way without using a wrapper?

RE: Interrupt handling in FreeRTOS

Posted by Richard on June 8, 2010
If your interrupt is wanting to cause a context switch, or wanting to call a FreeRTOS API function, then the wrapper is required - as per the documentation and examples.


[ 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