Hi Li Peng Fei,
The RAM content after power-on reset is random. The RAM content is not affected in the case of system resets like COP, Low Voltage reset,…
When you specify some specific default value for a variable like:
unsigned char FirmwareUsbRequestFlag = 100;
The startup code will read this value from flash and store it at the FirmwareUsbRequestFlag position in RAM.
If you do not specify a specific default value, like:
unsigned char FirmwareUsbRequestFlag;
The startup code will clear FirmwareUsbRequestFlag position in RAM (=0).
When you place your FirmwareUsbRequestFlag variable into the NO_INIT segment, the startup code will simply ignore this variable = no load from flash/ no clearing. So, variable value will be random after Power-On reset and stay unchanged after other resets.
The reset type may be checked by flags like PORF. Please be aware, that you have to clear this flag after reading for correct reset type detection.
For example:
if (CPMURFLG_PORF)
{
FirmwareUsbRequestFlag = 0;
}
CPMURFLG = 0x6B;
I hope it helps you.
Have a great day,
Radek