Skip to content

Commit 0793041

Browse files
committed
fix(ci): source wrapping in stm32wrapper
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 35ab6ad commit 0793041

3 files changed

Lines changed: 37 additions & 45 deletions

File tree

CI/update/stm32wrapper.py

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
templates_dir = script_path / "templates"
4848
all_ll_h_file = "stm32yyxx_ll.h"
4949
ll_h_file = "stm32yyxx_ll_ppp.h"
50-
c_file = "stm32yyxx_zz_ppp.c"
50+
c_file = "stm32yyxx_feat.c"
5151
stm32_def_build_file = "stm32_def_build.h"
5252
system_stm32_file = "system_stm32yyxx.c"
5353

@@ -63,8 +63,8 @@
6363
system_stm32_template = j2_env.get_template(system_stm32_file)
6464

6565
# re
66-
peripheral_c_regex = re.compile(r"stm32\w+_[h]?[al][l]_(.*).c$")
67-
peripheral_h_regex = re.compile(r"stm32\w+_[h]?[al][l]_(.*).h$")
66+
feat_c_regex = re.compile(r"stm32[^_]+_(.*).c$")
67+
feat_h_regex = re.compile(r"stm32[^_]+_(.*).h$")
6868

6969

7070
def checkConfig(arg_core, arg_cmsis):
@@ -205,79 +205,75 @@ def wrap(arg_core, arg_cmsis, log):
205205
legacy = fp.parent.name == "Legacy"
206206
# File name
207207
fn = fp.name
208-
found = peripheral_c_regex.match(fn)
209208
if "_template" in fn:
210209
continue
211-
peripheral = found.group(1) if found else "hal"
210+
found = feat_c_regex.match(fn)
211+
if not found:
212+
print(f"File {fn} does not match the expected pattern!")
213+
continue
214+
feat = found.group(1)
212215
if "_ll_" in fn:
213-
if peripheral in ll_c_dict:
216+
if feat in ll_c_dict:
214217
if legacy:
215218
# Change legacy value if exists
216-
current_list = ll_c_dict.pop(peripheral)
219+
current_list = ll_c_dict.pop(feat)
217220
if current_list[-1][0] == lower:
218221
current_list.pop()
219222
current_list.append((lower, legacy, stm32_dict[series]))
220-
ll_c_dict[peripheral] = current_list
223+
ll_c_dict[feat] = current_list
221224
else:
222-
ll_c_dict[peripheral].append(
223-
(lower, legacy, stm32_dict[series])
224-
)
225+
ll_c_dict[feat].append((lower, legacy, stm32_dict[series]))
225226
else:
226-
ll_c_dict[peripheral] = [(lower, legacy, stm32_dict[series])]
227+
ll_c_dict[feat] = [(lower, legacy, stm32_dict[series])]
227228
else:
228-
if peripheral in hal_c_dict:
229+
if feat in hal_c_dict:
229230
if legacy:
230231
# Change legacy value if exists
231-
current_list = hal_c_dict.pop(peripheral)
232+
current_list = hal_c_dict.pop(feat)
232233
if current_list[-1][0] == lower:
233234
current_list.pop()
234235
current_list.append((lower, legacy, stm32_dict[series]))
235-
hal_c_dict[peripheral] = current_list
236+
hal_c_dict[feat] = current_list
236237
else:
237-
hal_c_dict[peripheral].append(
238-
(lower, legacy, stm32_dict[series])
239-
)
238+
hal_c_dict[feat].append((lower, legacy, stm32_dict[series]))
240239
else:
241-
hal_c_dict[peripheral] = [(lower, legacy, stm32_dict[series])]
240+
hal_c_dict[feat] = [(lower, legacy, stm32_dict[series])]
242241

243242
# Search stm32yyxx_ll_*.h file
244243
filelist = inc.glob(f"stm32{lower}{nx}_ll_*.h")
245244
for fp in filelist:
246245
# File name
247246
fn = fp.name
248-
found = peripheral_h_regex.match(fn)
247+
found = feat_h_regex.match(fn)
249248
if not found:
250249
continue
251-
peripheral = found.group(1)
250+
feature = found.group(1)
252251
# Amend all LL header list
253252
all_ll_h_list.append(fn.replace(f"{lower}{nx}", "yyxx"))
254-
if peripheral in ll_h_dict:
255-
ll_h_dict[peripheral].append((lower, stm32_dict[series]))
253+
if feature in ll_h_dict:
254+
ll_h_dict[feature].append((lower, stm32_dict[series]))
256255
else:
257-
ll_h_dict[peripheral] = [(lower, stm32_dict[series])]
256+
ll_h_dict[feature] = [(lower, stm32_dict[series])]
258257

259258
# Generate stm32yyxx_hal_*.c file
260259
for key, value in hal_c_dict.items():
261-
if key == "hal":
262-
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("_ppp", "")
263-
else:
264-
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("ppp", key)
260+
filepath = HALoutSrc_path / f"stm32yyxx_{key}.c"
265261
with open(filepath, "w", newline="\n") as out_file:
266262
out_file.write(
267-
c_file_template.render(periph=key, type="hal", serieslist=value)
263+
c_file_template.render(feat=key, type="HAL", serieslist=value)
268264
)
269265
# Generate stm32yyxx_ll_*.c file
270266
for key, value in ll_c_dict.items():
271-
filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace("ppp", key)
267+
filepath = LLoutSrc_path / f"stm32yyxx_{key}.c"
272268
with open(filepath, "w", newline="\n") as out_file:
273269
out_file.write(
274-
c_file_template.render(periph=key, type="ll", serieslist=value)
270+
c_file_template.render(feat=key, type="LL", serieslist=value)
275271
)
276272
# Generate stm32yyxx_ll_*.h file
277273
for key, value in ll_h_dict.items():
278-
filepath = LLoutInc_path / ll_h_file.replace("ppp", key)
274+
filepath = LLoutInc_path / f"stm32yyxx_{key}.h"
279275
with open(filepath, "w", newline="\n") as out_file:
280-
out_file.write(ll_h_file_template.render(periph=key, serieslist=value))
276+
out_file.write(ll_h_file_template.render(feat=key, serieslist=value))
281277
if log:
282278
print("done")
283279

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* {{type.upper()}} raised several warnings, ignore them */
1+
/* {{type}} raised several warnings, ignore them */
22
#pragma GCC diagnostic push
33
#pragma GCC diagnostic ignored "-Wunused-parameter"
44

@@ -8,14 +8,10 @@
88
{% else %}
99
#elif STM32{{series.upper()}}{{nx}}
1010
{% endif %}
11-
{% if type == periph %}
12-
#include "stm32{{series}}{{nx}}_{{type}}.c"
13-
{% else %}
14-
{% if legacy %}
15-
#include "Legacy/stm32{{series}}{{nx}}_{{type}}_{{periph}}.c"
16-
{% endif %}
17-
#include "stm32{{series}}{{nx}}_{{type}}_{{periph}}.c"
11+
{% if legacy %}
12+
#include "Legacy/stm32{{series}}{{nx}}_{{feat}}.c"
1813
{% endif %}
14+
#include "stm32{{series}}{{nx}}_{{feat}}.c"
1915
{% if loop.last %}
2016
#endif
2117
{% endif %}

CI/update/templates/stm32yyxx_ll_ppp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _STM32YYXX_LL_{{periph.upper()}}_H_
2-
#define _STM32YYXX_LL_{{periph.upper()}}_H_
1+
#ifndef _STM32YYXX_{{feat.upper()}}_H_
2+
#define _STM32YYXX_{{feat.upper()}}_H_
33
/* LL raised several warnings, ignore them */
44
#pragma GCC diagnostic push
55
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -14,11 +14,11 @@
1414
{% else %}
1515
#elif STM32{{series.upper()}}{{nx}}
1616
{% endif %}
17-
#include "stm32{{series}}{{nx}}_ll_{{periph}}.h"
17+
#include "stm32{{series}}{{nx}}_{{feat}}.h"
1818
{% if loop.last %}
1919
#endif
2020
{% endif %}
2121
{% endfor %}
2222
#pragma GCC diagnostic pop
23-
#endif /* _STM32YYXX_LL_{{periph.upper()}}_H_ */
23+
#endif /* _STM32YYXX_{{feat.upper()}}_H_ */
2424

0 commit comments

Comments
 (0)