The existing problem is BMPs hanging upon a HardFault etc. with no indication of that happening.
This PR solves it by overriding default libopencm3-provided weak blocking_handler()'s with meaningful handlers which set a morse message and spin the systick (because of priority) for 10 seconds then reboot the probe.
I'm not sure if platform_request_boot() to request "stay in DFU" is better than just rebooting the probe, or if USB D+ pulse low is needed to trigger re-enumeration on some platforms, so I coded a direct scb_reset_system() instead. Future PRs could unwind the stack (I have tried implementing just that) and/or record crash dumps to SRAM or SPI flash or UART. If MPU is enabled by platform, to e.g. catch NULL dereferences, then there's a simple handler for that, too. Platforms should enable separate SCB->SHCSR BusFault and UsageFault bits for this code to distinguish between them.
Note I don't spin the UART/DMA/TIM or USB device IRQ handlers, but it technically could also be done to keep UART DMA and USB (DFU runtime stub, CDC-ACM, suspend/reset) working for a while for logging purposes. Notably sys_tick_handler() on native indirectly checks for Vtpwr undervoltage. I have not tested how this behaves yet.
Detailed description
blocking_handler()
's with meaningful handlers which set a morse message and spin the systick (because of priority) for 10 seconds then reboot the probe.I'm not sure if
platform_request_boot()
to request "stay in DFU" is better than just rebooting the probe, or if USB D+ pulse low is needed to trigger re-enumeration on some platforms, so I coded a directscb_reset_system()
instead. Future PRs could unwind the stack (I have tried implementing just that) and/or record crash dumps to SRAM or SPI flash or UART. If MPU is enabled by platform, to e.g. catch NULL dereferences, then there's a simple handler for that, too. Platforms should enable separateSCB->SHCSR
BusFault and UsageFault bits for this code to distinguish between them.Note I don't spin the UART/DMA/TIM or USB device IRQ handlers, but it technically could also be done to keep UART DMA and USB (DFU runtime stub, CDC-ACM, suspend/reset) working for a while for logging purposes. Notably
sys_tick_handler()
onnative
indirectly checks for Vtpwr undervoltage. I have not tested how this behaves yet.Your checklist for this pull request
Closing issues