diff options
| author | Damien George <damien@micropython.org> | 2024-12-19 00:55:31 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-12-19 00:55:31 +1100 |
| commit | 3c1722e705002b2182f138a114f4408ae7ebac38 (patch) | |
| tree | f24920137d542ad226bb2150b89fe85c34a8f1a3 | |
| parent | 7924b31050271c76ff6cf26c6fda5fe3ba615d08 (diff) | |
stm32: Fix extraction of hse/hsi/pllm values from preprocessed source.
The expressions for the `micropy_hw_hse_value` etc variables may contain
parenthesis, eg `micropy_hw_hse_value = ((25) * 1000000)`. To handle such
a case, simplify the regex and always use `eval(found)` to evaluate the
expression.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/stm32/boards/plli2svalues.py | 11 | ||||
| -rw-r--r-- | ports/stm32/boards/pllvalues.py | 8 |
2 files changed, 7 insertions, 12 deletions
diff --git a/ports/stm32/boards/plli2svalues.py b/ports/stm32/boards/plli2svalues.py index 436dcee74..e5ea4e8df 100644 --- a/ports/stm32/boards/plli2svalues.py +++ b/ports/stm32/boards/plli2svalues.py @@ -132,12 +132,9 @@ def search_header(filename, re_define, lookup): 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) + found = m.group(2) if m.group(1) == lookup: - val = int(found) + val = eval(found) return val @@ -179,7 +176,7 @@ def main(): # extract hse value from processed header files hse = search_header( argv[0][len("file:") :], - r"static.* (micropy_hw_hse_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;", + r"static.* (micropy_hw_hse_value) = +([0-9 +-/\*()]+);", "micropy_hw_hse_value", ) if hse is None: @@ -190,7 +187,7 @@ def main(): # extract pllm value from processed header files pllm = search_header( argv[0][len("file:") :], - r"static.* (micropy_hw_clk_pllm) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;", + r"static.* (micropy_hw_clk_pllm) = +([0-9 +-/\*()]+);", "micropy_hw_clk_pllm", ) if pllm is None: diff --git a/ports/stm32/boards/pllvalues.py b/ports/stm32/boards/pllvalues.py index 5edc1d51f..d8856bfec 100644 --- a/ports/stm32/boards/pllvalues.py +++ b/ports/stm32/boards/pllvalues.py @@ -231,7 +231,7 @@ def print_table(hse, valid_plls): 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 +-/\*]+)\)*;", + r"static.* +(micropy_hw_hs[ei]_value) = +([0-9 +-/\*()]+);", ) with open(filename) as f: for line in f: @@ -239,10 +239,8 @@ def search_header_for_hsx_values(filename): m = regex_def.match(line) if m: # Found HSE_VALUE or HSI_VALUE - found = m.group(3) - if "*" in found or "/" in found: - found = eval(found) - val = int(found) // 1000000 + found = m.group(2) + val = eval(found) // 1000000 if m.group(1) == "micropy_hw_hse_value": hse = val else: |
