Skip to main content
frackers
Senior
May 22, 2016
Question

Mixed Thumb and ARM modes in .init section hard fault

  • May 22, 2016
  • 3 replies
  • 756 views
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
    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    May 23, 2016
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    frackers
    frackersAuthor
    Senior
    May 23, 2016
    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 :(

    Tesla DeLorean
    Guru
    May 23, 2016
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..