Scientific progress goes "Boink"?

Xilinx SDK: Corrupt Memory when Using xilffs in Interrupt Handler

It happened to me when I wanted to read from SD card while being in an interrupt handler. Whenever I read something from the SD card, the local variables of main() got destroyed.

The root cause: There was a stack overflow of the IRQ Stack which then “leaked” into the User Stack. What I learned was: An ARM CPU has multiple stacks. If an exception is processed, the CPU switches from System and User Mode to IRQ Mode (Click here for a brief explanation). Although I increased the stack size to 32768, the IRQ stack size remained unchanged at 1024 bytes. So, this problem is not specific to the xilffs library. Whenever your interrupt handler uses more than 1024 bytes local variables (accumulated over the whole call depth), you will be in trouble.

The solution: Change the parameter _IRQ_STACK_SIZE in the linker script file (extension: .ld).

  • If you haven’t done already, create a linker script file:
  • Change _IRQ_STACK_SIZE from 1024 to 4096:
  • Be aware that next time you generate a linker script file, this will be overridden. It would be better to define _IRQ_STACK_SIZE outside the linker script file. Looks as if the script will keep whatever _IRQ_STACK_SIZE is set to, so it must be possible to define it outside the linker script file. However, I haven’t figured it out, yet. I tried pre-processor defines as well as environment variables.

Leave a comment