I have an STM32F205 processor in a battery backed up circuit. The battery is normally non connected, it can be connected via switch or GPIO. The problem is that if the IWD (Independent Watch Dog) fires whilst the system is running on battery, the GPIO goes low, the battery gets disconnected and the system turns off.
So, I'd like a soft reset, leave the GPIO high, but reset everything else. The IWG will fire after 16 seconds, I've setup a standard timer to run for 15 seconds, both get reset by the standard WD kick. This all works fine, But I now need the timer ISR to do this software reset.
I've tried duplicating the standard 'Reset_Handler' as 'SoftReset_Handler', adding SP init at start. This works ok, runs through SystemInit, runs through main(). Then it encounters os_sys_init_user() that calls os_set_env() all registers and all values in os_set_env() are the same between hard and soft reset with hard, BX LR ends up in SVC_Handler with soft, BX LR ends up in HardFaultHandler
Within the ISR, I've disabled all interrupts in NVIC and cleared all pending interrupts in NVIC.
Because I'm kicking this off from ISR, I'm in 'Handler' Mode instead of 'Thread' Mode, but this is the only difference I can see, other than doing something horrible like putting address of SoftResetHandler on stack and returning, I can't find a way of changing this.
Any ideas?
Yes, that resets the whole chip, including the GPIO, as soon as you do that, the pin goes to input, the line goes low, the battery turns off, the system shuts down. I need a softer reset, keep the GPIOs in their current state but reset everything else.
Firstly, the software should never have to reset, so this should never get called. Secondly, if it ever does reset, whilst on mains power a standard full reset is ok. So, we are talking about a condition that should never occur, but it still needs to be handled.
Using our own OS with simpler processor this was relatively easy. Using RTX and STM32F205, the OS and the security / complexity of the Controller make it impossible from my current viewpoint.
So, I'm stuck and asking for ideas as I think I've run out.
"as soon as you do that, the pin goes to input, the line goes low"
The line going low is a result of your hardware design.
You could add a pullup if you want it to be high.
In normal use, it's not supposed to be high, it actually has a pull down on it because the system should not run up when you connect the battery. I have considered adding a capacitor so that it delays the turn off for long enough purely for this condition through a reset, but the project is too late for hardware changes at this stage.
Hmm - that is a pickle, then.
Sorry, don't know what else to suggest - you are fighting the hardware.
:(