cancel
Showing results for 
Search instead for 
Did you mean: 

Mixed Thumb and ARM modes in .init section hard fault

frackers
Senior
Posted on May 23, 2016 at 01:07

I have a 5 liner 'c' code to copy a module into ccmram which I put into the .init section which works fine. However, immediately after this function, libc_array_init() is called which results in a hard fault. I think this is due to my code being in thumb mode and the libc code is in arm mode and it isn't switching modes correctly. I want to avoid changes to the startup_smtxxx.s assembler module (reduced maintenance) and my stm32f303 gcc doesn't seem to support the __attribute__((target(''arm''))) which might force my code into arm mode.

I've hacked it for now into the .fini section which works but I'd like to find a proper solution.

#.init #thumb-mode #arm-mode
3 REPLIES 3
Posted on May 23, 2016 at 02:17

The Cortex-Mx parts don't support 32-bit ARM code, at all.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frackers
Senior
Posted on May 23, 2016 at 02:44

Any ideas on what might be causing the Hard Fault if it is not erroneous arm code in libc?

The STM32f303 I'm using has ccmram on the I & D buses which is where I'm copying my flash programming code to but at this point I'm only copying the code, not executing it.

When I do come to execute it I get a similar hard fault but that appears to be my copy code is picking up a bad pointer (the default ST supplied LD script uses _siccmram as the start of code to be copied to ccmram). Documentation is sparse to say the least in this area :(

Posted on May 23, 2016 at 03:01

The Hard Fault mechanism should point you to exactly where the code is faulting, the processor registers and stacked state should be available for analysis.

When jumping to code, the address must be ODD

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..