Quality RTOS & Embedded Software

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


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