@@ -137,8 +137,11 @@ def search_header(filename, re_include, re_define, lookup, val):
137137 m = regex_define .match (line )
138138 if m :
139139 # found lookup value
140+ found = m .group (3 )
141+ if "*" in found or "/" in found :
142+ found = eval (found )
140143 if m .group (1 ) == lookup :
141- val [0 ] = int (m . group ( 3 ) )
144+ val [0 ] = int (found )
142145 return val
143146
144147
@@ -170,31 +173,31 @@ def main():
170173 print ("usage: pllvalues.py [-c] [-m <mcu_series>] <hse in MHz> <pllm in MHz>" )
171174 sys .exit (1 )
172175
173- if argv [0 ].startswith ("hse :" ):
174- # extract HSE_VALUE from header file
176+ if argv [0 ].startswith ("file :" ):
177+ # extract HSE_VALUE and from header file
175178 (hse ,) = search_header (
176- argv [0 ][len ("hse :" ) :],
179+ argv [0 ][len ("file :" ) :],
177180 r'#include "(boards/[A-Za-z0-9_./]+)"' ,
178- r"#define +(HSE_VALUE) +\((\(uint32_t\))?([0-9]+)\)" ,
179- "HSE_VALUE " ,
181+ r"static.* (micropy_hw_hse_value) = +\(* (\(uint32_t\))?([0-9 +-/\* ]+)\)*; " ,
182+ "micropy_hw_hse_value " ,
180183 [None ],
181184 )
182185 if hse is None :
183- raise ValueError ("%s does not contain a definition of HSE_VALUE" % argv [0 ])
184- argv .pop (0 )
186+ raise ValueError (
187+ "%s does not contain a definition of micropy_hw_hse_value" % argv [0 ]
188+ )
185189
186- if argv [0 ].startswith ("pllm:" ):
187190 # extract MICROPY_HW_CLK_PLLM from header file
188191 (pllm ,) = search_header (
189- argv [0 ][len ("pllm :" ) :],
192+ argv [0 ][len ("file :" ) :],
190193 r'#include "(boards/[A-Za-z0-9_./]+)"' ,
191- r"#define +(MICROPY_HW_CLK_PLLM) +\((\(uint32_t\))?([0-9]+)\)" ,
192- "MICROPY_HW_CLK_PLLM " ,
194+ r"static.* (micropy_hw_clk_pllm) = +\(* (\(uint32_t\))?([0-9 +-/\* ]+)\)*; " ,
195+ "micropy_hw_clk_pllm " ,
193196 [None ],
194197 )
195198 if pllm is None :
196199 raise ValueError (
197- "%s does not contain a definition of MICROPY_HW_CLK_PLLM " % argv [0 ]
200+ "%s does not contain a definition of micropy_hw_clk_pllm " % argv [0 ]
198201 )
199202 argv .pop (0 )
200203
0 commit comments