Conversation
|
Which bootloaders? This seems like a bootloader bug, although we have the |
|
I encountered this with the bootloader on py32f072 after flashing a firmware using its usb hid bootloader. It seems like the bootloader enables the USB interrupt, SysTick and PendSV and doesn't disable it after jumping to user code, so if an interrupt fires before the user firmware data structures are set up, the interrupt handler can corrupt data or crash causing a stuck cpu. The fix would be to enable both this feature and the set-vtor feature which seems to make it reliably boot. |
|
I think you could just disable interrupts, and write code in Rust inside main to reset your peripherals? I don't think restting all the interrupts needs to be pre-main, and I don't think it needs to be in cortex-m-rt, given it's only to work-around buggy bootloaders on specific platforms. |
|
There would still be a small window between setting vtor and disabling peripherals though. Putting it before setting vtor would be much less likely to crash since we assume that the data structures in ram are still set up for the bootloader's ISR. Yeah I agree trying to fix every bootloader's bugs in cortex-m-rt isn't a good idea so I wanted to get some comments on this. |
|
I think it would probably be enough to have a new feature like |
| // If enabled, mask all configurable interrupts before any other startup code runs. This | ||
| // prevents interrupts left enabled by a bootloader from using the bootloader's vector table. | ||
| #[cfg(feature = "reset-interrupt-state")] | ||
| "cpsid i", |
There was a problem hiding this comment.
Would cpsid f be needed as well on targets that support it?
(Probably not - when interrupts are disabled, any HardFault between this point and the proper initialization of the vector table must be triggered by our own startup code, so it's our responsibility to not trigger such a fault in the first place. Unlike interrupts, that could be triggered by outside events.)
Some bootloaders don't disable interrupts when exiting and jumping into user code.
What should be the order to execute this with respect to set-vtor/set-sp?