Skip to content

stm32: Fix extraction of hse/hsi/pllm values from preprocessed source. #16444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions ports/stm32/boards/plli2svalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions ports/stm32/boards/pllvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,16 @@ 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:
line = line.strip()
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:
Expand Down
Loading