Skip to content

Commit 0c72de2

Browse files
committed
[stm2variant] Add board_entry.txt
This will help to add generic board entry. Note: upload.maximum_size and product_line have to be verified and changed if needed. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 6897e8d commit 0c72de2

File tree

2 files changed

+127
-21
lines changed

2 files changed

+127
-21
lines changed

CI/utils/stm32variant.py

Lines changed: 111 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
tim_inst_list = [] # TIMx instance
4949
usb_inst = {"usb": "", "otg_fs": "", "otg_hs": ""}
5050
mcu_family = ""
51+
mcu_refname = ""
52+
mcu_flash = []
53+
mcu_ram = ""
54+
55+
# Cube information
56+
startup_dict = {}
5157

5258
# format
5359
# Peripheral
@@ -59,19 +65,31 @@
5965

6066

6167
# mcu file parsing
62-
def parse_IP_file():
68+
def parse_mcu_file():
6369
global gpiofile
6470
global mcu_family
71+
global mcu_refname
72+
global mcu_ram
73+
6574
tim_regex = r"^(TIM\d+)$"
6675
usb_regex = r"^(USB(?!PD|_HOST|_DEVICE).*)$"
6776
gpiofile = ""
6877
del tim_inst_list[:]
78+
del mcu_flash[:]
6979
usb_inst["usb"] = ""
7080
usb_inst["otg_fs"] = ""
7181
usb_inst["otg_hs"] = ""
7282

7383
mcu_node = xml_mcu.getElementsByTagName("Mcu")[0]
7484
mcu_family = mcu_node.attributes["Family"].value
85+
if mcu_family.endswith("+"):
86+
mcu_family = mcu_family[:-1]
87+
mcu_refname = mcu_node.attributes["RefName"].value
88+
89+
mcu_ram = int(mcu_node.getElementsByTagName("Ram")[0].firstChild.nodeValue) * 1024
90+
flash_node = mcu_node.getElementsByTagName("Flash")
91+
for f in flash_node:
92+
mcu_flash.append(int(f.firstChild.nodeValue) * 1024)
7593

7694
itemlist = xml_mcu.getElementsByTagName("IP")
7795
for s in itemlist:
@@ -95,7 +113,7 @@ def parse_IP_file():
95113

96114

97115
def get_gpio_af_num(pintofind, iptofind):
98-
if "STM32F10" in mcu_file.stem:
116+
if "STM32F1" in mcu_family:
99117
return get_gpio_af_numF1(pintofind, iptofind)
100118
# DBG print ('pin to find ' + pintofind)
101119
i = 0
@@ -325,7 +343,7 @@ def adc_pinmap():
325343
wpin = []
326344
# For STM32L47xxx/48xxx, it is necessary to configure
327345
# the GPIOx_ASCR register
328-
if re.match("STM32L4[78]+", mcu_file.stem):
346+
if re.match("STM32L4[78]+", mcu_refname):
329347
default_mode = "STM_MODE_ANALOG_ADC_CONTROL"
330348
else:
331349
default_mode = "STM_MODE_ANALOG"
@@ -512,7 +530,7 @@ def uart_pinmap(lst):
512530
inst = p[2].split("_")[0]
513531
winst.append(len(inst))
514532
wpin.append(len(p[0]))
515-
if "STM32F10" in mcu_file.stem and lst == uartrx_list:
533+
if "STM32F1" in mcu_family and lst == uartrx_list:
516534
mode = "STM_MODE_INPUT"
517535
else:
518536
mode = "STM_MODE_AF_PP"
@@ -598,7 +616,7 @@ def can_pinmap(lst):
598616
inst += "1"
599617
winst.append(len(inst))
600618
wpin.append(len(p[0]))
601-
if "STM32F10" in mcu_file.stem and lst == canrd_list:
619+
if "STM32F1" in mcu_family and lst == canrd_list:
602620
mode = "STM_MODE_INPUT"
603621
else:
604622
mode = "STM_MODE_AF_PP"
@@ -1106,7 +1124,7 @@ def timer_variant():
11061124
return dict(tone=tone, servo=servo)
11071125

11081126

1109-
def print_variant(generic_def):
1127+
def print_variant(generic_list):
11101128
variant_h_template = j2_env.get_template(variant_h_filename)
11111129
variant_cpp_template = j2_env.get_template(variant_cpp_filename)
11121130

@@ -1192,7 +1210,7 @@ def print_variant(generic_def):
11921210
variant_h_file.write(
11931211
variant_h_template.render(
11941212
year=datetime.datetime.now().year,
1195-
generic_def=generic_def,
1213+
generic_list=generic_list,
11961214
pins_number_list=pins_number_list,
11971215
alt_pins_list=alt_pins_list,
11981216
waltpin=max(waltpin),
@@ -1211,13 +1229,83 @@ def print_variant(generic_def):
12111229
variant_cpp_file.write(
12121230
variant_cpp_template.render(
12131231
year=datetime.datetime.now().year,
1214-
generic_def=generic_def,
1232+
generic_list=generic_list,
12151233
pinnames_list=pinnames_list,
12161234
analog_pins_list=analog_pins_list,
12171235
)
12181236
)
12191237

12201238

1239+
def print_boards_entry():
1240+
boards_entry_template = j2_env.get_template(boards_entry_filename)
1241+
# Search if several flash size
1242+
# Also used to manage define name (ARDUINO_GENERIC_*)
1243+
sub = re.search(r"STM32(.*)\((.*)\)(.*)", mcu_refname)
1244+
generic_list = []
1245+
if sub:
1246+
valueline = re.sub(r"\([\s\S]*\)", "x", mcu_refname)
1247+
for index, flash in enumerate(sub.group(2).split("-")):
1248+
gen_name = sub.group(1) + flash + sub.group(3)
1249+
generic_list.append(
1250+
{
1251+
"name": gen_name,
1252+
"board": gen_name.upper(),
1253+
"flash": mcu_flash[index],
1254+
}
1255+
)
1256+
else:
1257+
valueline = mcu_refname
1258+
generic_list.append(
1259+
{
1260+
"name": mcu_refname.replace("STM32", ""),
1261+
"board": mcu_refname.replace("STM32", "").upper(),
1262+
"flash": mcu_flash[0],
1263+
}
1264+
)
1265+
1266+
gen_entry = mcu_family.replace("STM32", "Gen")
1267+
1268+
# Parse only one time the CMSIS startup file
1269+
if mcu_family not in startup_dict:
1270+
# Search the product line
1271+
CMSIS_startup_file_path = (
1272+
system_path
1273+
/ "Drivers"
1274+
/ "CMSIS"
1275+
/ "Device"
1276+
/ "ST"
1277+
/ mcu_dir
1278+
/ "Source"
1279+
/ "Templates"
1280+
/ "gcc"
1281+
)
1282+
startup_dict[mcu_family] = sorted(
1283+
[s.name for s in CMSIS_startup_file_path.glob("startup_*.s")]
1284+
)
1285+
for s in startup_dict[mcu_family]:
1286+
mcu_line = re.split("_|\\.", s)[1]
1287+
if "stm32mp15" in mcu_line and not mcu_line.endswith("xx"):
1288+
mcu_line += "xx"
1289+
mcu_line = mcu_line.upper().replace("X", "x")
1290+
if mcu_line > valueline:
1291+
break
1292+
else:
1293+
# In case of CMSIS device does not exist
1294+
mcu_line = ""
1295+
1296+
boards_entry_file.write(
1297+
boards_entry_template.render(
1298+
generic_list=generic_list,
1299+
gen_entry=gen_entry,
1300+
mcu_name=mcu_refname,
1301+
mcu_dir=mcu_dir,
1302+
mcu_ram=mcu_ram,
1303+
product_line=mcu_line,
1304+
)
1305+
)
1306+
return generic_list
1307+
1308+
12211309
# List management
12221310
tokenize = re.compile(r"(\d+)|(\D+)").findall
12231311

@@ -1536,12 +1624,15 @@ def manage_repo():
15361624
root_dir = cur_dir.parents[1]
15371625
system_path = root_dir / "system"
15381626
templates_dir = cur_dir / "templates"
1627+
mcu_dir = ""
15391628
periph_c_filename = "PeripheralPins.c"
15401629
pinvar_h_filename = "PinNamesVar.h"
15411630
config_filename = Path("variant_config.json")
15421631
variant_h_filename = "variant.h"
15431632
variant_cpp_filename = "variant.cpp"
1633+
boards_entry_filename = "boards_entry.txt"
15441634
repo_local_path = cur_dir / "repo"
1635+
cubemxdir = ""
15451636
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
15461637
repo_name = gh_url.rsplit("/", 1)[-1]
15471638
repo_path = repo_local_path / repo_name
@@ -1553,7 +1644,7 @@ def manage_repo():
15531644
parser = argparse.ArgumentParser(
15541645
description=textwrap.dedent(
15551646
"""\
1556-
By default, generate {}, {}, {} and {}
1647+
By default, generate {}, {}, {}, {} and {}
15571648
for all xml files description available in STM32CubeMX internal database.
15581649
Internal database path must be defined in {}.
15591650
It can be the one from STM32CubeMX directory if defined:
@@ -1566,6 +1657,7 @@ def manage_repo():
15661657
pinvar_h_filename,
15671658
variant_cpp_filename,
15681659
variant_h_filename,
1660+
boards_entry_filename,
15691661
config_filename,
15701662
cubemxdir,
15711663
gh_url,
@@ -1687,7 +1779,7 @@ def manage_repo():
16871779

16881780
# Open input file
16891781
xml_mcu = parse(str(mcu_file))
1690-
parse_IP_file()
1782+
parse_mcu_file()
16911783
if not gpiofile:
16921784
print("Could not find GPIO file")
16931785
quit()
@@ -1699,6 +1791,7 @@ def manage_repo():
16991791
pinvar_h_filepath = out_path / pinvar_h_filename
17001792
variant_cpp_filepath = out_path / variant_cpp_filename
17011793
variant_h_filepath = out_path / variant_h_filename
1794+
boards_entry_filepath = out_path / boards_entry_filename
17021795
out_path.mkdir(parents=True, exist_ok=True)
17031796

17041797
# open output file
@@ -1715,24 +1808,18 @@ def manage_repo():
17151808
if variant_h_filepath.exists():
17161809
variant_h_filepath.unlink()
17171810
variant_h_file = open(variant_h_filepath, "w", newline="\n")
1811+
if boards_entry_filepath.exists():
1812+
boards_entry_filepath.unlink()
1813+
boards_entry_file = open(boards_entry_filepath, "w", newline="\n")
17181814

17191815
parse_pins()
17201816
sort_my_lists()
17211817
manage_alternate()
17221818

1723-
# manage ARDUINO_GENERIC_* define name
1724-
# Search if several flash size
1725-
sub = re.search(r"STM32(.*)\((.*)\)(.*)", mcu_file.stem)
1726-
generic_def = []
1727-
if sub:
1728-
for flash in sub.group(2).split("-"):
1729-
generic_def.append((sub.group(1) + flash + sub.group(3)).upper())
1730-
else:
1731-
generic_def = [mcu_file.stem.upper()]
1732-
1819+
generic_list = print_boards_entry()
17331820
print_peripheral()
17341821
print_pinamevar()
1735-
print_variant(generic_def)
1822+
print_variant(generic_list)
17361823

17371824
print(
17381825
"* Total I/O pins found: {}".format(
@@ -1755,3 +1842,6 @@ def manage_repo():
17551842
pinvar_h_file.close()
17561843
variant_h_file.close()
17571844
variant_cpp_file.close()
1845+
boards_entry_file.close()
1846+
xml_mcu.unlink()
1847+
xml_gpio.unlink()

CI/utils/templates/boards_entry.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file help to add generic board entry.
2+
# upload.maximum_size and product_line have to be verified
3+
# and changed if needed.
4+
# See: https://github.com/stm32duino/wiki/wiki/Add-a-new-variant-%28board%29
5+
6+
{% for generic in generic_list %}
7+
# Generic {{generic.name}}
8+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}=Generic {{generic.name}}
9+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}.upload.maximum_size={{generic.flash}}
10+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}.upload.maximum_data_size={{mcu_ram}}
11+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}.build.board=GENERIC_{{generic.board}}
12+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}.build.product_line={{product_line}}
13+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}.build.mcu_name={{mcu_name}}
14+
{{gen_entry}}.menu.pnum.GENERIC_{{generic.board}}.build.variant={{mcu_dir}}/{{mcu_name}}
15+
16+
{% endfor %}

0 commit comments

Comments
 (0)