Page 2 of 3
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 11:55 am
by steved
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!)
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 12:06 pm
by elagil
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.

Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 12:33 pm
by mikeprotts
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
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 12:46 pm
by elagil
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.
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 12:59 pm
by mikeprotts
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.
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 1:16 pm
by Giovanni
You should check your stacks using the ChibiOS view in ChibiStudio, do you have margins on all of them?
Giovanni
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 1:41 pm
by elagil
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?
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 1:48 pm
by Giovanni
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
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 1:53 pm
by elagil
Ok, I will try. I am on Linux, so I cannot directly use ChibiStudio but have to build it from plugins first.
Re: Unhandled exception - how to debug
Posted: Fri Jul 12, 2019 2:49 pm
by Giovanni
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