Quality RTOS & Embedded Software

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




Loading

Global xSemaphoreHandle corrupted

Posted by Fabien on August 8, 2013
Hi all,

I use xSemaphoreHandle as global variable in my program.
Declaration is the next:
xSemaphoreHandle xComSemaphore in main.c
extern xSemaphoreHandle xComSemaphore in all other .c files.

I check its value when I create it: vSemaphoreCreateBinary( xComSemaphore);
But in my interrupts file, when I check its value in next function xSemaphoreGiveFromISR(xComSemaphore, &xHigherPriorityTaskWoken ); I saw that the value was different from the one during creation.

For information, I don't use any Compiler optimization.

I know that xSemaphoreHandle is a pointer to a xQUEUE structure, but I don't understand why this value had change? Is it forbidden to use global variable for xSemaphoreHandle?

Thanks for your help.




RE: Global xSemaphoreHandle corrupted

Posted by Richard on August 8, 2013
“Is it forbidden to use global variable for xSemaphoreHandle?”


It is just a variable, like any other variable. The compiler has no knowledge of the kernel, so there is no way the kernel could impose any restriction on where or how the variable is defined. The rules for defining them are just the same as for defining any other C variable, and your extern declaration should not be a problem.

I assume, as your program links, you have declared the variable at file scope, and not on the stack of a C function (which would be wrong, because when the function returns the stack is removed so the variable no longer exists).

I would guess this is just a simple RAM corruption somewhere, maybe caused by an incorrect linker script, or a stack overflow, or something similar.

Do you have stack overflow checking turned on?

If you have a fancy CPU and debugger then you should be able to set a data watch point on the variable and have the debugger automatically break at the point where the variable is written to. Failing that, simply add the variable to a watch window, then step through the code until you find the value of the variable inexplicably changing to try and determine what is writing over it.

Regards.

RE: Global xSemaphoreHandle corrupted

Posted by Fabien on August 8, 2013
Hi Richard,

One more time, you help me a lot.
I added a data watch point I saw that a I tried to write inside a array smaller than my index and overwrite the semaphore...

Thanks for your feedback.
Fabien


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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