@@ -123,22 +123,21 @@ def generate_c_table(plli2s_table, hse, pllm):
123
123
print ("}" )
124
124
125
125
126
- def search_header (filename , re_include , re_define , lookup , val ):
127
- regex_include = re .compile (re_include )
126
+ def search_header (filename , re_define , lookup ):
128
127
regex_define = re .compile (re_define )
128
+ val = None
129
129
with open (filename ) as f :
130
130
for line in f :
131
131
line = line .strip ()
132
- m = regex_include .match (line )
133
- if m :
134
- # Search included file
135
- search_header (m .group (1 ), re_include , re_define , lookup , val )
136
- continue
137
132
m = regex_define .match (line )
138
133
if m :
139
134
# 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 )
140
139
if m .group (1 ) == lookup :
141
- val [ 0 ] = int (m . group ( 3 ) )
140
+ val = int (found )
142
141
return val
143
142
144
143
@@ -166,35 +165,37 @@ def main():
166
165
break
167
166
168
167
if mcu_series in mcu_support_plli2s :
169
- if len (argv ) != 2 :
168
+ if len (argv ) not in ( 1 , 2 ) :
170
169
print ("usage: pllvalues.py [-c] [-m <mcu_series>] <hse in MHz> <pllm in MHz>" )
171
170
sys .exit (1 )
172
171
173
172
if argv [0 ].startswith ("hse:" ):
174
- # extract HSE_VALUE from header file
175
- (hse ,) = search_header (
176
- argv [0 ][len ("hse:" ) :],
177
- r'#include "(boards/[A-Za-z0-9_./]+)"' ,
178
- r"#define +(HSE_VALUE) +\((\(uint32_t\))?([0-9]+)\)" ,
179
- "HSE_VALUE" ,
180
- [None ],
173
+ hse = int (argv [0 ][len ("hse:" ) :])
174
+
175
+ if argv [0 ].startswith ("pllm:" ):
176
+ pllm = int (argv [0 ][len ("pllm:" ) :])
177
+
178
+ if argv [0 ].startswith ("file:" ):
179
+ # extract hse value from processed header files
180
+ hse = search_header (
181
+ argv [0 ][len ("file:" ) :],
182
+ r"static.* (micropy_hw_hse_value) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;" ,
183
+ "micropy_hw_hse_value" ,
181
184
)
182
185
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
+ )
185
189
186
- if argv [0 ].startswith ("pllm:" ):
187
- # extract MICROPY_HW_CLK_PLLM from header file
188
- (pllm ,) = search_header (
189
- argv [0 ][len ("pllm:" ) :],
190
- r'#include "(boards/[A-Za-z0-9_./]+)"' ,
191
- r"#define +(MICROPY_HW_CLK_PLLM) +\((\(uint32_t\))?([0-9]+)\)" ,
192
- "MICROPY_HW_CLK_PLLM" ,
193
- [None ],
190
+ # extract pllm value from processed header files
191
+ pllm = search_header (
192
+ argv [0 ][len ("file:" ) :],
193
+ r"static.* (micropy_hw_clk_pllm) = +\(*(\(uint32_t\))?([0-9 +-/\*]+)\)*;" ,
194
+ "micropy_hw_clk_pllm" ,
194
195
)
195
196
if pllm is None :
196
197
raise ValueError (
197
- "%s does not contain a definition of MICROPY_HW_CLK_PLLM " % argv [0 ]
198
+ "%s does not contain a definition of micropy_hw_clk_pllm " % argv [0 ]
198
199
)
199
200
argv .pop (0 )
200
201
0 commit comments