My mcu is MC9S12.
Can i execute some codes to reset the mcu,other than a dead loop to wait the WDG to reset it?
1) Connect externally reset pin with some GPIO pin which is set as an output
For example, let's consider PTS_PTS7 is connected to a reset pin.
// pin setup
DDRS_DDRS7 = 0; // pi is an input to ensure it does not affect the reset pin
PTS_PTS7 = 0;
// I want to reset now
DDRS_DDRS7 = 1; // connect reset pin to GND
2) you can create an application which call uses Illegal Address Reset (use keyword in the reference manual to see possibilities)
- Accessing unimplemented FLASH pages in single chip modes causes an illegal address reset if the MPU is not configured to flag an MPU protection error in that range.
- Unimplemented RAM pages are mapped externally in expanded modes. Accessing unimplemented RAM pages in single chip modes causes an illegal address reset if the MPU is not configured to flag an MPU protection error in that range.
I do not agree with you. The COP provides you controlled reset with defined start vector different from POR reset vector if the reset signal meets some conditions defined in the reference manual. I have created a document, https://community.nxp.com/docs/DOC-103737, which says a little bit more with calculator providing values for external components to correctly calculate Reset circuitry components to be COP correctly recognized if it is necessary.
I you have already enabled COP then you can reset the MCU immediately by writing different value to ARMCOP than sequence 0x55, 0xAA.
ARMCOP=0x00; // reset MCU immediately by means of COP
If you do not use COP during run of the application then the approach is similar:
COPCTL = 0x01; // enable COP
ARMCOP=0x00; // reset MCU immediately by means of
You have to keep in mind that COPCTL is write once only and if you write or some tool like processor expert writes to COPCTL any value (even 0x00 .. we do not want to use COP) then you are not able to enable COP at the moment you need it. (Because of this I do not use any automatic setup and generated code...I want to have everything under my control)
If you want to use this approach then I suggest you also to read comments in the function interrupt 2 void WatchDogIsr(void) in the attached example. The COP is normal reset with different vector so SP is not set so it is not allowed to be used before it is set. Note, that the compiler can place some local variables to the stack and if it is not initialized then it is an issue. Global variables are better to be used if you need to do something within OP reset function. Then you can continue anywhere you want…your own functions or you can use start function of POR reset.
Just to add info just to increase complexity:
In the attached reset_recognition_calc_with_graph.xlsx (file to calculate external reset, also can be used to investigate COP) you can see that if you use capacitor 100nF and only internal pull up resistor t the reset pin then you can be sure that when the COP is generate then after reset it is not recognized and the MCU starts at POR reset. (for this calculation worst case scenario of pull up resistor value is 25kohm)
The setup I described above:
Yellow and grey lines shows logic low and high
Blue line only shows reset timing phases:
- zero step when the rest pin is held low internally or externally
- the first step...COP recognition
- the second step POR recognition
Orange line shows voltage at reset pin
In the case you want to be able recognize COP then you should use internal pull up resistance worst case scenario 50kohm and you will see also an external pull up resistor will be necessary.
Some more SW examples can be found at: