Hi Alistair
1. I don't actually think that the order of the two instructions make any difference in thsi circumance since the oscillator input is not actually connected to anything until later on. However I tried the reversed odering and it didn't change the behaviour in any way.
2. I did think that there may be a slow starup involved but it doesn't start when the watchdog is disabled either. If I watch the oscillation on the crystal itself it is quite fast - when the watchdog fires and the board resets the oscillator virtually continues running across the reset.
3. When I set to 4kHz the debugger still doesn't operate correctly.
However I have realised something and that is that the program is actually not hanging at the clock initialisation but rather does run further due to the fact that there is an LED being turned on before the "freeze" occurs. This output is initialised (before the clock setting) to an output driving '1' which means that the LED is initially turned off. The LED is turned on a little later after variable initialisation has taken place.
With this clock speed, debugging is seemingly not possible (with the tools that I am presenty using) but I am now believing that the problem lies elsewhere, but is due to the slow speed.
What I have been able to determine by using some port output debugging is that the SYSTICK is programmed (with a value of 0x665 to give 50ms) but this interrupt is not firing.
The same code (of course with higher SYSTICK match reload value) at 8MHz or 48MHz clock rate is reliable.
As mentioned earlier - if I leave the board for 5 or 10 minuted in the watchdog cycle (resets every 1s due to missing timer) it starts working at some random point in time! (LED flashes at 50ms rate). I can make as many resets as I want to the board now and each time it starts immediately. As soon as I perform a power cycle I have to wait 5..10 minutes again before it starts working once more.
My intermediate conclusion is thus that there is no probelm with changing the clock mode but rather due to having a slow clock (32kHz) - related to the SYSTICK or its interrupt. There looks to be some state held across warm resets but if it can somehow manage to get a first TICK interrupt it then runs normally until the next power cycle. There is no "freeze" involved because it is certainly spinning in main() waiting for the interrupt.
I have attached the binary in case anyone would like to see its behaviour and or see whether a debugger can connect to it.
Regards
Mark