# AT91SAM7S64 IAR port

**URL:** <https://forums.freertos.org/t/at91sam7s64-iar-port/5206>\
**Category:** Kernel\
**Created:** [September 20, 2005, 7:33am UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206 "2005-09-20T07:33:33Z")\
**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:** [September 20, 2005, 7:33am UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206/1 "2005-09-20T07:33:33Z")

</div>

**[jra01](https://sourceforge.net/u/jra01/)** wrote on [Tuesday, September 20, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/e699c82e/#4d76):

I discovered a problem with crashing system. The cause showed up to be that IAR expects stack to be initiated to 0, but freeRTOS initates to 01010101, 02020202 …

Therefore I have made a change to port.c, in "pxPortInitialiseStack":  
—  
&nbsp;&nbsp;&nbsp; \*pxTopOfStack = ( portSTACK\_TYPE ) 0xaaaaaaaa;&nbsp;&nbsp;&nbsp; /\* R14 \*/  
&nbsp;&nbsp;&nbsp; pxTopOfStack–;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; \*pxTopOfStack = ( portSTACK\_TYPE ) pxOriginalTOS; /\* Stack used when task starts goes in R13. \*/  
&nbsp;&nbsp;&nbsp; pxTopOfStack–;  
&nbsp;&nbsp;&nbsp; for (i = 0; i \< 12; ++i) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \*pxTopOfStack = ( portSTACK\_TYPE ) 0x0;&nbsp;&nbsp;&nbsp; /\* R12…R1 \*/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pxTopOfStack–;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; }

—

After that it works.

Regards

Jokke

---

<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:** [September 20, 2005, 7:44am UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206/2 "2005-09-20T07:44:10Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 20, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/e699c82e/#4d76/3120):

This is definitely not the case.&nbsp; When a task starts it does not make any assumptions as to the stack or register states.

I suspect you are calling main() in the wrong processor mode.&nbsp; main() must be called in supervisor mode.&nbsp; Are you using the startup code that came with the demo project?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 20, 2005, 8:21am UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206/3 "2005-09-20T08:21:48Z")

</div>

**[jra01](https://sourceforge.net/u/jra01/)** wrote on [Tuesday, September 20, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/e699c82e/#4d76/290d):

This has nothing to do with main. In a normal task I discovered (looking at the assembler listing) that the compiler places a read in a vector, using an index that is in some cases still not initialized. This works fine as long as the index is 0 until it is used, but I got problems with reads out of defined memory, since, in this case, R5 was 0x05050505, as is initialised in port.c.  
Maybe this is a compiler error, but my guess was that they made this assumption.  
The code is a state machine, and it might not be obvious enough for the compiler that it starts in a state where the index is set, before moving to the state where it is used. On the other hand I do not get any warning of "used before set"(maybe IAR does not give such warnings?).  
I am using the startup from the demo project, and I made a lot of versions of the software before this came up.  
I guess I will have to send you the code and the assembler listing before we reach consensus on this…  
Regards  
Jokke

---

<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:** [September 20, 2005, 8:30am UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206/4 "2005-09-20T08:30:49Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 20, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/e699c82e/#4d76/290d/e83d):

If you could send me the smallest project possible that exhibits this behaviour I would be very grateful!&nbsp; Send it to the email address from the FreeRTOS WEB site Contacts page (r dot barry at fr…org).&nbsp; Thanks.

---

<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:** [September 20, 2005, 12:50pm UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206/5 "2005-09-20T12:50:11Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, September 20, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/e699c82e/#4d76/290d/e83d/eb1c):

From the received code it looks as if there could be a compiler error - I will post the results but might take a while.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 26, 2005, 11:15am UTC](https://forums.freertos.org/t/at91sam7s64-iar-port/5206/6 "2005-09-26T11:15:36Z")

</div>

**[jra01](https://sourceforge.net/u/jra01/)** wrote on [Monday, September 26, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/e699c82e/#4d76/0841):

I upgraded the IAR tools to lates version (4.30), and there the compiler bug seems to be solved!  
No problem with freeRTOS!  
SOLVED
