2023-11-04 04:15 AM
Hi there,
I may ask something **bleep** or impossible, but I want to try.
Is there a way to debug (or at least look at the fault registers) a running MCU in a Fault state?
In my case, I have an STM32H735g (so Cortex M7) which runs a FreeRTOS-based code (quite a complex project), and now I'm facing the splendid situation of random system crashes, not replicable, on on-field running devices that, of course, don't have a debugger plugged in.
I'm wondering if there's a way to use tools like STM32cube Programmer in order to read the registers of a running MCU, or some magical trick done with other tools...
Any help or suggestion is warmly accepted,
thanks a lot
Solved! Go to Solution.
2023-11-04 08:01 AM
Added the GNU startup.s assembler to cut-n-paste
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c#L26
; Equivalent for GNU/GAS used with STM32CubeIDE etc
.section .text.HardFault_Handler,"ax",%progbits
HardFault_Handler:
/* Determine correct stack */
TST lr, #4
ITE EQ
MRSEQ R0, MSP /* Read MSP (Main) */
MRSNE R0, PSP /* Read PSP (Process) */
MOV R1, R4
MOV R2, R5
MOV R3, R6
B hard_fault_handler_c /* sourcer32@gmail.com */
.size HardFault_Handler, .-HardFault_Handler
2023-11-04 06:19 AM
Hot-swapping or hot-plugging can be hit or miss. Use those options in ST-LINK or J-LINK tools.
Here we tend to use the serial port to output enough actionable data to debug/diagnose the situation. If you want to get a report after failure add a wait for getchar() and loop to reprint.
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c
Also recommended to move to the version of Error_Handler() that outputs source file and line number info so those can be run to ground too.
2023-11-04 06:35 AM
Thanks for the quick reply!
I see. Didn't know about hot-plugging options you're talking about, I'll search for them on the net..
I have a few questions:
1) didn't know about that error handler version, how does it works exactly?
2) i see that it uses a snippet to insert inside the linker file of Keil. Did anybody created a Stm32cube version?
Thanks again
2023-11-04 07:45 AM
startup.s I've likely posted GNU GAS format assembler before, shouldn't be too traumatic to port.
ST some times used Error_Handler(__FILE__, __LINE__); form to understand WTH the fault came from, especially when there's dozens of potential sources. Also best to have some method of resolution or restart, as the while() loop basically bricks a product.
/**
* @brief This function is executed in case of error occurrence.
* @PAram None
* @retval None
*/
void Error_Handler(const char *file, uint32_t line)
{
printf("Error %s %u\n", file, line);
/* User may add here some code to deal with this error */
while(1)
{
}
}
2023-11-04 08:01 AM
Added the GNU startup.s assembler to cut-n-paste
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c#L26
; Equivalent for GNU/GAS used with STM32CubeIDE etc
.section .text.HardFault_Handler,"ax",%progbits
HardFault_Handler:
/* Determine correct stack */
TST lr, #4
ITE EQ
MRSEQ R0, MSP /* Read MSP (Main) */
MRSNE R0, PSP /* Read PSP (Process) */
MOV R1, R4
MOV R2, R5
MOV R3, R6
B hard_fault_handler_c /* sourcer32@gmail.com */
.size HardFault_Handler, .-HardFault_Handler
2023-11-14 01:11 AM
Sorry for the late response, I missed the notifications.
Thanks for your time and the good answers, I found the hotplug configurations on CubeIDE, and they seem to work fine. Also, the code you posted is really good, thanks!