Skip to content

Commit 2d18050

Browse files
committed
ci(stm32wrapper): manage startup source files
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 2255d79 commit 2d18050

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

‎CI/update/stm32wrapper.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
# Out startup files
3636
CMSIS_Startupfile = ""
37+
CMSIS_Startupfile_source = ""
3738

3839
# Out system stm32 files
3940
system_stm32_outfile = ""
@@ -48,6 +49,7 @@
4849
ll_h_file = "stm32yyxx_ll_ppp.h"
4950
c_file = "stm32yyxx_feat.c"
5051
stm32_def_build_file = "stm32_def_build.h"
52+
startup_stm32yyxx_file = "startup_stm32yyxx.c"
5153
system_stm32_file = "system_stm32yyxx.c"
5254

5355
# Create the jinja2 environment.
@@ -60,6 +62,7 @@
6062
c_file_template = j2_env.get_template(c_file)
6163
dsp_file_template = Template('#include "../Source/{{ dsp_dir }}/{{ dsp_name }}"\n\n')
6264
stm32_def_build_template = j2_env.get_template(stm32_def_build_file)
65+
startup_stm32yyxx_template = j2_env.get_template(startup_stm32yyxx_file)
6366
system_stm32_template = j2_env.get_template(system_stm32_file)
6467

6568
# re
@@ -79,6 +82,7 @@ def checkConfig(arg_core, arg_cmsis):
7982
global CMSIS_DSP_lib_path
8083
global CMSIS_DSP_outSrc_path
8184
global CMSIS_Startupfile
85+
global CMSIS_Startupfile_source
8286
global system_path
8387
global system_stm32_outfile
8488
global HALoutSrc_path
@@ -100,6 +104,9 @@ def checkConfig(arg_core, arg_cmsis):
100104
CMSIS_DSP_lib_path = core_path / "libraries" / "CMSIS_DSP"
101105
CMSIS_DSP_outSrc_path = CMSIS_DSP_lib_path / "src"
102106
CMSIS_Startupfile = core_path / "cores" / "arduino" / "stm32" / stm32_def_build_file
107+
CMSIS_Startupfile_source = (
108+
core_path / "cores" / "arduino" / "stm32" / startup_stm32yyxx_file
109+
)
103110
system_stm32_outfile = SrcWrapper_path / "src" / "stm32" / system_stm32_file
104111

105112
HALoutSrc_path = SrcWrapper_path / "src" / "HAL"
@@ -149,6 +156,36 @@ def printCMSISStartup(log):
149156
else:
150157
if log:
151158
print("No startup files found!")
159+
# v2
160+
filelist = sorted(CMSIS_Device_ST_path.glob("**/startup_*.c"))
161+
filelist = [pth.name for pth in filelist]
162+
if len(filelist):
163+
if log:
164+
print(f"Number of source startup files: {len(filelist)}")
165+
# Some mcu have two startup files
166+
# Ex: WL one for cm0plus and one for cm4
167+
# In that case this is the same value line so add an extra defined
168+
# to use the correct one.
169+
group_startup_list = [
170+
list(g) for _, g in groupby(filelist, lambda x: re.split("_|\\.", x)[1])
171+
]
172+
cmsis_list = []
173+
for fn_list in group_startup_list:
174+
if len(fn_list) == 1:
175+
valueline = re.split("_|\\.", fn_list[0])
176+
vline = valueline[1].upper().replace("X", "x")
177+
cmsis_list.append({"vline": vline, "fn": fn_list[0], "cm": ""})
178+
else:
179+
for fn in fn_list:
180+
valueline = re.split("_|\\.", fn)
181+
vline = valueline[1].upper().replace("X", "x")
182+
cm = valueline[2].upper()
183+
cmsis_list.append({"vline": vline, "fn": fn, "cm": cm})
184+
with open(CMSIS_Startupfile_source, "w", newline="\n") as out_file:
185+
out_file.write(startup_stm32yyxx_template.render(cmsis_list=cmsis_list))
186+
else:
187+
if log:
188+
print("No startup files found!")
152189

153190

154191
def printSystemSTM32(log):
@@ -181,6 +218,8 @@ def wrap(arg_core, arg_cmsis, log):
181218
createFolder(LLoutInc_path)
182219
if CMSIS_Startupfile.is_file():
183220
CMSIS_Startupfile.unlink()
221+
if CMSIS_Startupfile_source.is_file():
222+
CMSIS_Startupfile_source.unlink()
184223
all_ll_h_list = []
185224
# key: peripheral, value: series list
186225
ll_h_dict = {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef _STARTUP_STM32YYXX_C_
2+
#define _STARTUP_STM32YYXX_C_
3+
4+
#if defined(USE_HALV2_DRIVER)
5+
{% for cmsis in cmsis_list %}
6+
{% if loop.first %}
7+
#if defined({{ cmsis.vline }})
8+
{% else %}
9+
#elif defined({{ cmsis.vline }}){{ " && defined(USE_{}_STARTUP_FILE)".format(cmsis.cm) if cmsis.cm }}
10+
{% endif %}
11+
#include "{{ cmsis.fn }}"
12+
{% endfor %}
13+
#else
14+
#if !defined(CUSTOM_STARTUP_FILE)
15+
#error "No CMSIS startup file defined, custom one should be used"
16+
#else
17+
#include CUSTOM_STARTUP_FILE
18+
#endif
19+
#endif
20+
#endif /* USE_HALV2_DRIVER */
21+
#endif /* _STARTUP_STM32YYXX_C_ */

‎CI/update/templates/stm32_def_build.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _STM32_DEF_BUILD_
22
#define _STM32_DEF_BUILD_
33

4-
#if !defined(CMSIS_STARTUP_FILE) && !defined(CUSTOM_STARTUP_FILE)
4+
#if !defined(USE_HALV2_DRIVER) && !defined(CMSIS_STARTUP_FILE) && !defined(CUSTOM_STARTUP_FILE)
55
{% for cmsis in cmsis_list %}
66
{% if loop.first %}
77
#if defined({{ cmsis.vline }})
@@ -15,6 +15,6 @@
1515
#endif
1616
#else
1717
#warning "No CMSIS startup file defined, custom one should be used"
18-
#endif /* !CMSIS_STARTUP_FILE && !CUSTOM_STARTUP_FILE */
18+
#endif /* !USE_HALV2_DRIVER && !CMSIS_STARTUP_FILE && !CUSTOM_STARTUP_FILE */
1919
#endif /* _STM32_DEF_BUILD_ */
2020

0 commit comments

Comments
 (0)