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




Loading

Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by ajienikicio on March 19, 2015

Hi,

I'm having a problem of a crash whenever a FromISR function is called in my TWI0_Handler(). I have followed the interrupt priority rule as mentioned here (and tried different numbers) http://www.freertos.org/RTOS-Cortex-M3-M4.html but the problem persists.

So configLIBRARYMAXSYSCALLINTERRUPTPRIORITY is set to 5 and configLIBRARYLOWESTINTERRUPT_PRIORITY is set to 0x0f (as in Demo for SAM3X). And this is how the interrupt is initialized:

NVIC_SetPriorityGrouping( 0 );

NVIC_DisableIRQ(TWI0_IRQn);
NVIC_ClearPendingIRQ(TWI0_IRQn);
NVIC_SetPriority(TWI0_IRQn, 6);
NVIC_EnableIRQ(TWI0_IRQn);

and this is the TWI ISR:

void TWI0Handler() { int status = twigetinterruptstatus(TWI0); portBASE_TYPE xTaskWoken = pdFALSE; printf("entered testISRn");

xSemaphoreGiveFromISR( testHandle, &xTaskWoken );    // hangs here
    printf("passed fromISR\n");

portEND_SWITCHING_ISR( xTaskWoken );

}

Do I miss anything here?

Thank you very much for your help!


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by davedoors on March 19, 2015

Can you try again without the printf() in the ISR.


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by ajienikicio on March 19, 2015

Just tried and it still crashed at the same place


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by davedoors on March 19, 2015

Did you remove both printfs? Which version of FreeRTOS are you using? Have you defined configASSERT()? Is taskHandle valid? When you step into the function where does the crash happen?


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by ajienikicio on March 19, 2015

Yes I removed both printfs and it crashed again.

I'm not familiar with configASSERT, do I have to define it by myself? I found some lines related to it in the FreeRTOS source codes such as this in the FreeRTOSConfig.h:

define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

and in FreeRTOS.h:

ifndef configASSERT
#define configASSERT( x )
#define configASSERT_DEFINED 0
else
#define configASSERT_DEFINED 1
endif

taskHandle is just a SemaphoreHandle_t defined globally.

The crash happens at xSemaphoreGiveFromISR( testHandle, &xTaskWoken ). This problem also happened with xQueueSendToBackFromISR.


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by rtel on March 19, 2015

Here is the link to configASSERT() info:

http://www.freertos.org/a00110.html#configASSERT

You define it in FreeRTOSConfig.h - it can do what you want as long as you know it has been called. The normal thing to do is disable interrupts and sit in a loop, as per your post, so when you break the debugger you can see it is sat on a configASSERT() statement. There are more elaborate schemes you can implement - but the simpler the better I think.

Generally calling printf() in an interrupt is not recommended.

The crash happens at xSemaphoreGiveFromISR( testHandle, &xTaskWoken ).

I think the intention was for you to find out where inside the function the crash happens. If you place a break point on the line, then step into the function in the debugger you should be able to see why the crash happens.

Regards.


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by ajienikicio on March 23, 2015

Hi!

I had confirmed that there was no configASSERT() called and I just found out the problem :).

After looking at the FreeRTOS Demo Application again, I noticed that the Demo sets configTOTALHEAPSIZE as 40960, while I had 8096. After setting it to 40960, the problem disappeared. But I don't understand why the value was causing the problem.


Problem with FromISR functions and TWI Interrupt using Atmel SAM3X

Posted by rtel on March 23, 2015

If you run out of heap then queues, semaphores, event groups, tasks, etc. cannot be created - and the return value of the function used to create the object will return pdFAIL. Are you checking the return values of such functions - or any direct call to pvPortMalloc().

You can also define a malloc failed hook function to get notification that the heap was exhausted.

Regards.


[ 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