Page 1 of 1
Overriding _unhandled_exception doesn't work
Posted: Thu May 06, 2021 7:03 pm
by szekelyisz
Hi,
I want to override the default exception handler. I see it's a weak symbol so all it should take is to create a function with the same name and signature, right? So I created a file called handlers.c with the following content:
Code: Select all
#include <stdbool.h>
void _unhandled_exception(void) {
while (true) {
}
}
I made sure it's compiled and linked. Yet the weak version is called. Any ideas what's wrong?
Thanks!
Re: Overriding _unhandled_exception doesn't work
Posted: Thu May 06, 2021 7:24 pm
by Giovanni
Hi,
You may look for the symbol in the .map file and see what happened.
Giovanni
Re: Overriding _unhandled_exception doesn't work
Posted: Thu May 06, 2021 11:28 pm
by szekelyisz
Thanks @Giovanni. I checked the map file, and my symbol appears under "Discarded Input Sections". I guess the linker dumps it before it has a chance to override the weak version. But I was unable to keep it in even by marking it with [font=Courier New]__attribute__((used))[/font].
There are two more references to this symbol, one under "Cross Reference Table" that only tells that it's defined in my source file, and under "Linker script and memory map" on the top of all exception vectors from vectors.o, so it's the weak version.
Re: Overriding _unhandled_exception doesn't work
Posted: Thu May 06, 2021 11:53 pm
by szekelyisz
Here's my linker command:
Code: Select all
arm-none-eabi-g++ <all object files> -mcpu=cortex-m4 -O0 -ggdb3 -fomit-frame-pointer -falign-functions=16 -Wall -ffunction-sections -fdata-sections -fno-common -nostartfiles -Lboard/ -Wl,-Map=build/firmware.map,--cref,--no-warn-mismatch,--library-path=ChibiOS/os/common/startup/ARMCMx/compilers/GCC/ld,--script=board/STM32F427xG_boot_app.ld,--gc-sections,-print-memory-usage,--defsym=__process_stack_size__=0x1000,--defsym=__main_stack_size__=0x400 -mno-thumb-interwork -o build/firmware.elf
I don't see anything wrong with it.
Re: Overriding _unhandled_exception doesn't work
Posted: Fri May 07, 2021 6:01 am
by Giovanni
Hi,
I tried to add that code to a main.c of an existing demo and it is linked correctly, no need to put the "used" attribute.
Which compiler are you using?
Giovanni
Re: Overriding _unhandled_exception doesn't work
Posted: Fri May 07, 2021 1:00 pm
by szekelyisz
I'm using the most recent version of GCC included with ChibiStudio:
Code: Select all
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
I tried it with 10-2020-q4-major, but got the same results.
Re: Overriding _unhandled_exception doesn't work
Posted: Fri May 07, 2021 1:45 pm
by Giovanni
Could you try putting it in main.c ?
Giovanni
Re: Overriding _unhandled_exception doesn't work
Posted: Fri May 07, 2021 7:49 pm
by szekelyisz
Actually I have a main.cpp. I tried putting it there making sure it has C-style linkage, but that didn't help, either.
Do you think it has something to do with messing around with the vector table? I partitioned my flash, the first 128kB is for the bootloader, the main app starts after that. So for the main app I moved my vectors 128kB into the flash by defining CORTEX_VTOR_INIT to 0x00020000U in my chconf.h. I also recompiled and flashed my bootloader with the overridden handler, but no luck.
Re: Overriding _unhandled_exception doesn't work
Posted: Fri May 07, 2021 8:51 pm
by Giovanni
I don't know if it is the moved vectors table, you have a customized setup so you should look into differences.
Giovanni