Skip to content

Commit 3c1722e

Browse files
committed
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 <[email protected]>
1 parent 7924b31 commit 3c1722e

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

ports/stm32/boards/plli2svalues.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,9 @@ def search_header(filename, re_define, lookup):
132132
m = regex_define.match(line)
133133
if m:
134134
# found lookup value
135-
found = m.group(3)
136-
if "*" in found or "/" in found:
137-
# process define using multiply or divide to calculate value
138-
found = eval(found)
135+
found = m.group(2)
139136
if m.group(1) == lookup:
140-
val = int(found)
137+
val = eval(found)
141138
return val
142139

143140

@@ -179,7 +176,7 @@ def main():
179176
# extract hse value from processed header files
180177
hse = search_header(
181178
argv[0][len("file:") :],
182-
r"static.* (micropy_hw_hse_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;",
179+
r"static.* (micropy_hw_hse_value) = +([0-9 +-/\*()]+);",
183180
"micropy_hw_hse_value",
184181
)
185182
if hse is None:
@@ -190,7 +187,7 @@ def main():
190187
# extract pllm value from processed header files
191188
pllm = search_header(
192189
argv[0][len("file:") :],
193-
r"static.* (micropy_hw_clk_pllm) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;",
190+
r"static.* (micropy_hw_clk_pllm) = +([0-9 +-/\*()]+);",
194191
"micropy_hw_clk_pllm",
195192
)
196193
if pllm is None:

ports/stm32/boards/pllvalues.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,16 @@ def print_table(hse, valid_plls):
231231
def search_header_for_hsx_values(filename):
232232
hse = hsi = None
233233
regex_def = re.compile(
234-
r"static.* +(micropy_hw_hs[ei]_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;",
234+
r"static.* +(micropy_hw_hs[ei]_value) = +([0-9 +-/\*()]+);",
235235
)
236236
with open(filename) as f:
237237
for line in f:
238238
line = line.strip()
239239
m = regex_def.match(line)
240240
if m:
241241
# Found HSE_VALUE or HSI_VALUE
242-
found = m.group(3)
243-
if "*" in found or "/" in found:
244-
found = eval(found)
245-
val = int(found) // 1000000
242+
found = m.group(2)
243+
val = eval(found) // 1000000
246244
if m.group(1) == "micropy_hw_hse_value":
247245
hse = val
248246
else:

0 commit comments

Comments
 (0)