How best to reset the CPU under program control?
Hi,
I thought this was probably obvious, but it seems more arcane than I expected. I'm sure there must be a proper way to do it.
I tried calling _start() .. it hard-faults after a few lines.
I tried calling reset_handler() .. it also hard-faults during _start().
I tried NVIC_SystemReset() which will probably work when STARTUP_FROM_RESET is defined, but won't of course, when debugging. (Hm, actually it seems not to work even then)
I tried calling main( 0, NULL ) .. again a hard-fault.
-
If you have a spare watchdog then enabling-and-abusing this can cause a reset.
But note that on stm32f4xx this is not as thorough as a power-on-reset. (I have seen this when read-protecting the FLASH).
At reset the arm processor loads its stack pointer and program counter from the vector table. So you might be able to do the same with a bit of assembly code. You will need to ensure that you have the _correct_ stack pointer active!
If the processor has different oscillator options then you might also have to put the processor back into its default oscillator mode before vectoring to the startup code (as that will assume it is in the default mode when switching to a faster mode).
Hope this helps,
Danish
-
It's highly processor dependent. Danish's suggestion to force a watchdog reset is probably the best universal solution. As he also notes, there may be some components that only reset as a result of a real power-on reset.
Cortex M3 devices can use the SYSRESETREQ bit in the application interrupt and reset control register to request to "force a large system reset of all major components except for debug."
Please sign in to leave a comment.
Comments
2 comments