-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The current runtime_init() invokes clocks_init() which is entirely hard-wired for crystal oscillator at 12MHz (and sets up PLLs assuming 12MHz base frequency), such that any board with a higher frequency crystal/external oscillator to XIN will fail before the user application gets a chance to reconfigure it.
Issue #748 requests support to heavily customise this startup behaviour (for example, if there is no crystal at all or it is undersirable to use it for power reasons). However, there is another class of applications that do want all the standard initialisation but simply have a crystal of different frequency (or an external clock wired to XIN). This could usefully be supported by allowing the board file to specify the crystal frequency.
There is already a symbol XOSC_MHZ defined in platform_defs.h, but this is almost entirely ignored in the setup code in clocks_init().
If the code in clocks_init() were updated to respect XOSC_MHZ, it could be overridden in the board file for boards with non-standard crystals.
One question is what setup is expected in respect of the PLLs. The minimum requirement is that the PLLs are not set up to out-of-range frequencies, causing a crash before the user program has a chance to do further setup. The ideal would be to set the desired PLL output frequencies for any crystal, but the PLL configuration tool is currently in the form of a python program not readily invoked during the build process. A compromise would be to allow the board file to define the PLL parameters, and for the code in clocks_init() to set the PLLs to x1 as a fallback if XOSC_MHZ != 12 and custom PLL parameters have not been defined.