Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse IDE for STM32, Hardfault_Handler due to failed vector table fetch
Eclipse IDE for STM32, Hardfault_Handler due to failed vector table fetch [message #1821653] Tue, 18 February 2020 08:33 Go to next message
Steliyan Vasilev is currently offline Steliyan VasilevFriend
Messages: 2
Registered: February 2020
Junior Member
First I want to say that I am a newbie in this field. I am trying to upload and debug a code on a custom-made board based on STM32F303CB chip through a NUCLEO-F446RE board. I am using Eclipse IDE (2019-12), a GNU toolchain and a SEGGER J-Link debugging software.

The code builds successfully with no errors, anyway when starting to debug, a HardFault_handler is called. The code was not written by me. I doubt that the problem is in the code itself (it builds) and rather think that some setting of the tools is not right (correct me if I am wrong). I also tried the same procedure on several boards, so I would exclude a hardware issue as well.

The debugger hangs when initializing the USB in the function MX_USB_Init(), leading to a HardFault_handler. When debugging in single-step mode, most funcitons within MX_USB_init() execute successfully, except USBD_Start(&hUsbDeviceFS). When stepping into USBD_Start(...), it arrives in the while(1) loop of the HardFault_handler. When debugging in resume mode (no single step), debugger would also hang at previous functions which work properly in single-step mode such as HAL_PCD_Init(&hpcd_USB_FS), HAL_PCDEx_PMAConfig, USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC), USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) and again USBD_Start(&hUsbDeviceFS).

EDIT: I was able to refine the issue but not resolve it yet. I commented out the empty Hardfault_Handler() function in stm32f3xx_it.c generated by CubeMX and caused the calling of the default CMSIS Hardfault_Handler() function in exception_handlers.c. Doing that in the debug console I get the values of several registers:

 SEGGER J-Link GDB Server V6.60f - Terminal output channel
[HardFault]
Stack frame:
 R0 =  00000000
 R1 =  0000BF00
 R2 =  40005C00
 R3 =  00000001
 R12 = 0000E000
 LR =  FFFFFFF9
 PC =  F3EF8008
 PSR = 6000005B
FSR/FAR:
 CFSR =  00000001
 HFSR =  40000000
 DFSR =  00000000
 AFSR =  00000000
Misc
 LR/EXC_RETURN= FFFFFFF1
Connection closed by the GDB server.


Then in the book "Mastering STM32" I read about the following meanings of the above register values:

LR = FFFF FFF9 - CPU has been running "regular code" (CPU was in thread mode) when the Hard Fault exception was called. It was not an interrupt. The stack used was MSP, FPU Unit disabled.

HFSR = 4000 0000 - the VECTBL bit is set which indicates that the Hard Fault is caused by failed vector table fetch. The explanation is as follows:

"Bus error received during a vector table fetch. This happens because the vector table is invalid (the most of the times we forgot to include the assembly file provided by ST or we forgot to modify its extension from lower .s to capital .S)."

In my project there is no .s or .S file and no function is referring to such a file. This makes me think that maybe the programmer is trying to write to a wrong address in the memory because there is no proper startup file. Does that make sense for you?

Thanks in advance!
Re: Eclipse IDE for STM32, Hardfault_Handler due to failed vector table fetch [message #1822159 is a reply to message #1821653] Fri, 28 February 2020 09:34 Go to previous message
Steliyan Vasilev is currently offline Steliyan VasilevFriend
Messages: 2
Registered: February 2020
Junior Member
SOLUTION:

It appeared that really the startup_stm32fXXXxX.S file was missing. I solved the problem by creating a new dummy project for my MCU using CubeMX and generating the code for Other IDEs (GPDSC). Then I copied the generated .s file (in my case startup_stm32f303xc.s) to the system->src->cmsis folder of the original project and deleted the files system_DEVICE.c and vectors_DEVICE.c. I changed the file extension from small .s to capital .S, compiled the project and then I was able to flash and debug the microcontroller successfully.

Thank you!
Previous Topic:Run error caused by mismatching brackets
Next Topic:IDE Exception Handler (Java heap space)
Goto Forum:
  


Current Time: Thu Apr 25 05:21:32 GMT 2024

Powered by FUDForum. Page generated in 0.03532 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top