I’m using evk1100 rev C, AVR studio 2.1, mkII environment to develop code which uses freertos and lwIP etc. I have configured the external SDRAM as a heap by using avr32elf_uc3a0512.x linker script (attached), which I have modified only by changing heap start and end addresses. Also, I have added sdram initialization in _init_startup function. SDRAM works fine. Otherwise I’m using pretty much the set up provided by software framework example.
Now, I have worked on integrating a module (zlib) in my application. First, I compiled it in separate simple project without freertos, with sdram as a heap. It works fine.
When I take the same module codes in my freertos based application and try to test it in a similar way in a simple task, it ends up with a Data Address Read exception while excecuting zlib code. The assembly code that causes the exception is
The r8 contains address of flash or sdram (0x8001da77, 0xd673da77), which varies because of unknown reason, and the code tries to read a value from a static const vector. This happens without optimization. When I modify the particular code line so that it uses more local variables, the compiled machine code changes and it works, which is, of course, not the solution. Anyway, the code itself is not the reason. That is, when I set -O1 on, a Bus Error Data Fetch exception occurs - not in the same code line but later.
I have seen couple of post with similar kind of issue, but they give no solution: