Variable Defined In main() Not Accessible By Any Task

I am using the PSoC 5 microcontroller and built a FreeRTOS firmware app based on the associated example. I am having an interesting problem in where any variable I declare in main() is not accessible by a task. That is, I create a variable in main(), and then pass a pointer that points to this variable to the tasks. After calling vTaskStartScheduler(), the tasks then try and read/write to this variable, however it is invalid? I would of thought this would be o.k., since the firmware never exits main(), this variable should be accessible.

Variable Defined In main() Not Accessible By Any Task

PSoC 5 – is that Cortex-M3? On Cortex-M the stack that was used by main is reused as the system stack. Your variable will simple get overwritten each time there is an interrupt. If you make the variable static then it won’t be on the stack and should work, but if you do that then why not just give the variable file scope so declare it outside of main?

Variable Defined In main() Not Accessible By Any Task

Yes, it is the Cortex-M3. Oh thanks for that information! I wasn’t aware the main() stack was shared with the system stack (I will have to look further into what that exactly means). Yes I can make it static or the variable global, which will put it on the heap, and that is what I have been currently doing to fix it. However, I still find this concept odd to grasp, I thought a variable that had been given scope in main() would exist until main() exited, no matter what else happened.