Heap overwriting

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
diurpaneus
Posts: 7
Joined: Thu Sep 15, 2011 3:37 pm

Heap overwriting

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Heap overwriting

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Heap overwriting

Post 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
diurpaneus
Posts: 7
Joined: Thu Sep 15, 2011 3:37 pm

Re: Heap overwriting

Post 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?
DrunkenDonkey
Posts: 124
Joined: Sun Aug 28, 2011 5:16 pm

Re: Heap overwriting

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Heap overwriting

Post by Giovanni »

As DrunkenDonkey suggested, use the const qualifier.

Giovanni
diurpaneus
Posts: 7
Joined: Thu Sep 15, 2011 3:37 pm

Re: Heap overwriting

Post by diurpaneus »

Thanks guys. That solved the problem :).
Post Reply