# problem with GCC ARM\_CM3 port

**URL:** <https://forums.freertos.org/t/problem-with-gcc-arm-cm3-port/2883>\
**Category:** Kernel\
**Created:** [December 7, 2015, 4:35am UTC](https://forums.freertos.org/t/problem-with-gcc-arm-cm3-port/2883 "2015-12-07T04:35:36Z")\
**Posts on this page:** 2\
**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:** [December 7, 2015, 4:35am UTC](https://forums.freertos.org/t/problem-with-gcc-arm-cm3-port/2883/1 "2015-12-07T04:35:36Z")

</div>

**[gbiagioni](https://sourceforge.net/u/gbiagioni/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/831b315d/#1c0b):

The implementation of prvPortStartFirstTask( void ) in FreeRTOS/Source/portable/GCC/ARM\_CM3/port.c begins with the following assembly instructions

" ldr r0, =0xE000ED08 \n" /\* Use the NVIC offset register to locate the stack. _/  
" ldr r0, [r0] \n"  
" ldr r0, [r0] \n"  
" msr msp, r0 \n" /_ Set the msp back to the start of the stack. \*/

This strips the stack back to the start of stack as defined in the interrupt vector table. This has the undesirable effect of losing automatic variables that were on the stack at the time the first task is started. This is bad. For example, if tasks are created before scheduler startup and are passed addresses of automatic variables, they will likely see clobbered data.

Is there some reason that the stack is stripped back in this way?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 7, 2015, 9:12am UTC](https://forums.freertos.org/t/problem-with-gcc-arm-cm3-port/2883/2 "2015-12-07T09:12:01Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/831b315d/#3636):

See the following discussion:  
[http://www.freertos.org/FreeRTOS\_Support\_Forum\_Archive/January\_2015/freertos\_Main\_stack\_pointer\_reset\_when\_starting\_the\_scheduler\_e5a776c1j.html](http://www.freertos.org/FreeRTOS_Support_Forum_Archive/January_2015/freertos_Main_stack_pointer_reset_when_starting_the_scheduler_e5a776c1j.html)

I think strictly speaking this is against the C standard - however considered desirable when using very small microcontrollers. I think the first Cortex-M port was done on a device with 2K of RAM.
