Skip to content

Commit d0e8845

Browse files
committed
script: smt32wrapper: handle multiple startup files
Some mcu have two startup files for the same value line Ex: STM32WL can have one for cm0plus and one for cm4 In that case this is the same value line so add an extra definition to use the correct one. This defined will have to be defined in the boards.txt Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent f1d1432 commit d0e8845

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

CI/utils/stm32wrapper.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import re
3+
from itertools import groupby
34
from jinja2 import Environment, FileSystemLoader, Template
45
from pathlib import Path
56
from stm32common import createFolder, deleteFolder, genSTM32List
@@ -102,16 +103,29 @@ def checkConfig(arg_core, arg_cmsis):
102103

103104
def printCMSISStartup(log):
104105
filelist = sorted(CMSIS_Device_ST_path.glob("**/startup_*.s"))
106+
filelist = [pth.name for pth in filelist]
105107
if len(filelist):
106108
if log:
107109
print("Number of startup files: {}".format(len(filelist)))
110+
# Some mcu have two startup files
111+
# Ex: WL one for cm0plus and one for cm4
112+
# In that case this is the same value line so add an extra defined
113+
# to use the correct one.
114+
group_startup_list = [
115+
list(g) for _, g in groupby(filelist, lambda x: re.split("_|\\.", x)[1])
116+
]
108117
cmsis_list = []
109-
for fp in filelist:
110-
# File name
111-
fn = fp.name
112-
valueline = re.split("_|\\.", fn)
113-
vline = valueline[1].upper().replace("X", "x")
114-
cmsis_list.append({"vline": vline, "fn": fn})
118+
for fn_list in group_startup_list:
119+
if len(fn_list) == 1:
120+
valueline = re.split("_|\\.", fn_list[0])
121+
vline = valueline[1].upper().replace("X", "x")
122+
cmsis_list.append({"vline": vline, "fn": fn_list[0], "cm": ""})
123+
else:
124+
for fn in fn_list:
125+
valueline = re.split("_|\\.", fn)
126+
vline = valueline[1].upper().replace("X", "x")
127+
cm = valueline[2].upper()
128+
cmsis_list.append({"vline": vline, "fn": fn, "cm": cm})
115129
out_file = open(CMSIS_Startupfile, "w", newline="\n")
116130
out_file.write(stm32_def_build_template.render(cmsis_list=cmsis_list))
117131
out_file.close()

CI/utils/templates/stm32_def_build.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#if !defined(CMSIS_STARTUP_FILE) && !defined(CUSTOM_STARTUP_FILE)
55
{% for cmsis in cmsis_list %}
66
{% if loop.first %}
7-
#if defined({{cmsis.vline}})
7+
#if defined({{ cmsis.vline }})
88
{% else %}
9-
#elif defined({{cmsis.vline}})
9+
#elif defined({{ cmsis.vline }}){{ " && defined(USE_{}_STARTUP_FILE)".format(cmsis.cm) if cmsis.cm }}
1010
{% endif %}
11-
#define CMSIS_STARTUP_FILE "{{cmsis.fn}}"
11+
#define CMSIS_STARTUP_FILE "{{ cmsis.fn }}"
1212
{% endfor %}
1313
#else
1414
#error UNKNOWN CHIP

0 commit comments

Comments
 (0)