The original GD32 SPL code sadly does a static clock source selection in the system_xxx.c file.
|
/* select a system clock by uncommenting the following line */ |
|
/* use IRC8M */ |
|
//#define __SYSTEM_CLOCK_IRC8M (uint32_t)(__IRC8M) |
|
//#define __SYSTEM_CLOCK_48M_PLL_IRC8M (uint32_t)(48000000) |
|
//#define __SYSTEM_CLOCK_72M_PLL_IRC8M (uint32_t)(72000000) |
|
//#define __SYSTEM_CLOCK_108M_PLL_IRC8M (uint32_t)(108000000) |
|
//#define __SYSTEM_CLOCK_120M_PLL_IRC8M (uint32_t)(120000000) |
|
|
|
/* use HXTAL(XD series CK_HXTAL = 8M, CL series CK_HXTAL = 25M) */ |
|
//#define __SYSTEM_CLOCK_HXTAL (uint32_t)(__HXTAL) |
|
//#define __SYSTEM_CLOCK_48M_PLL_HXTAL (uint32_t)(48000000) |
|
//#define __SYSTEM_CLOCK_72M_PLL_HXTAL (uint32_t)(72000000) |
|
//#define __SYSTEM_CLOCK_108M_PLL_HXTAL (uint32_t)(108000000) |
|
#define __SYSTEM_CLOCK_120M_PLL_HXTAL (uint32_t)(120000000) |
This means that users who want to change which clock their firmware uses need to edit SPL package files. This is not how it's supposed to be, the SPL files are supposed to be constant but externally user-configurable.
A solution must be engineered that allows, e.g. via global macro setting, to influence the clock selection logic of the SPL framework easily.
Idea: global CLOCK_SOURCE macro with numeric values selecting the source? Or better a more dynamic "target frequency" macro, HSE or HSI clock flag, PLL factors macros, ...?
It should also be a choice to not compile in the clock selection code, but have the user provide it via one of the project files (and the linker).
The original GD32 SPL code sadly does a static clock source selection in the
system_xxx.cfile.gd32-pio-spl-package/gd32/cmsis/variants/gd32f30x/system_gd32f30x.c
Lines 42 to 55 in d8af9a4
This means that users who want to change which clock their firmware uses need to edit SPL package files. This is not how it's supposed to be, the SPL files are supposed to be constant but externally user-configurable.
A solution must be engineered that allows, e.g. via global macro setting, to influence the clock selection logic of the SPL framework easily.
Idea: global
CLOCK_SOURCEmacro with numeric values selecting the source? Or better a more dynamic "target frequency" macro, HSE or HSI clock flag, PLL factors macros, ...?It should also be a choice to not compile in the clock selection code, but have the user provide it via one of the project files (and the linker).