18.2.2 The On Reset Routine

Some hardware configurations require special initialization, often within the first few instruction cycles after Reset. For instance, you might need to initialize a DDR RAM controller before the program's variables are initialized. To achieve this, there is an On Reset hook provided, so that you do not need to customize the entire startup code sequence.

An empty weak implementation of the On Reset routine (_on_reset) is provided with the start-up code. It is called by the runtime startup code after minimal initialization of the C/C++ language context.

If you do need to implement your own version of this routine, you can modify the following stub. (Note the leading underscore character in the function’s name.)
void _on_reset(void)
{
  // Add code to be executed soon after reset here
}
This routine can be placed into any source file in your project, and you do not need to adjust any compiler options to have it executed.

Special consideration needs to be taken when writing this routine in C or C++. The code should not assume that the runtime environment has been fulled established. See 18.2 Runtime Start-up Code for the order in which the environment is set up. Most importantly, statically allocated variables will not have been initialized (with either the specified initializer or a zero value, as required for uninitialized variables), nor will any static constructors have been called for C++ applications. References to non-automatic variables in C/C++ applications might yield unexpected or unpredictable results; however, the stack pointer will have been initialized.