Hello everyone:
The function I want to design is when MCU lose the main external oscillator, it could switch the Clock source to Internal Clock source 、keep the code running i and get the external main oscillator fault flag
The following are the ways I tried:
1、Detect the register MOSCCTL (I don't set any bit of it), when the code is running, the bit OSCRNG(High Frequency Range (equal to or greater than 10 MHz).) was 1 when the rest were 0. After I cut off the external oscillator, the code jump into Hard_fault handler automatically and register MOSCCTL didn't has any changes.
2、When I used j-link simulator to simulate the MCU, I cut off the external oscillator. In most case, the code will jump to Hard_Fault Handler, but sometimes it will jump to bus_fault or memery_fault. What's more, when code jump into hard_fault handler, it need me to click single step run the code, it can't run in full speed and sometimes it even didn't run and register PC didn't count when I click single step. So it 's difficult to me to judge whether the MCU was still working.
3、I have some idea that when the external oscillator fail, it could reboot the MCU and when it decides which clock source to use according to bit MOSCPUPIM in register IMC and set a flag which means MCU lost external oscillator last time when it initialize the MCU. There are 2 defects, one is when it repower MCU, the bit MOSCPUPIM will be clear; two is when clock fault happen,it don't have time to do the emergency operation such as control GPIO to cut off some breaker.
It is very kind of you if you have any ideas could share to me.
Thank you all