stm32: Generate PLL tables from pre-processed headers.
Some checks failed
JavaScript code lint and formatting with Biome / eslint (push) Failing after 0s
unix port / macos (push) Waiting to run
windows port / build-vs (Debug, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Debug, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x64, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, dev, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2019, standard, 2019, [16, 17)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, dev, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-2022, standard, 2022, [17, 18)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, dev, 2017, [15, 16)) (push) Waiting to run
windows port / build-vs (Release, x86, windows-latest, standard, 2017, [15, 16)) (push) Waiting to run
windows port / build-mingw (i686, mingw32, dev) (push) Waiting to run
windows port / build-mingw (i686, mingw32, standard) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, dev) (push) Waiting to run
windows port / build-mingw (x86_64, mingw64, standard) (push) Waiting to run
Check code formatting / code-formatting (push) Failing after 0s
Check spelling with codespell / codespell (push) Failing after 0s
Build docs / build (push) Failing after 0s
Check examples / embedding (push) Failing after 0s
Package mpremote / build (push) Failing after 0s
.mpy file format and tools / test (push) Failing after 0s
Build ports metadata / build (push) Failing after 0s
cc3200 port / build (push) Failing after 0s
esp32 port / build_idf (esp32_build_cmod_spiram_s2) (push) Failing after 0s
esp32 port / build_idf (esp32_build_s3_c3) (push) Failing after 0s
esp8266 port / build (push) Failing after 0s
mimxrt port / build (push) Failing after 0s
nrf port / build (push) Failing after 0s
powerpc port / build (push) Failing after 0s
qemu port / build_and_test_arm (push) Failing after 0s
qemu port / build_and_test_rv32 (push) Failing after 0s
renesas-ra port / build_renesas_ra_board (push) Failing after 0s
rp2 port / build (push) Failing after 0s
samd port / build (push) Failing after 0s
stm32 port / build_stm32 (stm32_misc_build) (push) Failing after 0s
stm32 port / build_stm32 (stm32_nucleo_build) (push) Failing after 0s
stm32 port / build_stm32 (stm32_pyb_build) (push) Failing after 0s
unix port / minimal (push) Failing after 0s
unix port / reproducible (push) Failing after 0s
unix port / standard (push) Failing after 0s
unix port / standard_v2 (push) Failing after 0s
unix port / coverage (push) Failing after 0s
unix port / coverage_32bit (push) Failing after 0s
unix port / nanbox (push) Failing after 0s
unix port / float (push) Failing after 0s
unix port / stackless_clang (push) Failing after 0s
unix port / float_clang (push) Failing after 0s
unix port / settrace (push) Failing after 0s
unix port / settrace_stackless (push) Failing after 0s
unix port / qemu_mips (push) Failing after 0s
unix port / qemu_arm (push) Failing after 0s
unix port / qemu_riscv64 (push) Failing after 0s
webassembly port / build (push) Failing after 0s
windows port / cross-build-on-linux (push) Failing after 0s
zephyr port / build (push) Failing after 0s
Python code lint and formatting with ruff / ruff (push) Failing after 0s

Allows boards to configure their HSE and PLL values in variants.

Signed-off-by: Andrew Leech <andrew@alelec.net>
This commit is contained in:
Andrew Leech
2024-09-03 10:41:25 +10:00
committed by Damien George
parent 22804fccf3
commit 7924b31050
5 changed files with 68 additions and 50 deletions

View File

@@ -640,15 +640,15 @@ $(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(HEADER_
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) \
--output-af-const $(GEN_PINS_AF_CONST) --output-af-defs $(GEN_PINS_AF_DEFS)
powerctrl.c: $(GEN_PLLFREQTABLE_HDR)
$(GEN_PLLFREQTABLE_HDR): $(PLLVALUES) | $(HEADER_BUILD)
$(BUILD)/powerctrl.o: $(GEN_PLLFREQTABLE_HDR)
$(GEN_PLLFREQTABLE_HDR): $(PLLVALUES) | $(HEADER_BUILD)/qstr.i.last
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PLLVALUES) -c -m $(CMSIS_MCU_LOWER) file:$(BOARD_DIR)/stm32$(MCU_SERIES)xx_hal_conf.h > $@
$(Q)$(PYTHON) $(PLLVALUES) -c -m $(CMSIS_MCU_LOWER) file:$(HEADER_BUILD)/qstr.i.last > $@
$(TOP)/extmod/machine_i2s.c: $(GEN_PLLI2STABLE_HDR)
$(GEN_PLLI2STABLE_HDR): $(PLLI2SVALUES) | $(HEADER_BUILD)
$(BUILD)/extmod/machine_i2s.o: $(GEN_PLLI2STABLE_HDR)
$(GEN_PLLI2STABLE_HDR): $(PLLI2SVALUES) | $(HEADER_BUILD)/qstr.i.last
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PLLI2SVALUES) -c -m $(CMSIS_MCU_LOWER) hse:$(BOARD_DIR)/stm32$(MCU_SERIES)xx_hal_conf.h pllm:$(BOARD_DIR)/mpconfigboard.h > $@
$(Q)$(PYTHON) $(PLLI2SVALUES) -c -m $(CMSIS_MCU_LOWER) file:$(HEADER_BUILD)/qstr.i.last > $@
$(BUILD)/modstm.o: $(GEN_STMCONST_HDR)
$(HEADER_BUILD)/modstm_const.h: $(CMSIS_MCU_HDR) make-stmconst.py | $(HEADER_BUILD)

View File

@@ -123,22 +123,21 @@ def generate_c_table(plli2s_table, hse, pllm):
print("}")
def search_header(filename, re_include, re_define, lookup, val):
regex_include = re.compile(re_include)
def search_header(filename, re_define, lookup):
regex_define = re.compile(re_define)
val = None
with open(filename) as f:
for line in f:
line = line.strip()
m = regex_include.match(line)
if m:
# Search included file
search_header(m.group(1), re_include, re_define, lookup, val)
continue
m = regex_define.match(line)
if m:
# found lookup value
found = m.group(3)
if "*" in found or "/" in found:
# process define using multiply or divide to calculate value
found = eval(found)
if m.group(1) == lookup:
val[0] = int(m.group(3))
val = int(found)
return val
@@ -166,35 +165,37 @@ def main():
break
if mcu_series in mcu_support_plli2s:
if len(argv) != 2:
if len(argv) not in (1, 2):
print("usage: pllvalues.py [-c] [-m <mcu_series>] <hse in MHz> <pllm in MHz>")
sys.exit(1)
if argv[0].startswith("hse:"):
# extract HSE_VALUE from header file
(hse,) = search_header(
argv[0][len("hse:") :],
r'#include "(boards/[A-Za-z0-9_./]+)"',
r"#define +(HSE_VALUE) +\((\(uint32_t\))?([0-9]+)\)",
"HSE_VALUE",
[None],
)
if hse is None:
raise ValueError("%s does not contain a definition of HSE_VALUE" % argv[0])
argv.pop(0)
hse = int(argv[0][len("hse:") :])
if argv[0].startswith("pllm:"):
# extract MICROPY_HW_CLK_PLLM from header file
(pllm,) = search_header(
argv[0][len("pllm:") :],
r'#include "(boards/[A-Za-z0-9_./]+)"',
r"#define +(MICROPY_HW_CLK_PLLM) +\((\(uint32_t\))?([0-9]+)\)",
"MICROPY_HW_CLK_PLLM",
[None],
pllm = int(argv[0][len("pllm:") :])
if argv[0].startswith("file:"):
# extract hse value from processed header files
hse = search_header(
argv[0][len("file:") :],
r"static.* (micropy_hw_hse_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;",
"micropy_hw_hse_value",
)
if hse is None:
raise ValueError(
"%s does not contain a definition of micropy_hw_hse_value" % argv[0]
)
# extract pllm value from processed header files
pllm = search_header(
argv[0][len("file:") :],
r"static.* (micropy_hw_clk_pllm) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;",
"micropy_hw_clk_pllm",
)
if pllm is None:
raise ValueError(
"%s does not contain a definition of MICROPY_HW_CLK_PLLM" % argv[0]
"%s does not contain a definition of micropy_hw_clk_pllm" % argv[0]
)
argv.pop(0)

View File

@@ -228,26 +228,26 @@ def print_table(hse, valid_plls):
print("found %u valid configurations" % len(valid_plls))
def search_header_for_hsx_values(filename, vals):
regex_inc = re.compile(r'#include "(boards/[A-Za-z0-9_./]+)"')
regex_def = re.compile(r"#define +(HSE_VALUE|HSI_VALUE) +\((\(uint32_t\))?([0-9]+)\)")
def search_header_for_hsx_values(filename):
hse = hsi = None
regex_def = re.compile(
r"static.* +(micropy_hw_hs[ei]_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;",
)
with open(filename) as f:
for line in f:
line = line.strip()
m = regex_inc.match(line)
if m:
# Search included file
search_header_for_hsx_values(m.group(1), vals)
continue
m = regex_def.match(line)
if m:
# Found HSE_VALUE or HSI_VALUE
val = int(m.group(3)) // 1000000
if m.group(1) == "HSE_VALUE":
vals[0] = val
found = m.group(3)
if "*" in found or "/" in found:
found = eval(found)
val = int(found) // 1000000
if m.group(1) == "micropy_hw_hse_value":
hse = val
else:
vals[1] = val
return vals
hsi = val
return hse, hsi
def main():
@@ -280,9 +280,9 @@ def main():
if argv[0].startswith("file:"):
# extract HSE_VALUE, and optionally HSI_VALUE, from header file
hse, hsi = search_header_for_hsx_values(argv[0][5:], [None, None])
hse, hsi = search_header_for_hsx_values(argv[0][5:])
if hse is None:
raise ValueError("%s does not contain a definition of HSE_VALUE" % argv[0])
raise ValueError("%s does not contain a definition of micropy_hw_hse_value" % argv[0])
else:
# HSE given directly as an integer
hse = int(argv[0])

View File

@@ -33,7 +33,9 @@
#include "py/mphal.h"
#include "pin.h"
#include "dma.h"
#ifndef NO_QSTR
#include "genhdr/plli2stable.h"
#endif
// Notes on this port's specific implementation of I2S:
// - the DMA callbacks (1/2 complete and complete) are used to implement the asynchronous background operations

View File

@@ -28,8 +28,23 @@
#include "py/mphal.h"
#include "powerctrl.h"
#include "rtc.h"
#include "genhdr/pllfreqtable.h"
#include "extmod/modbluetooth.h"
#include "py/mpconfig.h"
#ifndef NO_QSTR
#include "genhdr/pllfreqtable.h"
#endif
// These will be defined / expanded in pre-processor output for use in the
// boards/pllvalues.py script, then generally stripped from final firmware.
#ifdef HSI_VALUE
static uint32_t __attribute__((unused)) micropy_hw_hsi_value = HSI_VALUE;
#endif
#ifdef HSE_VALUE
static uint32_t __attribute__((unused)) micropy_hw_hse_value = HSE_VALUE;
#endif
#ifdef MICROPY_HW_CLK_PLLM
static uint32_t __attribute__((unused)) micropy_hw_clk_pllm = MICROPY_HW_CLK_PLLM;
#endif
#if defined(STM32H5) || defined(STM32H7)
#define RCC_SR RSR