48
48
tim_inst_list = [] # TIMx instance
49
49
usb_inst = {"usb" : "" , "otg_fs" : "" , "otg_hs" : "" }
50
50
mcu_family = ""
51
+ mcu_refname = ""
52
+ mcu_flash = []
53
+ mcu_ram = ""
54
+
55
+ # Cube information
56
+ startup_dict = {}
51
57
52
58
# format
53
59
# Peripheral
59
65
60
66
61
67
# mcu file parsing
62
- def parse_IP_file ():
68
+ def parse_mcu_file ():
63
69
global gpiofile
64
70
global mcu_family
71
+ global mcu_refname
72
+ global mcu_ram
73
+
65
74
tim_regex = r"^(TIM\d+)$"
66
75
usb_regex = r"^(USB(?!PD|_HOST|_DEVICE).*)$"
67
76
gpiofile = ""
68
77
del tim_inst_list [:]
78
+ del mcu_flash [:]
69
79
usb_inst ["usb" ] = ""
70
80
usb_inst ["otg_fs" ] = ""
71
81
usb_inst ["otg_hs" ] = ""
72
82
73
83
mcu_node = xml_mcu .getElementsByTagName ("Mcu" )[0 ]
74
84
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 )
75
93
76
94
itemlist = xml_mcu .getElementsByTagName ("IP" )
77
95
for s in itemlist :
@@ -95,7 +113,7 @@ def parse_IP_file():
95
113
96
114
97
115
def get_gpio_af_num (pintofind , iptofind ):
98
- if "STM32F10 " in mcu_file . stem :
116
+ if "STM32F1 " in mcu_family :
99
117
return get_gpio_af_numF1 (pintofind , iptofind )
100
118
# DBG print ('pin to find ' + pintofind)
101
119
i = 0
@@ -325,7 +343,7 @@ def adc_pinmap():
325
343
wpin = []
326
344
# For STM32L47xxx/48xxx, it is necessary to configure
327
345
# the GPIOx_ASCR register
328
- if re .match ("STM32L4[78]+" , mcu_file . stem ):
346
+ if re .match ("STM32L4[78]+" , mcu_refname ):
329
347
default_mode = "STM_MODE_ANALOG_ADC_CONTROL"
330
348
else :
331
349
default_mode = "STM_MODE_ANALOG"
@@ -512,7 +530,7 @@ def uart_pinmap(lst):
512
530
inst = p [2 ].split ("_" )[0 ]
513
531
winst .append (len (inst ))
514
532
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 :
516
534
mode = "STM_MODE_INPUT"
517
535
else :
518
536
mode = "STM_MODE_AF_PP"
@@ -598,7 +616,7 @@ def can_pinmap(lst):
598
616
inst += "1"
599
617
winst .append (len (inst ))
600
618
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 :
602
620
mode = "STM_MODE_INPUT"
603
621
else :
604
622
mode = "STM_MODE_AF_PP"
@@ -1106,7 +1124,7 @@ def timer_variant():
1106
1124
return dict (tone = tone , servo = servo )
1107
1125
1108
1126
1109
- def print_variant (generic_def ):
1127
+ def print_variant (generic_list ):
1110
1128
variant_h_template = j2_env .get_template (variant_h_filename )
1111
1129
variant_cpp_template = j2_env .get_template (variant_cpp_filename )
1112
1130
@@ -1192,7 +1210,7 @@ def print_variant(generic_def):
1192
1210
variant_h_file .write (
1193
1211
variant_h_template .render (
1194
1212
year = datetime .datetime .now ().year ,
1195
- generic_def = generic_def ,
1213
+ generic_list = generic_list ,
1196
1214
pins_number_list = pins_number_list ,
1197
1215
alt_pins_list = alt_pins_list ,
1198
1216
waltpin = max (waltpin ),
@@ -1211,13 +1229,83 @@ def print_variant(generic_def):
1211
1229
variant_cpp_file .write (
1212
1230
variant_cpp_template .render (
1213
1231
year = datetime .datetime .now ().year ,
1214
- generic_def = generic_def ,
1232
+ generic_list = generic_list ,
1215
1233
pinnames_list = pinnames_list ,
1216
1234
analog_pins_list = analog_pins_list ,
1217
1235
)
1218
1236
)
1219
1237
1220
1238
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
+
1221
1309
# List management
1222
1310
tokenize = re .compile (r"(\d+)|(\D+)" ).findall
1223
1311
@@ -1536,12 +1624,15 @@ def manage_repo():
1536
1624
root_dir = cur_dir .parents [1 ]
1537
1625
system_path = root_dir / "system"
1538
1626
templates_dir = cur_dir / "templates"
1627
+ mcu_dir = ""
1539
1628
periph_c_filename = "PeripheralPins.c"
1540
1629
pinvar_h_filename = "PinNamesVar.h"
1541
1630
config_filename = Path ("variant_config.json" )
1542
1631
variant_h_filename = "variant.h"
1543
1632
variant_cpp_filename = "variant.cpp"
1633
+ boards_entry_filename = "boards_entry.txt"
1544
1634
repo_local_path = cur_dir / "repo"
1635
+ cubemxdir = ""
1545
1636
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
1546
1637
repo_name = gh_url .rsplit ("/" , 1 )[- 1 ]
1547
1638
repo_path = repo_local_path / repo_name
@@ -1553,7 +1644,7 @@ def manage_repo():
1553
1644
parser = argparse .ArgumentParser (
1554
1645
description = textwrap .dedent (
1555
1646
"""\
1556
- By default, generate {}, {}, {} and {}
1647
+ By default, generate {}, {}, {}, {} and {}
1557
1648
for all xml files description available in STM32CubeMX internal database.
1558
1649
Internal database path must be defined in {}.
1559
1650
It can be the one from STM32CubeMX directory if defined:
@@ -1566,6 +1657,7 @@ def manage_repo():
1566
1657
pinvar_h_filename ,
1567
1658
variant_cpp_filename ,
1568
1659
variant_h_filename ,
1660
+ boards_entry_filename ,
1569
1661
config_filename ,
1570
1662
cubemxdir ,
1571
1663
gh_url ,
@@ -1687,7 +1779,7 @@ def manage_repo():
1687
1779
1688
1780
# Open input file
1689
1781
xml_mcu = parse (str (mcu_file ))
1690
- parse_IP_file ()
1782
+ parse_mcu_file ()
1691
1783
if not gpiofile :
1692
1784
print ("Could not find GPIO file" )
1693
1785
quit ()
@@ -1699,6 +1791,7 @@ def manage_repo():
1699
1791
pinvar_h_filepath = out_path / pinvar_h_filename
1700
1792
variant_cpp_filepath = out_path / variant_cpp_filename
1701
1793
variant_h_filepath = out_path / variant_h_filename
1794
+ boards_entry_filepath = out_path / boards_entry_filename
1702
1795
out_path .mkdir (parents = True , exist_ok = True )
1703
1796
1704
1797
# open output file
@@ -1715,24 +1808,18 @@ def manage_repo():
1715
1808
if variant_h_filepath .exists ():
1716
1809
variant_h_filepath .unlink ()
1717
1810
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 " )
1718
1814
1719
1815
parse_pins ()
1720
1816
sort_my_lists ()
1721
1817
manage_alternate ()
1722
1818
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 ()
1733
1820
print_peripheral ()
1734
1821
print_pinamevar ()
1735
- print_variant (generic_def )
1822
+ print_variant (generic_list )
1736
1823
1737
1824
print (
1738
1825
"* Total I/O pins found: {}" .format (
@@ -1755,3 +1842,6 @@ def manage_repo():
1755
1842
pinvar_h_file .close ()
1756
1843
variant_h_file .close ()
1757
1844
variant_cpp_file .close ()
1845
+ boards_entry_file .close ()
1846
+ xml_mcu .unlink ()
1847
+ xml_gpio .unlink ()
0 commit comments