Skip to content

Commit 437cbed

Browse files
authored
Merge pull request #1710 from fpistm/HAL_Legacy
HAL legacy support
2 parents 6ba929e + a018a5f commit 437cbed

File tree

265 files changed

+693
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+693
-702
lines changed

Diff for: CI/update/stm32cube.py

+1-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
script_path = Path(__file__).parent.resolve()
1616
sys.path.append(str(script_path.parent))
1717
from utils import copyFile, copyFolder, createFolder, deleteFolder, genSTM32List
18+
from utils import execute_cmd, getRepoBranchName
1819

1920
if sys.platform.startswith("win32"):
2021
from colorama import init
@@ -74,16 +75,6 @@
7475
out_separator = "-" * 70
7576

7677

77-
def execute_cmd(cmd, stderror):
78-
try:
79-
output = subprocess.check_output(cmd, stderr=stderror).decode("utf-8").strip()
80-
except subprocess.CalledProcessError as e:
81-
print("Failed command: ")
82-
print(e.cmd)
83-
exit(e.returncode)
84-
return output
85-
86-
8778
def create_config(config_file_path):
8879
global repo_local_path
8980

@@ -238,22 +229,6 @@ def createSystemFiles(serie):
238229
copyFile(hal_conf_file, hal_conf_default)
239230

240231

241-
def getRepoBranchName(repo_path):
242-
bname = ""
243-
rname = ""
244-
cmd = ["git", "-C", repo_path, "branch", "-r"]
245-
bnames = execute_cmd(cmd, None).split("\n")
246-
for b in bnames:
247-
name_match = re.match(r"\S+/\S+ -> (\S+)/(\S+)", b.strip())
248-
if name_match:
249-
rname = name_match.group(1)
250-
bname = name_match.group(2)
251-
if not bname:
252-
print(f"Could not find branch name for {repo_path}!")
253-
exit(1)
254-
return (rname, bname)
255-
256-
257232
def updateCoreRepo():
258233
# Handle core repo
259234
repo_path = repo_local_path / repo_core_name

Diff for: CI/update/stm32variant.py

+82-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import argparse
2-
import datetime
32
import json
43
import re
54
import subprocess
@@ -13,6 +12,10 @@
1312
from pathlib import Path
1413
from xml.dom.minidom import parse, Node
1514

15+
script_path = Path(__file__).parent.resolve()
16+
sys.path.append(str(script_path.parent))
17+
from utils import execute_cmd, getRepoBranchName
18+
1619
mcu_list = [] # 'name'
1720
io_list = [] # 'PIN','name'
1821
alt_list = [] # 'PIN','name'
@@ -58,7 +61,7 @@
5861
mcu_refname = ""
5962
mcu_flash = []
6063
mcu_ram = []
61-
64+
legacy_hal = {"CAN": ["F0", "F1", "F2", "F3", "F4", "F7", "L4"], "ETH": ["F4", "H7"]}
6265
# Cube information
6366
product_line_dict = {}
6467

@@ -185,7 +188,7 @@ def parse_mcu_file():
185188
else:
186189
usb_inst["usb"] = inst.group(1)
187190
else:
188-
if gpiofile == "" and "GPIO" in s.attributes["Name"].value:
191+
if gpiofile == "" and s.attributes["Name"].value == "GPIO":
189192
gpiofile = s.attributes["Version"].value
190193

191194

@@ -813,7 +816,9 @@ def can_pinmap(lst):
813816
)
814817
return dict(
815818
name=name,
816-
hal=name,
819+
hal=["CAN", "CAN_LEGACY"]
820+
if name != "FDCAN" and any(mcu in mcu_family for mcu in legacy_hal["CAN"])
821+
else name,
817822
aname=aname,
818823
data="",
819824
wpin=max(wpin) + 1,
@@ -842,7 +847,9 @@ def eth_pinmap():
842847
)
843848
return dict(
844849
name="ETHERNET",
845-
hal="ETH",
850+
hal=["ETH", "ETH_LEGACY"]
851+
if any(mcu in mcu_family for mcu in legacy_hal["ETH"])
852+
else "ETH",
846853
aname="Ethernet",
847854
data="",
848855
wpin=max(wpin) + 1,
@@ -2007,7 +2014,9 @@ def aggregate_dir():
20072014
out_family_path = root_dir / "variants" / mcu_family.name
20082015
# Get all mcu_dir
20092016
mcu_dirs = sorted(mcu_family.glob("*/"))
2010-
2017+
# Get original directory list of current serie STM32YYxx
2018+
mcu_out_dirs_ori = sorted(out_family_path.glob("*/"))
2019+
mcu_out_dirs_up = []
20112020
# Group mcu directories when only expressions and xml file name are different
20122021
while mcu_dirs:
20132022
# Pop first item
@@ -2069,8 +2078,38 @@ def aggregate_dir():
20692078
fname.unlink()
20702079
else:
20712080
fname.replace(out_path / fname.name)
2081+
# Append updated directory to the list of current serie STM32YYxx
2082+
mcu_out_dirs_up.append(out_path)
20722083
del group_mcu_dir[:]
20732084
del mcu_dir1_files_list[:]
2085+
mcu_out_dirs_up.sort()
2086+
new_dirs = set(mcu_out_dirs_up) - set(mcu_out_dirs_ori)
2087+
if new_dirs:
2088+
nb_new = len(new_dirs)
2089+
dir_str = "directories" if nb_new > 1 else "directory"
2090+
print(f"\nNew {dir_str} for {mcu_family.name}:\n")
2091+
for d in new_dirs:
2092+
print(f" - {d.name}")
2093+
print("\n --> Please, check if it is a new directory or a renamed one.")
2094+
old_dirs = set(mcu_out_dirs_ori) - set(mcu_out_dirs_up)
2095+
if old_dirs:
2096+
nb_old = len(old_dirs)
2097+
dir_str = "Directories" if nb_old > 1 else "Directory"
2098+
print(f"\n{dir_str} not updated for {mcu_family.name}:\n")
2099+
for d in old_dirs:
2100+
print(f" - {d.name}")
2101+
print(
2102+
"""
2103+
--> Please, check if it is due to directory name update (renamed), if true then:
2104+
- Move custom boards definition files, if any.
2105+
- Move linker script(s), if any.
2106+
- Copy 'SystemClock_Config(void)' function to the new generic clock config file.
2107+
--> Then remove it, update old path in boards.txt
2108+
(for custom board(s) as well as generic ones).
2109+
"""
2110+
)
2111+
del mcu_out_dirs_ori[:]
2112+
del mcu_out_dirs_up[:]
20742113

20752114

20762115
def default_cubemxdir():
@@ -2143,46 +2182,44 @@ def manage_repo():
21432182
global db_release
21442183
repo_local_path.mkdir(parents=True, exist_ok=True)
21452184

2146-
try:
2147-
if not args.skip:
2148-
print(f"Updating {repo_name}...")
2149-
if repo_path.is_dir():
2150-
# Get new tags from the remote
2151-
git_cmds = [
2152-
["git", "-C", repo_path, "clean", "-fdx"],
2153-
["git", "-C", repo_path, "fetch"],
2154-
["git", "-C", repo_path, "reset", "--hard", "origin/main"],
2155-
]
2156-
else:
2157-
# Clone it as it does not exists yet
2158-
git_cmds = [["git", "-C", repo_local_path, "clone", gh_url]]
2159-
2160-
for cmd in git_cmds:
2161-
subprocess.check_output(cmd).decode("utf-8")
2185+
if not args.skip:
2186+
print(f"Updating {repo_name}...")
21622187
if repo_path.is_dir():
2163-
# Get tag
2164-
sha1_id = (
2165-
subprocess.check_output(
2166-
["git", "-C", repo_path, "rev-list", "--tags", "--max-count=1"]
2167-
)
2168-
.decode("utf-8")
2169-
.strip()
2170-
)
2171-
version_tag = (
2172-
subprocess.check_output(
2173-
["git", "-C", repo_path, "describe", "--tags", sha1_id]
2174-
)
2175-
.decode("utf-8")
2176-
.strip()
2177-
)
2178-
subprocess.check_output(
2179-
["git", "-C", repo_path, "checkout", version_tag],
2180-
stderr=subprocess.DEVNULL,
2181-
)
2182-
db_release = version_tag
2183-
return True
2184-
except subprocess.CalledProcessError as e:
2185-
print(f"Command {e.cmd} failed with error code {e.returncode}")
2188+
rname, bname = getRepoBranchName(repo_path)
2189+
2190+
# Get new tags from the remote
2191+
git_cmds = [
2192+
["git", "-C", repo_path, "clean", "-fdx"],
2193+
["git", "-C", repo_path, "fetch"],
2194+
[
2195+
"git",
2196+
"-C",
2197+
repo_path,
2198+
"reset",
2199+
"--hard",
2200+
f"{rname}/{bname}",
2201+
],
2202+
]
2203+
else:
2204+
# Clone it as it does not exists yet
2205+
git_cmds = [["git", "-C", repo_local_path, "clone", gh_url]]
2206+
2207+
for cmd in git_cmds:
2208+
execute_cmd(cmd, None)
2209+
if repo_path.is_dir():
2210+
# Get tag
2211+
sha1_id = execute_cmd(
2212+
["git", "-C", repo_path, "rev-list", "--tags", "--max-count=1"], None
2213+
)
2214+
version_tag = execute_cmd(
2215+
["git", "-C", repo_path, "describe", "--tags", sha1_id], None
2216+
)
2217+
execute_cmd(
2218+
["git", "-C", repo_path, "checkout", version_tag],
2219+
subprocess.DEVNULL,
2220+
)
2221+
db_release = version_tag
2222+
return True
21862223
return False
21872224

21882225

Diff for: CI/update/stm32wrapper.py

+45-38
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ def wrap(arg_core, arg_cmsis, log):
184184
lower = serie.lower()
185185

186186
# Search stm32yyxx_[hal|ll]*.c file
187-
filelist = src.glob(f"stm32{lower}xx_*.c")
187+
filelist = src.glob(f"**/stm32{lower}xx_*.c")
188188
for fp in filelist:
189+
legacy = True if fp.parent.name == "Legacy" else False
189190
# File name
190191
fn = fp.name
191192
found = peripheral_c_regex.match(fn)
@@ -194,14 +195,30 @@ def wrap(arg_core, arg_cmsis, log):
194195
peripheral = found.group(1) if found else "hal"
195196
if "_ll_" in fn:
196197
if peripheral in ll_c_dict:
197-
ll_c_dict[peripheral].append(lower)
198+
if legacy:
199+
# Change legacy value if exists
200+
current_list = ll_c_dict.pop(peripheral)
201+
if current_list[-1][0] == lower:
202+
current_list.pop()
203+
current_list.append((lower, legacy))
204+
ll_c_dict[peripheral] = current_list
205+
else:
206+
ll_c_dict[peripheral].append((lower, legacy))
198207
else:
199-
ll_c_dict[peripheral] = [lower]
208+
ll_c_dict[peripheral] = [(lower, legacy)]
200209
else:
201210
if peripheral in hal_c_dict:
202-
hal_c_dict[peripheral].append(lower)
211+
if legacy:
212+
# Change legacy value if exists
213+
current_list = hal_c_dict.pop(peripheral)
214+
if current_list[-1][0] == lower:
215+
current_list.pop()
216+
current_list.append((lower, legacy))
217+
hal_c_dict[peripheral] = current_list
218+
else:
219+
hal_c_dict[peripheral].append((lower, legacy))
203220
else:
204-
hal_c_dict[peripheral] = [lower]
221+
hal_c_dict[peripheral] = [(lower, legacy)]
205222

206223
# Search stm32yyxx_ll_*.h file
207224
filelist = inc.glob(f"stm32{lower}xx_ll_*.h")
@@ -219,39 +236,29 @@ def wrap(arg_core, arg_cmsis, log):
219236
else:
220237
ll_h_dict[peripheral] = [lower]
221238

222-
# Generate stm32yyxx_hal_*.c file
223-
for key, value in hal_c_dict.items():
224-
if key == "hal":
225-
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace(
226-
"_ppp", ""
227-
)
228-
else:
229-
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace(
230-
"ppp", key
231-
)
232-
out_file = open(filepath, "w", newline="\n")
233-
out_file.write(
234-
c_file_template.render(periph=key, type="hal", serieslist=value)
235-
)
236-
out_file.close()
237-
# Generate stm32yyxx_ll_*.c file
238-
for key, value in ll_c_dict.items():
239-
filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace(
240-
"ppp", key
241-
)
242-
out_file = open(filepath, "w", newline="\n")
243-
out_file.write(
244-
c_file_template.render(periph=key, type="ll", serieslist=value)
245-
)
246-
out_file.close()
247-
# Generate stm32yyxx_ll_*.h file
248-
for key, value in ll_h_dict.items():
249-
filepath = LLoutInc_path / ll_h_file.replace("ppp", key)
250-
out_file = open(filepath, "w", newline="\n")
251-
out_file.write(ll_h_file_template.render(periph=key, serieslist=value))
252-
out_file.close()
253-
if log:
254-
print("done")
239+
# Generate stm32yyxx_hal_*.c file
240+
for key, value in hal_c_dict.items():
241+
if key == "hal":
242+
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("_ppp", "")
243+
else:
244+
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("ppp", key)
245+
out_file = open(filepath, "w", newline="\n")
246+
out_file.write(c_file_template.render(periph=key, type="hal", serieslist=value))
247+
out_file.close()
248+
# Generate stm32yyxx_ll_*.c file
249+
for key, value in ll_c_dict.items():
250+
filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace("ppp", key)
251+
out_file = open(filepath, "w", newline="\n")
252+
out_file.write(c_file_template.render(periph=key, type="ll", serieslist=value))
253+
out_file.close()
254+
# Generate stm32yyxx_ll_*.h file
255+
for key, value in ll_h_dict.items():
256+
filepath = LLoutInc_path / ll_h_file.replace("ppp", key)
257+
out_file = open(filepath, "w", newline="\n")
258+
out_file.write(ll_h_file_template.render(periph=key, serieslist=value))
259+
out_file.close()
260+
if log:
261+
print("done")
255262

256263
# Filter all LL header file
257264
all_ll_h_list = sorted(set(all_ll_h_list))

Diff for: CI/update/templates/stm32yyxx_zz_ppp.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#pragma GCC diagnostic push
33
#pragma GCC diagnostic ignored "-Wunused-parameter"
44

5-
{% for serie in serieslist %}
5+
{% for serie, legacy in serieslist %}
66
{% if loop.first %}
77
#ifdef STM32{{serie.upper()}}xx
88
{% else %}
@@ -11,6 +11,9 @@
1111
{% if type == periph %}
1212
#include "stm32{{serie}}xx_{{type}}.c"
1313
{% else %}
14+
{% if legacy %}
15+
#include "Legacy/stm32{{serie}}xx_{{type}}_{{periph}}.c"
16+
{% endif %}
1417
#include "stm32{{serie}}xx_{{type}}_{{periph}}.c"
1518
{% endif %}
1619
{% if loop.last %}

Diff for: CI/utils/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .pathlib_ext import *
1+
from .common_ext import *

0 commit comments

Comments
 (0)