Stack size and overflows

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

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm
Location: Finland

Stack size and overflows

Postby kulve » Wed Feb 08, 2012 4:35 pm

Hi

I bumped into stack overflow in one of my threads. I increase the WORKING_AREA to 256 and it complained about another thread (I have two of them currently). I increased that one as well and now I get:

Code: Select all

#0  port_halt () at ChibiOS/os/ports/GCC/ARMCMx/chcore.c:43
#1  0x08000742 in chDbgPanic (msg=0x8003c34 "stack overflow") at ChibiOS/os/kernel/src/chdebug.c:267
#2  0x08000bcc in chSchDoReschedule () at ChibiOS/os/kernel/src/chschd.c:302
#3  0x08000404 in _port_switch_from_isr () at ChibiOS/os/ports/GCC/ARMCMx/chcore_v7m.c:225
Backtrace stopped: frame did not save the PC
(gdb)


I'm using f205 and -fno-omit-frame-pointer as I've understood -fomit-frame-pointer is bad on ARM for getting proper back traces.

So, what should I now increase? __main_stack_size__ and/or __process_stack_size__? If I touch those should I also change something else or is everything calculated accordingly automatically?

Thank you.

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: Stack size and overflows

Postby Giovanni » Wed Feb 08, 2012 4:44 pm

Hi,

Are you compiling with -O0? if so try increasing PORT_INT_REQUIRED_STACK to 32 or 48. Compiling without optimizations makes the generated code use a lot more of space and it can make the idle thread overflow.

(you may override the default setting by adding it to chconf.h)

Giovanni

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm
Location: Finland

Re: Stack size and overflows

Postby kulve » Wed Feb 08, 2012 7:17 pm

Yes, with -O0 for now for debugging purposes.

I increased the PORT_INT_REQUIRED_STACK to 32 and now my led blinks again (i.e. e.g. adcConvert returns normally) :)

Thanks a lot again.

rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am
Location: Austria

Re: Stack size and overflows

Postby rubenswerk » Mon Jul 09, 2012 2:25 pm

Hello,

I'd like to change my project's stack configuration, but concerning the main stack und interrupt stack, I don't know how to do it. Is the main stack the region which is defined as stack area in the linker script, or are all stacks put into that area?
The article about stack usage points to the ChibiOS port documentation, but I couldn't find it. I'm using STM32F4, and I even don't know if this thing has a dedicated interrupt stack.
Giovanni, could you please post a link to the documentation of the port-dependent stack configuration?

Thanks, RuWe

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: Stack size and overflows

Postby Giovanni » Mon Jul 09, 2012 6:12 pm

Hi,

The interrupts stack and C-runtime stack (main() function) are out of the OS control, those are handled by the startup files and configured in the .ld file:

__main_stack_size__ is the size of INTERRUPTS stack
__process_stack_size__ is the stack of the C-runtime, in ChibiOS the "main" thread uses the C-runtime stack.

If you need to customize those values the best way is to copy the .ld file locally in your project, customize it and then make the Makefile point to the local copy.

Giovanni

rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am
Location: Austria

Re: Stack size and overflows

Postby rubenswerk » Wed Jul 11, 2012 9:54 am

Thank you Giovanni, this helped me to same some RAM.

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm
Location: Finland

Re: Stack size and overflows

Postby kulve » Tue Jan 01, 2013 6:46 pm

I'm getting the following panic:

(gdb) bt
#0 port_halt () at ChibiOS/os/ports/GCC/ARMCMx/chcore.c:43
#1 0x08000962 in chDbgPanic (msg=0x8007f94 "stack overflow") at ChibiOS/os/kernel/src/chdebug.c:267
#2 0x08000ecc in chSchDoRescheduleAhead () at ChibiOS/os/kernel/src/chschd.c:340
#3 0x08000dd8 in chSchRescheduleS () at ChibiOS/os/kernel/src/chschd.c:251
#4 0x08007868 in sc_cmd_push_byte (byte=112 'p') at src/sc_cmd.c:101
#5 0x080074ec in rxchar (c=112) at src/sc_uart.c:420
#6 0x0800748a in rx1char_cb (uartp=0x2000193c, c=112) at src/sc_uart.c:379
#7 0x080065bc in uart_lld_serve_rx_end_irq (uartp=0x2000193c, flags=32)
at ChibiOS/os/hal/platforms/STM32/USARTv1/uart_lld.c:229
#8 0x08003882 in Vector150 () at ChibiOS/os/hal/platforms/STM32F2xx/stm32_dma.c:374
#9 <signal handler called>
#10 0x55555554 in ?? ()
#11 0x55555554 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)


I do have quite an old version of ChibiOS currently but I doubt it's related to this problem.

I've tried to increase PORT_INT_REQUIRED_STACK to 128 and increasing __main_stack_size__ and __process_stack_size__ from 0x400 to 0x800 but I'm still getting the same panic. Any suggestions?

Thanks.

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: Stack size and overflows

Postby Giovanni » Tue Jan 01, 2013 7:50 pm

Use the ChibiOS debug plugin for Eclipse, it should tell you the actual stack usage for all threads.

Giovanni

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm
Location: Finland

Re: Stack size and overflows

Postby kulve » Tue Jan 01, 2013 9:37 pm

Giovanni wrote:Use the ChibiOS debug plugin for Eclipse, it should tell you the actual stack usage for all threads.


Never used Eclipse before but I guess I'll try it out.

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 744 times
Been thanked: 620 times
Contact:

Re: Stack size and overflows

Postby Giovanni » Tue Jan 01, 2013 9:40 pm

You could download ChibiStudio for a quick test, everything is already configured.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 5 guests