Skip to main content
N Sornakumar
Associate III
August 30, 2021
Solved

Hardfault on STM32F746BGT6 startup, __libc_init_array

I'm trying to get a STM32Cube project compiled using arm-none-eabi-gcc and a Makefile. The FW builds without problems.but when I boot the MCU i get stuck in Hard Fault. Any ideas what could be wrong?

Reset_Handler: 
 ldr sp, =_estack /* set stack pointer */
 
/* Copy the data segment initializers from flash to SRAM */ 
 ldr r0, =_sdata
 ldr r1, =_edata
 ldr r2, =_sidata
 movs r3, #0
 b LoopCopyDataInit
 
CopyDataInit:
 ldr r4, [r2, r3]
 str r4, [r0, r3]
 adds r3, r3, #4
 
LoopCopyDataInit:
 adds r4, r0, r3
 cmp r4, r1
 bcc CopyDataInit
 
/* Zero fill the bss segment. */
 ldr r2, =_sbss
 ldr r4, =_ebss
 movs r3, #0
 b LoopFillZerobss
 
FillZerobss:
 str r3, [r2]
 adds r2, r2, #4
 
LoopFillZerobss:
 cmp r2, r4
 bcc FillZerobss
 
/* Call the clock system initialization function.*/
 bl SystemInit 
/* Call static constructors */
 bl __libc_init_array

This topic has been closed for replies.
N Sornakumar
N SornakumarBest answer
Associate III
August 31, 2021

I am use stlink v3 mini debugger so i am got this error. After i am use stlink v2 debugger, program loaded successfully in my target board without any problem

3 replies

TDK
August 30, 2021

Examine the SCB registers for the reason behind the hard fault.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
August 30, 2021

>>Any ideas what could be wrong?

Your constructors are touching memory that you haven't properly initialized in SystemInit() ?

ie External Memories (peripherals, pins, clocks, etc)

Are you using C++ ? If not then you probably don't need to be calling __libc_init_array

Look at the .MAP, check where the constructors are being placed, and the settings for those sections in the linker script (.LD)

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
N Sornakumar
N SornakumarAuthorBest answer
Associate III
August 31, 2021

I am use stlink v3 mini debugger so i am got this error. After i am use stlink v2 debugger, program loaded successfully in my target board without any problem