Quality RTOS & Embedded Software

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


Variable Defined In main() Not Accessible By Any Task

Posted by gbmhunter on July 19, 2014

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

Posted by davedoors on July 19, 2014

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

Posted by gbmhunter on July 19, 2014

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.

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists