# AVR32 Global Variable Corruption

**URL:** <https://forums.freertos.org/t/avr32-global-variable-corruption/2311>\
**Category:** Kernel\
**Created:** [July 12, 2009, 7:08pm UTC](https://forums.freertos.org/t/avr32-global-variable-corruption/2311 "2009-07-12T19:08:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 12, 2009, 7:08pm UTC](https://forums.freertos.org/t/avr32-global-variable-corruption/2311/1 "2009-07-12T19:08:55Z")

</div>

**[scottfindlay](https://sourceforge.net/u/scottfindlay/)** wrote on [Sunday, July 12, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/6a4994a6/#72c8):

I’m trying to run freeRTOS on an ATMEL AVR32 (UC3 A0512) on the EVK1100 dev board.  
I am having a problem with global variables being overwritten between task calls.  
I took the example and added a global (declared as static volatile) to the top of the main.c file. I then try to copy that to a temp variable in the error check task on each cycle and debug to check its value. It seems to be getting corrupted and I don’t know why. Usually it has the initial value correct but then it is either 1 or changes each cycle.  
Anyone know about a specific AVR32 issue or I’m I just doing something stupid?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 13, 2009, 6:37am UTC](https://forums.freertos.org/t/avr32-global-variable-corruption/2311/2 "2009-07-13T06:37:07Z")

</div>

**[mathias3](https://sourceforge.net/u/mathias3/)** wrote on [Monday, July 13, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/6a4994a6/#72c8/4b9d):

What are you doing with your global variable (e.g. where and how do you read/write it)? What’s its type? Are you sure it gets corrupted ‘between’ task calls? Check the AVR32 Studio help: C/C++ Development User Guide\>Tasks\>Running and debugging projects\>Debugging. Perhaps you could add a watchpoint for your variable that breaks whenever the content has been changed.

---

<div class="post-metadata">

**Author:** ![jwestmoreland](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@jwestmoreland](https://forums.freertos.org/u/jwestmoreland)\
**Post date:** [July 14, 2009, 1:15am UTC](https://forums.freertos.org/t/avr32-global-variable-corruption/2311/3 "2009-07-14T01:15:11Z")

</div>

**[jwestmoreland](https://sourceforge.net/u/jwestmoreland/)** wrote on [Tuesday, July 14, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/6a4994a6/#72c8/1963):

Scott,

You know what they say about globals.

As Mathias suggested above - you should be able to set a breakpoint on writes to the address of the global so the debugger will break - and that way you can look at your stack trace to see what task (and/or function) accessed the variable.

Can you use a semaphore and/or a queue to accomplish the same thing (and a lot safer)?

Regards,  
John
