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 taskEXIT_CRITICAL()

Posted by pelibz on October 22, 2012
Hello,
I am trying to use the taskENTER_CRITICAL() and taskEXIT_CRITICAL() macros to perform some lines of critical and very time-dependant code inside one task (I have three running in total). It looks working fine but when I try to exit the critical section with taskEXIT_CRITICAL() it always crashes afterwards (HardFault_Handler error).
Please, any idea why happens and how to solve it?? Or what can I do?

Thanks a lot in advance and kind regards,
Peli

RE: Problem with taskEXIT_CRITICAL()

Posted by Richard Damon on October 22, 2012
It would be helpful to know more about how you are using the calls (especially what processor!).

One thing that comes to mind is that these functions can only be used at the "task" level, they can NOT be used inside an ISR, doing so might cause the HardFault.

RE: Problem with taskEXIT_CRITICAL()

Posted by Richard on October 22, 2012
...if it is a Cortex-M processor then the following link may help: http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

Regards.

RE: Problem with taskEXIT_CRITICAL()

Posted by pelibz on October 23, 2012
Hello,
Thanks for the answers. I see I didn't give much information, sorry.
I am using a Cortex-M3 from NXP (LPC1758). I have a function that is called from a task, and inside the function I call taskENTER and taskEXIT_CRITICAL macros, I don't know if I can do that. Like this:

TASK:
void genTcpIpTask(void *pvParameters)
{
for( ;; )
{
IncomingGenericFramesCheck();
}
}

FUNCTION:
void IncomingGenericFramesCheck(void)
{
...
...
taskENTER_CRITICAL();
if (OW_WriteButton() != 0)
trama[5] = 6; // Error de lectura/escritura.
taskEXIT_CRITICAL();
...
...
}

After taskEXIT_CRITICAL is called the Hard_Fault happens on PortPendSVHandler() (apparently).

Thanks for your help!
Peli

RE: Problem with taskEXIT_CRITICAL()

Posted by Richard on October 23, 2012
There is nothing wrong with your code, from what you have posted, assuming OW_WriteButton() is not itself using FreeRTOS API functions (which should not be called from a critical section). I suspect the problem will lies elsewhere. Have you taken note of the points here:

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

Regards.

RE: Problem with taskEXIT_CRITICAL()

Posted by pelibz on October 23, 2012
Hello Richard,
I checked the FAQ and I don't see anything related. Actually my application runs fine, but it crashes in the very few cases I call taskENTER_CRITICAL() / taskEXIT_CRITICAL(). Normally it has three tasks running fine, performing some communications via Ethernet and UART1, checking some ports, switching leds, etc.
As said, in really few times I have to call to "OW_WriteButton()" function, that writes into a iButton from Dallas connected via One-Wire interface. This operation is very time dependant, that's why I want to make it in a critical section.
Inside "OW_WriteButton" I don't use any FreeRTOS function, I just start the Timer1, write iButton and disable Timer1. This function takes some time, maybe too much and it is affecting somehow.

When back from OW_WriteButton I call to taskEXIT_CRITICAL() and after a short time I get the Hard_Fault. On that point Debugger gives this info (I don't know if it helps):
6 HasdFault_Handler() cr_startup_lpc17.c: 298 0x00000164
5 () 0xfffffff1
4 xPortPendSVHandler() port.c: 237 0x0000a1a2
3 () 0xfffffffd
2 0x10007ef0
1 0x100011cc

Thanks and kind regards,
Peli

RE: Problem with taskEXIT_CRITICAL()

Posted by pelibz on October 25, 2012
Hello,
Richard is right, my problem happens due to other reason although taskEXIT_CRITICAL makes it show later... If I remove taskENTER / taskEXIT the problem happens anyway.
I reduced my function to this:

uint8_t OW_WriteButton()
{
uint8_t result;

TicksOW=0;
while(TicksOW<=G){} // G useg wait
outp(0x00); // Drives DQ low

TicksOW=0;
while(TicksOW<=H){} // H useg wait
outp(0x01);

TicksOW=0;
while(TicksOW<=I){} // I useg wait
result = inp() & 0x01;

TicksOW=0;
while(TicksOW<=J){} //J useg wait

return result; // Return sample presence pulse result
}

Where TicksOW is defined in a timer.c class and counts 1usg ticks. As you can see there are some waits done with while loops. "inp()" and "outp()" just read/write on one pin.
I cannot see the exact point causing the Hard_Fault, but it is inside this function.

Any idea please???

Thanks,
Peli

RE: Problem with taskEXIT_CRITICAL()

Posted by Dave on October 25, 2012
There is nothing in that file that looks suspicious at all. Have you tried it with the inp() and outp() commented out?

RE: Problem with taskEXIT_CRITICAL()

Posted by Jerry Durand on October 25, 2012
I presume you're not having a stack overflow causing this? I didn't see that mentioned so I thought I'd mention it.

RE: Problem with taskEXIT_CRITICAL()

Posted by pelibz on October 25, 2012
It was indeed an stack overflow..... I increased the task stack size and it is apparently working fine now.

Thanks a lot for your help!!

RE: Problem with taskEXIT_CRITICAL()

Posted by MEdwards on October 25, 2012
I recommend always having stack overflow detection turned on during development
http://www.freertos.org/Stacks-and-stack-overflow-checking.html


[ 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