[En-Nut-Discussion] Large auto variable called from main thread crashed programm

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Fri Jan 9 14:33:42 CET 2015


>>>>> "Philipp" == Philipp Burch <phip at hb9etc.ch> writes:


    Philipp> Well, the most obvious thing would be an overflow of the main
    Philipp> thread's stack. Have you enabled the stack checking code to see
    Philipp> how much is actually used when you run it with the smaller
    Philipp> variable?

    Philipp> Some other thing that comes to my mind is a stack-hungry
    Philipp> interrupt service routine. I'm still not sure which stack is
    Philipp> actually used for ISRs, but it may be the one used for the
    Philipp> currently executing thread. So if you have complex ISRs, that
    Philipp> may cause some more random crashes.

    Philipp> Since the STM32 is also a Cortex-M3/4 processor, you could
    Philipp> probably also use the post-mortem stack checking code. It is an
    Philipp> extension to Oles Cortex debug macro and can be found in r5891
    Philipp> in the devnut_tiva branch.

Reading enmem21e.pdf and arch/cm3/os/nutinit.c

#ifndef NUT_THREAD_MAINSTACK
#define NUT_THREAD_MAINSTACK    1024
#endif

make things clear: Main stack is only for idle thread, main program stack as
thread stack is allocated in pre-defined size from heap.

To cite enmen21e:

> To avoid wasting stack space, the application should...
>        ...
>        ...not declare large non-static arrays or structures within functions.

Thanks
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------


More information about the En-Nut-Discussion mailing list