diff --git a/os/hal/ports/STM32/STM32G4xx/cfg/clocktree.xml b/os/hal/ports/STM32/STM32G4xx/cfg/clocktree.xml
new file mode 100644
index 000000000..a430bee12
--- /dev/null
+++ b/os/hal/ports/STM32/STM32G4xx/cfg/clocktree.xml
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+ no clock
+
+
+
+ 16MHz high speed internal oscillator
+
+
+
+ 48MHz high speed internal oscillator
+
+
+
+ high frequency external oscillator
+
+
+
+ low frequency external oscillator
+
+
+
+ low frequency internal oscillator
+
+
+
+ PLL input
+
+
+
+
+
+
+
+
+ PLL reference
+
+
+
+ PLL VCO
+
+
+
+ PLL P output
+
+
+
+ PLL Q output
+
+
+
+ PLL R output
+
+
+
+ system clock
+
+
+
+
+
+
+
+ AHB
+
+
+
+
+
+
+
+
+
+
+
+
+
+ APB1
+
+
+
+
+
+
+
+
+
+ APB2
+
+
+
+
+
+
+
+
+
+
diff --git a/os/hal/ports/STM32/STM32G4xx/cfg/config.fmpp b/os/hal/ports/STM32/STM32G4xx/cfg/config.fmpp
new file mode 100644
index 000000000..25529f360
--- /dev/null
+++ b/os/hal/ports/STM32/STM32G4xx/cfg/config.fmpp
@@ -0,0 +1,15 @@
+sourceRoot: ../../../../../../tools/ftl/processors/clocktree
+outputRoot: ..
+dataRoot: .
+
+freemarkerLinks: {
+ lib: ../../../../../../tools/ftl/libs
+}
+
+data : {
+ doc1:xml (
+ clocktree.xml
+ {
+ }
+ )
+}
diff --git a/tools/ftl/processors/clocktree/clocktree.h.ftl b/tools/ftl/processors/clocktree/clocktree.h.ftl
new file mode 100644
index 000000000..3b91ce5e6
--- /dev/null
+++ b/tools/ftl/processors/clocktree/clocktree.h.ftl
@@ -0,0 +1,139 @@
+[#ftl]
+[#--
+ ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio.
+
+ This file is part of ChibiOS.
+
+ ChibiOS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ --]
+[@pp.dropOutputFile /]
+[#import "/@lib/libutils.ftl" as utils /]
+[#import "/@lib/liblicense.ftl" as license /]
+[@pp.changeOutputFile name="clocktree.h" /]
+[#-- Getting various constants.--]
+[#assign prename = doc1.clocktree.settings.prefixes.@name[0]?string /]
+[#assign postvalues = doc1.clocktree.settings.postfixes.@values[0]?string /]
+[#assign postclocks = doc1.clocktree.settings.postfixes.@clocks[0]?string /]
+[#assign postchoices = doc1.clocktree.settings.postfixes.@choices[0]?string /]
+[#assign postbits = doc1.clocktree.settings.postfixes.@bits[0]?string /]
+[#assign postswitches = doc1.clocktree.settings.postfixes.@switches[0]?string /]
+[#assign constfalse = doc1.clocktree.settings.constants.@false[0]?string /]
+[#assign consttrue = doc1.clocktree.settings.constants.@true[0]?string /]
+[#-- Sequence of the calculated clock points.--]
+[#assign clocks_expr = [] /]
+[#-- Sequence of the muxed clock points.--]
+[#assign clocks_mux = [] /]
+[#-- Scanning clock points, gathering data.--]
+[#list doc1.clocktree.clocks.clock as clock]
+ [#assign clockname = clock.@name[0] /]
+ [#if clock.description[0]??]
+ [#assign clockdescr = clock.description[0]?string?word_list?join(" ") /]
+ [#else /]
+ [#assign clockdescr = "no description" /]
+ [/#if]
+ [#-- Determining the type of the clock point by looking at the child element.--]
+ [#if clock.expr[0]??]
+ [#-- It is a calculated clock.--]
+ [#assign clockfreq = clock.expr[0].@frequency[0]?string /]
+ [#assign clocks_expr = clocks_expr + [{"description":clockdescr,
+ "name":clockname,
+ "frequency":clockfreq}] /]
+ [#elseif clock.mux[0]??]
+ [#-- It is a muxed clock.--]
+ [#assign muxname = clock.mux[0].@name[0] /]
+ [#assign inputs = [] /]
+ [#list clock.mux.input as input]
+ [#assign inputref = input.@ref[0] /]
+ [#assign inputbits = input.@bits[0]!"" /]
+ [#assign inputs = inputs + [{"name":inputref, "bits":inputbits}] /]
+ [/#list]
+ [#assign clocks_mux = clocks_mux + [{"name":clockname,
+ "muxname":muxname,
+ "inputs":inputs}] /]
+ [/#if]
+[/#list]
+/*
+[@license.EmitLicenseAsText /]
+*/
+
+/**
+ * @file clocktree.h
+ * @brief Generated clock tree description header.
+ *
+ * @addtogroup CLOCKTREE
+ * @{
+ */
+#ifndef CLOCKTREE_H
+#define CLOCKTREE_H
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name Mux configurations
+ * @{
+ */
+[#list clocks_mux as mux]
+ [#assign name = prename + mux["name"] + postchoices/]
+#if !defined(name) || defined(__DOXYGEN__)
+${("#define " + name)?right_pad(44) + prename + mux["name"] + "_" + mux["inputs"][0]["name"]}
+#endif
+
+[/#list]
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/**
+ * @name Calculated or fixed clocks
+ * @{
+ */
+[#list clocks_expr as clock]
+/**
+ * @brief ${clock["description"]?cap_first} clock point.
+ */
+${("#define " + prename + clock["name"] + postclocks)?right_pad(44) + clock["frequency"]}
+
+[/#list]
+/** @} */
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CLOCKTREE_H */
+
+/** @} */