Skip to content

Commit df00535

Browse files
committed
fix(stm32variant): flash size management
"flash" node is not always present in the mcu xml file. Add a backup based on mcu reference name else warn and set it to 0. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 9be939e commit df00535

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

CI/update/stm32variant.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,35 @@
9292
"CAN": ["F0", "F1", "F2", "F3", "F4", "F7", "L4"],
9393
"ETH": ["F4", "F7", "H7"],
9494
}
95+
96+
# Flash size encoding in not always present in the mcu file but it is generally
97+
# encoded as a single character (number or letter) which can be mapped to the
98+
# actual flash size in bytes.
99+
flash_size_dict = {
100+
"0": 1024, # 1Kb
101+
"1": 2048, # 2Kb
102+
"2": 4096, # 4Kb
103+
"3": 8192, # 8Kb
104+
"4": 16384, # 16Kb
105+
"5": 24576, # 24Kb
106+
"6": 32768, # 32Kb
107+
"7": 49152, # 48Kb
108+
"8": 65536, # 64Kb
109+
"9": 73728, # 72Kb
110+
"A": 98304, # 96Kb
111+
"B": 131072, # 128Kb
112+
"Z": 196608, # 192Kb
113+
"C": 262144, # 256Kb
114+
"D": 393216, # 384Kb
115+
"E": 524288, # 512Kb
116+
"F": 786432, # 768Kb
117+
"G": 1048576, # 1Mb
118+
"H": 1572864, # 1.5Mb
119+
"I": 2097152, # 2Mb
120+
"K": 3145728, # 3Mb
121+
"J": 4194304, # 4Mb
122+
}
123+
95124
# Cube information
96125
product_line_dict = {}
97126
svd_dict = {} # 'name':'svd file'
@@ -206,9 +235,24 @@ def parse_mcu_file():
206235
ram_node = mcu_node.getElementsByTagName("Ram")
207236
for f in ram_node:
208237
mcu_ram.append(int(f.firstChild.nodeValue) * 1024)
209-
flash_node = mcu_node.getElementsByTagName("Flash")
210-
for f in flash_node:
211-
mcu_flash.append(int(f.firstChild.nodeValue) * 1024)
238+
# Test if Flash size is present in the mcu file, if not get it from flash_size array
239+
if not mcu_node.getElementsByTagName("Flash"):
240+
# flash id is the character after the series name and the two next characters
241+
# (e.g. STM32F103xB -> flash id is 'B')
242+
flash_id = mcu_refname[len(mcu_family) + 3]
243+
# flash_id = mcu_refname.split("x")[-1]
244+
if flash_id in flash_size_dict:
245+
mcu_flash.append(flash_size_dict[flash_id])
246+
else:
247+
print(
248+
f"Warning: Flash size '{flash_id}' not found in dict for MCU {mcu_refname}."
249+
)
250+
print("Flash size set to 0.")
251+
mcu_flash.append(0)
252+
else:
253+
flash_node = mcu_node.getElementsByTagName("Flash")
254+
for f in flash_node:
255+
mcu_flash.append(int(f.firstChild.nodeValue) * 1024)
212256

213257
itemlist = xml_mcu.getElementsByTagName("IP")
214258
for s in itemlist:

0 commit comments

Comments
 (0)