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>
This commit is contained in:
@@ -132,12 +132,9 @@ def search_header(filename, re_define, lookup):
|
|||||||
m = regex_define.match(line)
|
m = regex_define.match(line)
|
||||||
if m:
|
if m:
|
||||||
# found lookup value
|
# found lookup value
|
||||||
found = m.group(3)
|
found = m.group(2)
|
||||||
if "*" in found or "/" in found:
|
|
||||||
# process define using multiply or divide to calculate value
|
|
||||||
found = eval(found)
|
|
||||||
if m.group(1) == lookup:
|
if m.group(1) == lookup:
|
||||||
val = int(found)
|
val = eval(found)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +176,7 @@ def main():
|
|||||||
# extract hse value from processed header files
|
# extract hse value from processed header files
|
||||||
hse = search_header(
|
hse = search_header(
|
||||||
argv[0][len("file:") :],
|
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",
|
"micropy_hw_hse_value",
|
||||||
)
|
)
|
||||||
if hse is None:
|
if hse is None:
|
||||||
@@ -190,7 +187,7 @@ def main():
|
|||||||
# extract pllm value from processed header files
|
# extract pllm value from processed header files
|
||||||
pllm = search_header(
|
pllm = search_header(
|
||||||
argv[0][len("file:") :],
|
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",
|
"micropy_hw_clk_pllm",
|
||||||
)
|
)
|
||||||
if pllm is None:
|
if pllm is None:
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ def print_table(hse, valid_plls):
|
|||||||
def search_header_for_hsx_values(filename):
|
def search_header_for_hsx_values(filename):
|
||||||
hse = hsi = None
|
hse = hsi = None
|
||||||
regex_def = re.compile(
|
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:
|
with open(filename) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
@@ -239,10 +239,8 @@ def search_header_for_hsx_values(filename):
|
|||||||
m = regex_def.match(line)
|
m = regex_def.match(line)
|
||||||
if m:
|
if m:
|
||||||
# Found HSE_VALUE or HSI_VALUE
|
# Found HSE_VALUE or HSI_VALUE
|
||||||
found = m.group(3)
|
found = m.group(2)
|
||||||
if "*" in found or "/" in found:
|
val = eval(found) // 1000000
|
||||||
found = eval(found)
|
|
||||||
val = int(found) // 1000000
|
|
||||||
if m.group(1) == "micropy_hw_hse_value":
|
if m.group(1) == "micropy_hw_hse_value":
|
||||||
hse = val
|
hse = val
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user