@@ -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
@@ -166,35 +169,41 @@ def main():
166169 break
167170
168171 if mcu_series in mcu_support_plli2s :
169- if len (argv ) != 2 :
172+ if len (argv ) not in ( 1 , 2 ) :
170173 print ("usage: pllvalues.py [-c] [-m <mcu_series>] <hse in MHz> <pllm in MHz>" )
171174 sys .exit (1 )
172175
173176 if argv [0 ].startswith ("hse:" ):
174- # extract HSE_VALUE from header file
177+ hse = int (argv [0 ][len ("hse:" ) :])
178+
179+ if argv [0 ].startswith ("pllm:" ):
180+ pllm = int (argv [0 ][len ("pllm:" ) :])
181+
182+ if argv [0 ].startswith ("file:" ):
183+ # extract HSE_VALUE and from header file
175184 (hse ,) = search_header (
176- argv [0 ][len ("hse :" ) :],
185+ argv [0 ][len ("file :" ) :],
177186 r'#include "(boards/[A-Za-z0-9_./]+)"' ,
178- r"#define +(HSE_VALUE) +\((\(uint32_t\))?([0-9]+)\)" ,
179- "HSE_VALUE " ,
187+ r"static.* (micropy_hw_hse_value) = +\(* (\(uint32_t\))?([0-9 +-/\* ]+)\)*; " ,
188+ "micropy_hw_hse_value " ,
180189 [None ],
181190 )
182191 if hse is None :
183- raise ValueError ("%s does not contain a definition of HSE_VALUE" % argv [0 ])
184- argv .pop (0 )
192+ raise ValueError (
193+ "%s does not contain a definition of micropy_hw_hse_value" % argv [0 ]
194+ )
185195
186- if argv [0 ].startswith ("pllm:" ):
187196 # extract MICROPY_HW_CLK_PLLM from header file
188197 (pllm ,) = search_header (
189- argv [0 ][len ("pllm :" ) :],
198+ argv [0 ][len ("file :" ) :],
190199 r'#include "(boards/[A-Za-z0-9_./]+)"' ,
191- r"#define +(MICROPY_HW_CLK_PLLM) +\((\(uint32_t\))?([0-9]+)\)" ,
192- "MICROPY_HW_CLK_PLLM " ,
200+ r"static.* (micropy_hw_clk_pllm) = +\(* (\(uint32_t\))?([0-9 +-/\* ]+)\)*; " ,
201+ "micropy_hw_clk_pllm " ,
193202 [None ],
194203 )
195204 if pllm is None :
196205 raise ValueError (
197- "%s does not contain a definition of MICROPY_HW_CLK_PLLM " % argv [0 ]
206+ "%s does not contain a definition of micropy_hw_clk_pllm " % argv [0 ]
198207 )
199208 argv .pop (0 )
200209
0 commit comments