cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 Hard Fault during startup

NIX AIR SOLUTIONS
Associate II

Hello, 

I realised an stm32l476 board. After receiving the board, we tested all the connection power.. All is good.

To start with the coding I added a simple code to toggle pins to check the functionality. The code install successfully on the board. However, we going to run mode, the stm32 isn't toggling the pins. 

I'm trying to debug the stm using stm32CubeIDE, I'm having a Hard Fault at the HAL_Init(). 

NIXAIRSOLUTIONS_0-1700097730756.pngNIXAIRSOLUTIONS_1-1700097765714.png

 

This might be the reason that the stm32 isn't working in run mode? If so, can you help? 

 

Thank you, 

Omar Abdul Aziz

4 REPLIES 4
Bob S
Principal

Well, the SP and PC values are BOTH not valid (well, SP maybe if RAM is mapped to address 0, I don't recall if that can happen on the L4xx).

You have the source code.  Use the debugger, step through the HAL_Init() and see where/why it fails.  Make sure the VTOR register is pointing to the actual vector table (look in system_stm32l4xx.c).

 

NIX AIR SOLUTIONS
Associate II

I apologies for the late reply. 

The code isn't stucking at the HAL_Init() anymore. I did the debug with breakpoint, the code fails at the SystemClock_Config() and it's pointing to the void HardFault_Handler(void) and stucking in the while(1). 

However, the error in the fault analkyser is the same (MPS, SP values). Noting that I don't have error in the clock configuration.  

For the VTOR register, it's set in the void SystemInit(void).

NIXAIRSOLUTIONS_0-1701142563580.png

An error in the system clock will cause the an error in the stack pointer values? 

 

Bob S
Principal

Did you single-step through the SystemInit() code to verify that the VTOR gets set?  Because it looks like your editor is showing you that the VTOR code is DISABLED (i.e. USER_VECT_TAB_ADDRESS is not defined).  Notice how the VTOR code is grayed out, while the FPU code below is not.

[EDIT] The fact that the fault handler is triggered from a different place may just be a timing issue before the first interrupt happens.

NIX AIR SOLUTIONS
Associate II

I just created a new project proceeding by the configuration point by point. The error was from the clock configuration and it works now.

Thanks sir.