stm32: a HardFault resets without a trace and MemManage/BusFault/UsageFault hang; add a board hook to record faults
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- c
- Área
- embedded-iot
Línea de trabajo
Start with ports/stm32/stm32_it.c and the listed HardFault_C_Handler, MemManage_Handler, BusFault_Handler, and UsageFault_Handler paths; check the existing fault handlers and board configuration hooks. Confirm the intended behavior with maintainers before implementation, since this proposes a new hook and changes fault handling. Done should include an optional board hook that can record fault details before reset, with configurable faults following the HardFault path when enabled.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
In ports/stm32/stm32_it.c (v1.29.0), faults leave nothing behind to diagnose them with in the field:
HardFault resets silently. HardFault_C_Handler calls powerctrl_mcu_reset() first unless pyb.fault_debug(True) was set (lines 149-151). A crash in the field then looks exactly like a board that rebooted on its own, and machine.reset_cause() can't tell it apart from a software or pin reset.
The configurable faults hang. mpu.h enables MemManage (SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk), and MemManage_Handler, BusFault_Handler and UsageFault_Handler loop forever in MICROPY_BOARD_FATAL_ERROR. An MPU violation hangs the board. A hardware watchdog can reset it, but at default priorities a watchdog early-warning interrupt can't preempt the fault handler, so nothing records where the fault happened.
Proposal: an optional board hook, called before the reset. A board can save the fault to backup registers or no-init RAM and report it after reboot. When a board defines the hook, the configurable faults take the HardFault path too, so they are recorded and reset instead of hanging.
see code below
BusFault_Handler and UsageFault_Handler get the same treatment. The board side is a few lines: store pc, lr, xpsr plus SCB->CFSR and SCB->HFSR.
Tested on an STM32N657 board. An inline-asm branch to address 0 reset within 1 s and left CFSR = INVSTATE, HFSR = FORCED, PC = 0, and LR in fun_asm_call. We use this as a local patch and can open a PR if the approach is acceptable.
Code Size
void HardFault_C_Handler(ExceptionRegisters_t *regs) {
- #if defined(MICROPY_BOARD_HARD_FAULT)
- // Last chance to note where it happened: the reset below is silent.
- MICROPY_BOARD_HARD_FAULT(regs->pc, regs->lr, regs->xpsr);
- #endif
- if (!pyb_hard_fault_debug) {
powerctrl_mcu_reset();
}
+#if defined(MICROPY_BOARD_HARD_FAULT)
+// The board records faults, so the configurable ones take the HardFault
+// path too: recorded, then reset (or dumped with pyb.fault_debug()), instead
+// of a silent hang. CFSR still says which fault it was. A plain branch keeps
+// LR as EXC_RETURN for HardFault_Handler's choice of stack.
+attribute((naked)) void MemManage_Handler(void) {
- __asm volatile ("b HardFault_Handler");
+}
+#else
void MemManage_Handler(void) {
/* Go to infinite loop when Memory Manage exception occurs */
while (1) {
MICROPY_BOARD_FATAL_ERROR("MemManage");
}
}
+#endif
Implementation
I intend to implement this feature and would submit a Pull Request if desirable
Code of Conduct
Yes, I agree
- Lenguaje dominante
- C
- Estrellas
- 22.2k
- Forks
- 9.1k
- Merge medio
- 6 d 8 h
- PR fusionados (30 d)
- 33
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de micropython/micropython
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
micropython/micropython#19942 ·
Los mantenedores suelen responder en 1 día
-
bug port-rp2
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
micropython/micropython#19933 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
micropython/micropython#19906 ·
Los mantenedores suelen responder en 1 día
-
bug port-stm32
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
micropython/micropython#19905 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
micropython/micropython#19873 ·
Los mantenedores suelen responder en 1 día
Todos los issues de micropython/micropython
Issues similares
-
快速入门那里会不会对新手不太友好,提出优化方案Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
-
-disable-symbolserver is ignored on macOS/Linux: PDBs are still downloaded from msdl.microsoft.comAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
-
follow-up Prio 📌
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
facebookincubator/muse-gadget-sdk#384 ·
Los mantenedores suelen responder en 5 días