Hardfault handler infinite loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-03 1:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-03 1:23 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-03 1:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-03 1:59 AM - edited ‎2024-04-03 4:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-03 5:25 AM
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 :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-03 10:04 AM
> 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.
