Skip to content

Commit 594ee29

Browse files
authored
Merge pull request #3024 from fpistm/fix_wrapper
fix(wrapper): enhance util(s) file management
2 parents dc53815 + 597f70f commit 594ee29

10 files changed

Lines changed: 87 additions & 55 deletions

File tree

‎CI/update/stm32wrapper.py‎

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,17 @@
5858
)
5959
all_ll_header_file_template = j2_env.get_template(all_ll_h_file)
6060
ll_h_file_template = j2_env.get_template(ll_h_file)
61-
util_h_file_template = j2_env.get_template("stm32yyxx_util_ppp.h")
61+
utils_h_file_template = j2_env.get_template("stm32yyxx_utils_ppp.h")
6262
c_file_template = j2_env.get_template(c_file)
6363
dsp_file_template = Template('#include "../Source/{{ dsp_dir }}/{{ dsp_name }}"\n\n')
6464
stm32_def_build_template = j2_env.get_template(stm32_def_build_file)
6565
startup_stm32yyxx_template = j2_env.get_template(startup_stm32yyxx_file)
6666
system_stm32_template = j2_env.get_template(system_stm32_file)
6767

6868
# re
69-
feat_c_regex = re.compile(r"stm32[^_]+_(.*).c$")
69+
feat_c_regex = re.compile(r"stm32[^_]*_(.*).c$")
7070
feat_h_regex = re.compile(r"stm32[^_]+_(.*).h$")
71-
feat_util_h_regex = re.compile(r"stm32[^_]+_util_(.*).h$")
72-
feat_utils_h_regex = re.compile(r"stm32_utils_(.*).h$")
71+
feat_utils_h_regex = re.compile(r"stm32[^_]*_utils?_(.*).h$")
7372

7473

7574
def checkConfig(arg_core, arg_cmsis):
@@ -225,7 +224,7 @@ def wrap(arg_core, arg_cmsis, log):
225224
ll_h_dict = {}
226225
ll_c_dict = {}
227226
hal_c_dict = {}
228-
util_h_dict = {}
227+
utils_h_dict = {}
229228

230229
# Search all files for each series
231230
for series in stm32_series:
@@ -238,9 +237,10 @@ def wrap(arg_core, arg_cmsis, log):
238237
print(f"Generating for {series}...")
239238
lower = series.lower()
240239

241-
# Search stm32yyxx_[hal|ll]*.c file
242-
filelist = src.glob(f"**/stm32{lower}{nx}_*.c")
240+
# Search stm32yyxx_[hal|ll|utils?]*.c or stm32_utils?_*.c file
241+
filelist = src.glob("**/stm32*.c")
243242
for fp in filelist:
243+
is_series_in_fn = fp.name.startswith(f"stm32{lower}{nx}_")
244244
legacy = fp.parent.name == "Legacy"
245245
# File name
246246
fn = fp.name
@@ -258,26 +258,37 @@ def wrap(arg_core, arg_cmsis, log):
258258
current_list = ll_c_dict.pop(feat)
259259
if current_list[-1][0] == lower:
260260
current_list.pop()
261-
current_list.append((lower, legacy, stm32_dict[series]))
261+
current_list.append(
262+
(lower, legacy, stm32_dict[series], is_series_in_fn)
263+
)
262264
ll_c_dict[feat] = current_list
263265
else:
264-
ll_c_dict[feat].append((lower, legacy, stm32_dict[series]))
266+
ll_c_dict[feat].append(
267+
(lower, legacy, stm32_dict[series], is_series_in_fn)
268+
)
265269
else:
266-
ll_c_dict[feat] = [(lower, legacy, stm32_dict[series])]
270+
ll_c_dict[feat] = [
271+
(lower, legacy, stm32_dict[series], is_series_in_fn)
272+
]
267273
else:
268274
if feat in hal_c_dict:
269275
if legacy:
270276
# Change legacy value if exists
271277
current_list = hal_c_dict.pop(feat)
272278
if current_list[-1][0] == lower:
273279
current_list.pop()
274-
current_list.append((lower, legacy, stm32_dict[series]))
280+
current_list.append(
281+
(lower, legacy, stm32_dict[series], is_series_in_fn)
282+
)
275283
hal_c_dict[feat] = current_list
276284
else:
277-
hal_c_dict[feat].append((lower, legacy, stm32_dict[series]))
285+
hal_c_dict[feat].append(
286+
(lower, legacy, stm32_dict[series], is_series_in_fn)
287+
)
278288
else:
279-
hal_c_dict[feat] = [(lower, legacy, stm32_dict[series])]
280-
289+
hal_c_dict[feat] = [
290+
(lower, legacy, stm32_dict[series], is_series_in_fn)
291+
]
281292
# Search stm32yyxx_ll_*.h file
282293
filelist = inc.glob(f"stm32{lower}{nx}_ll_*.h")
283294
for fp in filelist:
@@ -294,33 +305,26 @@ def wrap(arg_core, arg_cmsis, log):
294305
else:
295306
ll_h_dict[feature] = [(lower, stm32_dict[series])]
296307
# Search stm32yyxx_util_.*.h file
297-
filelist = inc.glob(f"stm32{lower}{nx}_util_*.h")
298-
for fp in filelist:
299-
# File name
300-
fn = fp.name
301-
found = feat_util_h_regex.match(fn)
302-
if not found:
303-
continue
304-
feature = found.group(1)
305-
# Add to util_h_dict to generate a header file for it
306-
if feature in util_h_dict:
307-
util_h_dict[feature].append((lower, stm32_dict[series], False))
308-
else:
309-
util_h_dict[feature] = [(lower, stm32_dict[series], False)]
310-
# Search stm32yyxx_util_.*.h file
311-
filelist = inc.glob(f"stm32_utils_*.h")
308+
filelist = list(inc.glob("stm32*_util_*.h"))
309+
filelist += list(inc.glob("stm32*_utils_*.h"))
312310
for fp in filelist:
313311
# File name
314312
fn = fp.name
315313
found = feat_utils_h_regex.match(fn)
314+
is_series_in_fn = fp.name.startswith(f"stm32{lower}{nx}_")
316315
if not found:
317316
continue
318317
feature = found.group(1)
319-
# Add to util_h_dict to generate a header file for it
320-
if feature in util_h_dict:
321-
util_h_dict[feature].append((lower, stm32_dict[series], True))
318+
utils = "_utils_" in fn
319+
# Add to utils_h_dict to generate a header file for it
320+
if feature in utils_h_dict:
321+
utils_h_dict[feature].append(
322+
(lower, stm32_dict[series], is_series_in_fn, utils)
323+
)
322324
else:
323-
util_h_dict[feature] = [(lower, stm32_dict[series], True)]
325+
utils_h_dict[feature] = [
326+
(lower, stm32_dict[series], is_series_in_fn, utils)
327+
]
324328

325329
# Generate stm32yyxx_hal_*.c file
326330
for key, value in hal_c_dict.items():
@@ -343,11 +347,11 @@ def wrap(arg_core, arg_cmsis, log):
343347
out_file.write(ll_h_file_template.render(feat=key, serieslist=value))
344348
if log:
345349
print("done")
346-
# Generate stm32yyxx_util_*.h file
347-
for key, value in util_h_dict.items():
348-
filepath = SrcWrapper_path / "inc" / f"stm32yyxx_util_{key}.h"
350+
# Generate stm32yyxx_utils_*.h file
351+
for key, value in utils_h_dict.items():
352+
filepath = SrcWrapper_path / "inc" / f"stm32yyxx_utils_{key}.h"
349353
with open(filepath, "w", newline="\n") as out_file:
350-
out_file.write(util_h_file_template.render(feat=key, serieslist=value))
354+
out_file.write(utils_h_file_template.render(feat=key, serieslist=value))
351355
# Filter all LL header file
352356
all_ll_h_list = sorted(set(all_ll_h_list))
353357
# Generate the all LL header file

‎CI/update/templates/stm32yyxx_feat.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#pragma GCC diagnostic push
33
#pragma GCC diagnostic ignored "-Wunused-parameter"
44

5-
{% for series, legacy, nx in serieslist %}
5+
{% for series, legacy, nx, is_series_in_fn in serieslist %}
66
{% if loop.first %}
77
#ifdef STM32{{series.upper()}}{{nx}}
88
{% else %}
@@ -11,7 +11,11 @@
1111
{% if legacy %}
1212
#include "Legacy/stm32{{series}}{{nx}}_{{feat}}.c"
1313
{% endif %}
14+
{% if is_series_in_fn %}
1415
#include "stm32{{series}}{{nx}}_{{feat}}.c"
16+
{% else %}
17+
#include "stm32_{{feat}}.c"
18+
{% endif %}
1519
{% if loop.last %}
1620
#endif
1721
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _STM32YYXX_UTIL_{{feat.upper()}}_H_
2-
#define _STM32YYXX_UTIL_{{feat.upper()}}_H_
1+
#ifndef _STM32YYXX_UTILS_{{feat.upper()}}_H_
2+
#define _STM32YYXX_UTILS_{{feat.upper()}}_H_
33
/* LL raised several warnings, ignore them */
44
#pragma GCC diagnostic push
55
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -8,21 +8,21 @@
88
#pragma GCC diagnostic ignored "-Wregister"
99
#endif
1010

11-
{% for series, nx, halv2 in serieslist %}
11+
{% for series, nx, is_series_in_fn, utils in serieslist %}
1212
{% if loop.first %}
1313
#ifdef STM32{{series.upper()}}{{nx}}
1414
{% else %}
1515
#elif STM32{{series.upper()}}{{nx}}
1616
{% endif %}
17-
{% if halv2 %}
18-
#include "stm32_utils_{{feat}}.h"
17+
{% if is_series_in_fn %}
18+
#include "stm32{{series}}{{nx}}_{{'utils' if utils else 'util'}}_{{feat}}.h"
1919
{% else %}
20-
#include "stm32{{series}}{{nx}}_util_{{feat}}.h"
20+
#include "stm32_{{'utils' if utils else 'util'}}_{{feat}}.h"
2121
{% endif %}
2222
{% if loop.last %}
2323
#endif
2424
{% endif %}
2525
{% endfor %}
2626
#pragma GCC diagnostic pop
27-
#endif /* _STM32YYXX_UTIL_{{feat.upper()}}_H_ */
27+
#endif /* _STM32YYXX_UTILS_{{feat.upper()}}_H_ */
2828

‎libraries/I3C/src/I3C.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#if defined(USE_HALV2_DRIVER)
88
#warning "I3C library is not yet compatible with HALv2 driver."
99
#else
10-
#include "stm32yyxx_util_i3c.h"
10+
#include "stm32yyxx_utils_i3c.h"
1111

1212
// ============================================================================
1313
// Descriptors, configuration structures, and enums

libraries/SrcWrapper/inc/stm32yyxx_util_fdcan.h renamed to libraries/SrcWrapper/inc/stm32yyxx_utils_fdcan.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _STM32YYXX_UTIL_FDCAN_H_
2-
#define _STM32YYXX_UTIL_FDCAN_H_
1+
#ifndef _STM32YYXX_UTILS_FDCAN_H_
2+
#define _STM32YYXX_UTILS_FDCAN_H_
33
/* LL raised several warnings, ignore them */
44
#pragma GCC diagnostic push
55
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -12,4 +12,4 @@
1212
#include "stm32_utils_fdcan.h"
1313
#endif
1414
#pragma GCC diagnostic pop
15-
#endif /* _STM32YYXX_UTIL_FDCAN_H_ */
15+
#endif /* _STM32YYXX_UTILS_FDCAN_H_ */

libraries/SrcWrapper/inc/stm32yyxx_util_i2c.h renamed to libraries/SrcWrapper/inc/stm32yyxx_utils_i2c.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _STM32YYXX_UTIL_I2C_H_
2-
#define _STM32YYXX_UTIL_I2C_H_
1+
#ifndef _STM32YYXX_UTILS_I2C_H_
2+
#define _STM32YYXX_UTILS_I2C_H_
33
/* LL raised several warnings, ignore them */
44
#pragma GCC diagnostic push
55
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -12,4 +12,4 @@
1212
#include "stm32_utils_i2c.h"
1313
#endif
1414
#pragma GCC diagnostic pop
15-
#endif /* _STM32YYXX_UTIL_I2C_H_ */
15+
#endif /* _STM32YYXX_UTILS_I2C_H_ */

libraries/SrcWrapper/inc/stm32yyxx_util_i3c.h renamed to libraries/SrcWrapper/inc/stm32yyxx_utils_i3c.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _STM32YYXX_UTIL_I3C_H_
2-
#define _STM32YYXX_UTIL_I3C_H_
1+
#ifndef _STM32YYXX_UTILS_I3C_H_
2+
#define _STM32YYXX_UTILS_I3C_H_
33
/* LL raised several warnings, ignore them */
44
#pragma GCC diagnostic push
55
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -16,4 +16,4 @@
1616
#include "stm32u3xx_util_i3c.h"
1717
#endif
1818
#pragma GCC diagnostic pop
19-
#endif /* _STM32YYXX_UTIL_I3C_H_ */
19+
#endif /* _STM32YYXX_UTILS_I3C_H_ */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* HAL raised several warnings, ignore them */
2+
#pragma GCC diagnostic push
3+
#pragma GCC diagnostic ignored "-Wunused-parameter"
4+
5+
#ifdef STM32C5xx
6+
#include "stm32_utils_fdcan.c"
7+
#endif
8+
#pragma GCC diagnostic pop
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* HAL raised several warnings, ignore them */
2+
#pragma GCC diagnostic push
3+
#pragma GCC diagnostic ignored "-Wunused-parameter"
4+
5+
#ifdef STM32C5xx
6+
#include "stm32_utils_i2c.c"
7+
#endif
8+
#pragma GCC diagnostic pop
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* HAL raised several warnings, ignore them */
2+
#pragma GCC diagnostic push
3+
#pragma GCC diagnostic ignored "-Wunused-parameter"
4+
5+
#ifdef STM32C5xx
6+
#include "stm32_utils_i3c.c"
7+
#endif
8+
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)