Page 1 of 1

Heap overwriting

Posted: Sat Oct 15, 2011 8:13 pm
by diurpaneus
Hi,

I have a problem. It seems the function _port_switch_from_isr in file chcore_v7m.c is overwriting one of my variables. The overwriting happens when this instruction executes: asm volatile ("svc #0"); At some point the stack pointer has the value: 0x20001b38 and when the above instruction executes it overwrites the address 0x20001b2C which is a member my own struct starting at 0x20001b28. According to the map file:

Code: Select all

       0x20001b28                xpmHeader
                0x20001b30                . = ALIGN (0x4)
 *fill*         0x20001b2e        0x2 00
                0x20001b30                _bss_end = .
                0x20001b30                PROVIDE (end, .)
                0x20001b30                _end = .
                0x20001b30                __heap_base__ = _end
                0x20001800                __heap_end__ = (__ram_end__ - __stacks_total_size__)


I'm using ChibiOS 2.2.6 and I have the STM32F100RBT6B.
Can somebody help me with this?

Re: Heap overwriting

Posted: Sat Oct 15, 2011 8:24 pm
by Giovanni
Hi,

Do you have threads created using chThdCreatFromHeap()? if so it could be a stack overflow, try increasing the stack size.

You may also enable the stack check option in chconf.h.

Giovanni

Re: Heap overwriting

Posted: Sat Oct 15, 2011 8:26 pm
by Giovanni
BTW, there is something strange in that map file, the heap end address is lower than the heap start. You should reduce the stack allocated to the main and process stacks in ch.ld.

Apparently your application uses much RAM.

Giovanni

Re: Heap overwriting

Posted: Sun Oct 16, 2011 2:55 pm
by diurpaneus
Hi,
Thanks for the quick reply.Indeed I do use alot of RAM. Can I somehow force some variables to remain in flash so as not to occupy the RAM?

Re: Heap overwriting

Posted: Sun Oct 16, 2011 3:31 pm
by DrunkenDonkey
static const int var=15; will be quite steady in the flash, if you have some tables and stuff you only read, you can happily put them to the flash.

Re: Heap overwriting

Posted: Sun Oct 16, 2011 4:02 pm
by Giovanni
As DrunkenDonkey suggested, use the const qualifier.

Giovanni

Re: Heap overwriting

Posted: Sun Oct 16, 2011 4:36 pm
by diurpaneus
Thanks guys. That solved the problem :).