Quality RTOS & Embedded Software

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


Loading

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