Unhandled exception - how to debug

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

steved
Posts: 608
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 5 times
Been thanked: 76 times

Re: Unhandled exception - how to debug

Postby steved » Fri Jul 12, 2019 11:55 am

elagil wrote:Since I have all chibiOS debug options enabled, would I not see some debug message? After all dynamic thread and pool element allocations, I use "chDbgAssert" and check for NULL pointers. Stack overflows would also be indicated, as far as I am aware.

Not necessarily - sometimes the exception can happen before you get to the stack checking code.
(And sometimes a stack can temporarily overflow in one thread, and its not until several context switches later that the crash happens!)

elagil
Posts: 61
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 4 times
Been thanked: 5 times

Re: Unhandled exception - how to debug

Postby elagil » Fri Jul 12, 2019 12:06 pm

steved wrote:And sometimes a stack can temporarily overflow in one thread, and its not until several context switches later that the crash happens!


Good to know but that sounds stressful to debug. :?

mikeprotts
Posts: 41
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 4 times
Been thanked: 7 times

Re: Unhandled exception - how to debug

Postby mikeprotts » Fri Jul 12, 2019 12:33 pm

I had problems with interrupt handlers when I hadn't allocated enough to the stack, or when I'd not left enough free core or heap. It took a while for me to realise that the unhandled exception was nothing to do with VectorF8, but somewhere else in the code, in my case often in the network interrupt area.

I've used an STM32F407 (192Kb SRAM) with these allocations:
USE_PROCESS_STACKSIZE = 0x400
USE_EXCEPTIONS_STACKSIZE = 0x800
PORT_IDLE_THREAD_STACK_SIZE=32
PORT_INT_REQUIRED_STACK=256

I am also using almost all the RAM in static variables (buffering to allow for network latency as I'm streaming at about 2Mbps), I try to leave a small margin for safety:
core free: 2288 heap frag: 1 heap free: 112

I can probably reduce the stack allocations, but that's something I'll work on when everything else seems to be stable.

Mike

elagil
Posts: 61
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 4 times
Been thanked: 5 times

Re: Unhandled exception - how to debug

Postby elagil » Fri Jul 12, 2019 12:46 pm

This is interesting, since I also use Ethernet with Lwip a lot. I may move the heap from lwip to external memory with

Code: Select all

#define LWIP_RAM_HEAP_POINTER (void *) SOME_ADDRESS


but I am not sure if this is a good idea. It may be too slow.

Did you finally solve your problem by increasing stack sizes?

By the way, I get "HardFault", when looking into xpsr. In the hard fault status register (HFSR) I can only see that it was a "forced" hard fault.

mikeprotts
Posts: 41
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 4 times
Been thanked: 7 times

Re: Unhandled exception - how to debug

Postby mikeprotts » Fri Jul 12, 2019 12:59 pm

I seem to be ok for now with these settings. My lwipopts.h and lwippools.h are attached. The pool sizes were bigger to start with, but i reduced them based on the usage indicated by lwip stats.
Attachments
lwipopts.zip
(15.94 KiB) Downloaded 5 times

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

Re: Unhandled exception - how to debug

Postby Giovanni » Fri Jul 12, 2019 1:16 pm

You should check your stacks using the ChibiOS view in ChibiStudio, do you have margins on all of them?

Giovanni

elagil
Posts: 61
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 4 times
Been thanked: 5 times

Re: Unhandled exception - how to debug

Postby elagil » Fri Jul 12, 2019 1:41 pm

Actually, I am not currently using ChibiStudio, but VS Code with the so-called "Cortex Debug" plugin. Is there another way to look into the statistics, like a global structure?

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

Re: Unhandled exception - how to debug

Postby Giovanni » Fri Jul 12, 2019 1:48 pm

ChibiStudio includes a plugin that allows to inspect everything in the RT kernel, including stacks usage.

You could give it a try just for this task.

Giovanni

elagil
Posts: 61
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 4 times
Been thanked: 5 times

Re: Unhandled exception - how to debug

Postby elagil » Fri Jul 12, 2019 1:53 pm

Ok, I will try. I am on Linux, so I cannot directly use ChibiStudio but have to build it from plugins first.

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

Re: Unhandled exception - how to debug

Postby Giovanni » Fri Jul 12, 2019 2:49 pm

There is a ChibiStudio for linux archive on SF download area, you may need to change some paths however, it is what I use on my PC.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 6 guests