diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 497e409c66563..5fe5512564e57 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -630,15 +630,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) hse:$(HEADER_BUILD)/qstr.i.last pllm:$(HEADER_BUILD)/qstr.i.last > $@ $(BUILD)/modstm.o: $(GEN_STMCONST_HDR) $(HEADER_BUILD)/modstm_const.h: $(CMSIS_MCU_HDR) make-stmconst.py | $(HEADER_BUILD) diff --git a/ports/stm32/boards/plli2svalues.py b/ports/stm32/boards/plli2svalues.py index 8ff7f0ff8fcdf..6ba1d6516599a 100644 --- a/ports/stm32/boards/plli2svalues.py +++ b/ports/stm32/boards/plli2svalues.py @@ -137,8 +137,11 @@ def search_header(filename, re_include, re_define, lookup, val): m = regex_define.match(line) if m: # found lookup value + found = m.group(3) + if "*" in found or "/" in found: + found = eval(found) if m.group(1) == lookup: - val[0] = int(m.group(3)) + val[0] = int(found) return val @@ -175,12 +178,14 @@ def main(): (hse,) = search_header( argv[0][len("hse:") :], r'#include "(boards/[A-Za-z0-9_./]+)"', - r"#define +(HSE_VALUE) +\((\(uint32_t\))?([0-9]+)\)", - "HSE_VALUE", + r"static.* (micropy_hw_hse_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;", + "micropy_hw_hse_value", [None], ) 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] + ) argv.pop(0) if argv[0].startswith("pllm:"): @@ -188,13 +193,13 @@ def main(): (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", + r"static.* (micropy_hw_clk_pllm) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;", + "micropy_hw_clk_pllm", [None], ) 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) diff --git a/ports/stm32/boards/pllvalues.py b/ports/stm32/boards/pllvalues.py index 2db6b5f257044..293e157dc9749 100644 --- a/ports/stm32/boards/pllvalues.py +++ b/ports/stm32/boards/pllvalues.py @@ -230,7 +230,9 @@ def print_table(hse, 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]+)\)") + 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() @@ -242,8 +244,11 @@ def search_header_for_hsx_values(filename, vals): 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": + 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": vals[0] = val else: vals[1] = val @@ -282,7 +287,7 @@ def main(): # extract HSE_VALUE, and optionally HSI_VALUE, from header file hse, hsi = search_header_for_hsx_values(argv[0][5:], [None, None]) 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]) diff --git a/ports/stm32/machine_i2s.c b/ports/stm32/machine_i2s.c index a2a0a8291008c..06a167d606a37 100644 --- a/ports/stm32/machine_i2s.c +++ b/ports/stm32/machine_i2s.c @@ -33,7 +33,14 @@ #include "py/mphal.h" #include "pin.h" #include "dma.h" +#ifndef NO_QSTR #include "genhdr/plli2stable.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. +static uint32_t __attribute__((unused)) micropy_hw_hse_value = HSE_VALUE; +static uint32_t __attribute__((unused)) micropy_hw_clk_pllm = MICROPY_HW_CLK_PLLM; // 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 diff --git a/ports/stm32/powerctrl.c b/ports/stm32/powerctrl.c index 7755149227216..330d73995e918 100644 --- a/ports/stm32/powerctrl.c +++ b/ports/stm32/powerctrl.c @@ -28,8 +28,17 @@ #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. +static uint32_t __attribute__((unused)) micropy_hw_hse_value = HSE_VALUE; +static uint32_t __attribute__((unused)) micropy_hw_hsi_value = HSI_VALUE; +static uint32_t __attribute__((unused)) micropy_hw_clk_pllm = MICROPY_HW_CLK_PLLM; #if defined(STM32H5) || defined(STM32H7) #define RCC_SR RSR