Page 1 of 2
C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Thu Jun 07, 2018 8:10 pm
by dflogeras
Hi, does anyone know why this might be:
If I compile a simple C++ test program (say RT-STM32F407-DISCOVERY-G++ demo), and make sure to remove "-fno-exceptions" and place the following code in main:
Code: Select all
try {
throw 1;
}
catch( ... ) {
// all ok
}
It works as expected. That is, the exception is thrown, caught, and then main gets on with its progress.
Now the clincher. If I do the same thing but target my STM32F7 (starting with RT-STM32F769I-DISCOVERY demo) and add C++ support with exceptions, the same code as above doesn't get into the catch() block, and treats it as an unhandled exception (eventually ending up in the std abort handler and thus chSysHalt() infinite loop).
I've tried this on ChibiOS-18.2.1, with the ARM GCC7-2017-q4-major toolchain.
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Thu Jun 07, 2018 8:19 pm
by Giovanni
It could be an error in the linker script, you should verify the map file and compare with the one of F4.
Giovanni
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Thu Jun 07, 2018 9:03 pm
by dflogeras
Giovanni wrote:It could be an error in the linker script, you should verify the map file and compare with the one of F4.
Giovanni
Hi,
After inspecting both map files, in particular the exception handling functions (__cxa_*), I noted that in the F4 they were all in 0x8000000 flash, while on the F7 they were in the 0x200000 (F7 specific ITCM flash).
If I modify the F7's linker file and change the sections that were in flash1 to flash0, the exception handling works as expected. I'm sure this isn't the solution, but it is definitely part of the cause.
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Thu Jun 07, 2018 9:15 pm
by Giovanni
Moving in bug reports, I need to understand the issue.
Giovanni
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Thu Jun 07, 2018 10:10 pm
by dflogeras
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Fri Jun 08, 2018 11:24 am
by dflogeras
Another tidbit, in case it helps you later. Only one of the changes was required in STM32F76xxI.ld to fix the problem I am seeing. Change:
REGION_ALIAS("VARIOUS_FLASH", flash1);
to flash0.
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Fri Jun 15, 2018 10:30 am
by Giovanni
Would be possible to setup a very simple example project for this?
Giovanni
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Fri Jun 15, 2018 7:07 pm
by dflogeras
Absolutely,
This started as a copy of testhal/STM32/STM32F7xx/SPI from ChibiOS_18.2.1
I converted it to c++, then simplified main() to the most basic to show the problem. The way I uploaded it, it uses the default linker script, but I've also included a modified one to show how it changes the outcome (I wont say fixes it since it might just be a band-aid). Just uncomment the linker-script line I left in the Makefile to use the modified one.
I ran it on a F769NI but the original SPI demo was meant to run on a F746 and should be able to try it on that depending on which hardware you have in your arsenal.
I used the gcc-arm-none-eabi-7-2017-q4-major compiler to test with, if you want the exact same environment
Thanks,
Dave
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Mon Dec 31, 2018 11:10 am
by Giovanni
bump
Re: C++ exceptions in cortex-m7 vs. cortex-m4
Posted: Sun Nov 10, 2019 10:29 am
by Giovanni
Hi,
Scatter files received changes for a problem that could be the root cause for this. Would be possible to re-check this using the latest version?
Giovanni