cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault handler infinite loop

Erwan03
Associate III

Hello,

 

I am currently using a Nucleo F446RE board and i am facing problem while trying to read an analog pin using ADC functions. When i start running or debugging the project, i immediately fall down into Hardfault_handler function. I don't know what i exactly did wrong, and don't know how to figure it out...

 

Thanks in advance for help!

 

Please find attached the main file i wrote.

5 REPLIES 5
SofLit
ST Employee

Hello,

At a first glance you declared this table with one element:

uint16_t uiADCRawValueBuffer[1];

  Then you access two elements.

uint16_t uiADCRawValueBuffer[1];

		for (int var = 0; var < 2; ++var) {
			uiADCRawValueBuffer[var] = HAL_ADC_GetValue(&hadc1); // Store converted values
		}
		buffer_throttle = uiADCRawValueBuffer[0];
		buffer_brake = uiADCRawValueBuffer[1];

  Please check.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello SofLit! hope you're doing well!

Ok then i changed 

uint16_t uiADCRawValueBuffer[1];

to

uint16_t uiADCRawValueBuffer[2];

so i have enough element in this array. But i am still stuck with same problem. Cannot debug nor Run. 

Let's start with only 1 analog input. Throttle one.

Not obvious to find the problem with the info you provide.

This kind of issue needs a debug. So go step by step and find at which step you get the hardfault. 

You can comment out the code and uncomment line by line and find at which level the hardfault occurs.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Yes, i did what you told me and i found out that the debug mode starts not working anymore as soon as i uncomment the MX_CAN_Init();

What a joke! since i was able to send CAN frames a few days ago using the same config :(

> What a joke!

Jeeze, really?

Sigh... as with all "fault handler" issues, the answer is to look at the fault registers and figure out what caused the fault.  There are many (MANY) posts on this forum describing how to do that.  CubeIDE even has a built-in fault analyzer.

Typically when the issue moves around like this, you either have a stack issue or uninitialized/null pointer dereference.  The fault registers will help you figure out where.