Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner