# Cortex-M3 Stack problem using a bootloader

**URL:** <https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875>\
**Category:** Kernel\
**Created:** [April 1, 2008, 10:58pm UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875 "2008-04-01T22:58:28Z")\
**Posts on this page:** 6\
**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:** [April 1, 2008, 10:58pm UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875/1 "2008-04-01T22:58:28Z")

</div>

**[ravaz](https://sourceforge.net/u/ravaz/)** wrote on [Tuesday, April 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/d63631da/#5f75):

I found a problem on the Cortex-M3 port. In the port.c file the MSP (main stack pointer) is initialized assuiming that the vector table is strored at the adress 0x00000000, using a bootloader this is not hte case. For that reason I modified the code as follow:

Line 160:&nbsp;&nbsp; prvSetMSP( \*((unsigned portLONG \*) portNVIC\_VTABLE ) );

The portNVIC\_VTABLE must be defined using:

#define portNVIC\_VTABLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0xE000ED08

Hope can help…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 3, 2008, 9:09am UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875/2 "2008-04-03T09:09:06Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Thursday, April 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/d63631da/#5f75/b3d4):

Very good point. Can we add this to the standard download?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 3, 2008, 11:29am UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875/3 "2008-04-03T11:29:41Z")

</div>

**[ravaz](https://sourceforge.net/u/ravaz/)** wrote on [Thursday, April 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/d63631da/#5f75/2389):

Another correction should be done is the systick timer reload value. To be correct the value should be loaded using:

\*(portNVIC\_SYSTICK\_LOAD) = (configCPU\_CLOCK\_HZ / configTICK\_RATE\_HZ)-1;

regards

Ravaz

---

<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:** [April 3, 2008, 3:11pm UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875/4 "2008-04-03T15:11:13Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, April 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/d63631da/#5f75/2389/c8d7):

I like to make sure I make that mistake over and over again :o)&nbsp; It will be right (for this port at least) in the next version.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 3, 2008, 9:32pm UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875/5 "2008-04-03T21:32:49Z")

</div>

**[ravaz](https://sourceforge.net/u/ravaz/)** wrote on [Thursday, April 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/d63631da/#5f75/03a4):

I would take the chance to thank you for the great job and for the perseverance you have to continously improve it…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 8, 2008, 11:43am UTC](https://forums.freertos.org/t/cortex-m3-stack-problem-using-a-bootloader/4875/6 "2008-04-08T11:43:31Z")

</div>

**[ravaz](https://sourceforge.net/u/ravaz/)** wrote on [Tuesday, April 08, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/d63631da/#5f75/5656):

I did the modification for the version 4.8.0 as follow

void vPortStartFirstTask(void)  
{  
&nbsp;&nbsp;&nbsp; asm volatile(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp; ldr r0, =0xE000ED08&nbsp; \n" /\* Load the NVIC\_TABLE offset address. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp; ldr r0, [r0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n" /\* Get the vector table offset. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp; ldr r0, [r0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n" /\* Get the stack pointer. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp; msr msp, r0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n" /\* Set the msp back to the start of the stack. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp;&nbsp; svc 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n" /\* System call to start first task. \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );  
}

Regards

Ravaz
