System time
Timekeeping is a basic requirement for almost any embedded system. A microcontroller can be programmed to trigger an interrupt at regular intervals, which is commonly used to increment the monotonic system clock. To do so, a few configuration steps must be performed at startup in order to have a stable tick interrupt. Many processors can run at custom frequencies while using the same oscillator as source. The input frequency of the oscillator, which can be internal or external to the CPU, is used to derive the processor main clock. The configurable logic integrated in the CPU is implemented by a PLL that multiplies the input clock from an external stable source, and produces the desired frequencies used by the CPU and integrated peripherals.
Adjusting the flash wait states
If the initialization code is running from flash, it might be necessary to set the wait state for the flash memory before altering the system clocks. If the microprocessor runs at high frequencies, it might require...