Skip to content

HAL legacy support #1710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions CI/update/stm32cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
script_path = Path(__file__).parent.resolve()
sys.path.append(str(script_path.parent))
from utils import copyFile, copyFolder, createFolder, deleteFolder, genSTM32List
from utils import execute_cmd, getRepoBranchName

if sys.platform.startswith("win32"):
from colorama import init
Expand Down Expand Up @@ -74,16 +75,6 @@
out_separator = "-" * 70


def execute_cmd(cmd, stderror):
try:
output = subprocess.check_output(cmd, stderr=stderror).decode("utf-8").strip()
except subprocess.CalledProcessError as e:
print("Failed command: ")
print(e.cmd)
exit(e.returncode)
return output


def create_config(config_file_path):
global repo_local_path

Expand Down Expand Up @@ -238,22 +229,6 @@ def createSystemFiles(serie):
copyFile(hal_conf_file, hal_conf_default)


def getRepoBranchName(repo_path):
bname = ""
rname = ""
cmd = ["git", "-C", repo_path, "branch", "-r"]
bnames = execute_cmd(cmd, None).split("\n")
for b in bnames:
name_match = re.match(r"\S+/\S+ -> (\S+)/(\S+)", b.strip())
if name_match:
rname = name_match.group(1)
bname = name_match.group(2)
if not bname:
print(f"Could not find branch name for {repo_path}!")
exit(1)
return (rname, bname)


def updateCoreRepo():
# Handle core repo
repo_path = repo_local_path / repo_core_name
Expand Down
127 changes: 82 additions & 45 deletions CI/update/stm32variant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import datetime
import json
import re
import subprocess
Expand All @@ -13,6 +12,10 @@
from pathlib import Path
from xml.dom.minidom import parse, Node

script_path = Path(__file__).parent.resolve()
sys.path.append(str(script_path.parent))
from utils import execute_cmd, getRepoBranchName

mcu_list = [] # 'name'
io_list = [] # 'PIN','name'
alt_list = [] # 'PIN','name'
Expand Down Expand Up @@ -58,7 +61,7 @@
mcu_refname = ""
mcu_flash = []
mcu_ram = []

legacy_hal = {"CAN": ["F0", "F1", "F2", "F3", "F4", "F7", "L4"], "ETH": ["F4", "H7"]}
# Cube information
product_line_dict = {}

Expand Down Expand Up @@ -185,7 +188,7 @@ def parse_mcu_file():
else:
usb_inst["usb"] = inst.group(1)
else:
if gpiofile == "" and "GPIO" in s.attributes["Name"].value:
if gpiofile == "" and s.attributes["Name"].value == "GPIO":
gpiofile = s.attributes["Version"].value


Expand Down Expand Up @@ -813,7 +816,9 @@ def can_pinmap(lst):
)
return dict(
name=name,
hal=name,
hal=["CAN", "CAN_LEGACY"]
if name != "FDCAN" and any(mcu in mcu_family for mcu in legacy_hal["CAN"])
else name,
aname=aname,
data="",
wpin=max(wpin) + 1,
Expand Down Expand Up @@ -842,7 +847,9 @@ def eth_pinmap():
)
return dict(
name="ETHERNET",
hal="ETH",
hal=["ETH", "ETH_LEGACY"]
if any(mcu in mcu_family for mcu in legacy_hal["ETH"])
else "ETH",
aname="Ethernet",
data="",
wpin=max(wpin) + 1,
Expand Down Expand Up @@ -2007,7 +2014,9 @@ def aggregate_dir():
out_family_path = root_dir / "variants" / mcu_family.name
# Get all mcu_dir
mcu_dirs = sorted(mcu_family.glob("*/"))

# Get original directory list of current serie STM32YYxx
mcu_out_dirs_ori = sorted(out_family_path.glob("*/"))
mcu_out_dirs_up = []
# Group mcu directories when only expressions and xml file name are different
while mcu_dirs:
# Pop first item
Expand Down Expand Up @@ -2069,8 +2078,38 @@ def aggregate_dir():
fname.unlink()
else:
fname.replace(out_path / fname.name)
# Append updated directory to the list of current serie STM32YYxx
mcu_out_dirs_up.append(out_path)
del group_mcu_dir[:]
del mcu_dir1_files_list[:]
mcu_out_dirs_up.sort()
new_dirs = set(mcu_out_dirs_up) - set(mcu_out_dirs_ori)
if new_dirs:
nb_new = len(new_dirs)
dir_str = "directories" if nb_new > 1 else "directory"
print(f"\nNew {dir_str} for {mcu_family.name}:\n")
for d in new_dirs:
print(f" - {d.name}")
print("\n --> Please, check if it is a new directory or a renamed one.")
old_dirs = set(mcu_out_dirs_ori) - set(mcu_out_dirs_up)
if old_dirs:
nb_old = len(old_dirs)
dir_str = "Directories" if nb_old > 1 else "Directory"
print(f"\n{dir_str} not updated for {mcu_family.name}:\n")
for d in old_dirs:
print(f" - {d.name}")
print(
"""
--> Please, check if it is due to directory name update (renamed), if true then:
- Move custom boards definition files, if any.
- Move linker script(s), if any.
- Copy 'SystemClock_Config(void)' function to the new generic clock config file.
--> Then remove it, update old path in boards.txt
(for custom board(s) as well as generic ones).
"""
)
del mcu_out_dirs_ori[:]
del mcu_out_dirs_up[:]


def default_cubemxdir():
Expand Down Expand Up @@ -2143,46 +2182,44 @@ def manage_repo():
global db_release
repo_local_path.mkdir(parents=True, exist_ok=True)

try:
if not args.skip:
print(f"Updating {repo_name}...")
if repo_path.is_dir():
# Get new tags from the remote
git_cmds = [
["git", "-C", repo_path, "clean", "-fdx"],
["git", "-C", repo_path, "fetch"],
["git", "-C", repo_path, "reset", "--hard", "origin/main"],
]
else:
# Clone it as it does not exists yet
git_cmds = [["git", "-C", repo_local_path, "clone", gh_url]]

for cmd in git_cmds:
subprocess.check_output(cmd).decode("utf-8")
if not args.skip:
print(f"Updating {repo_name}...")
if repo_path.is_dir():
# Get tag
sha1_id = (
subprocess.check_output(
["git", "-C", repo_path, "rev-list", "--tags", "--max-count=1"]
)
.decode("utf-8")
.strip()
)
version_tag = (
subprocess.check_output(
["git", "-C", repo_path, "describe", "--tags", sha1_id]
)
.decode("utf-8")
.strip()
)
subprocess.check_output(
["git", "-C", repo_path, "checkout", version_tag],
stderr=subprocess.DEVNULL,
)
db_release = version_tag
return True
except subprocess.CalledProcessError as e:
print(f"Command {e.cmd} failed with error code {e.returncode}")
rname, bname = getRepoBranchName(repo_path)

# Get new tags from the remote
git_cmds = [
["git", "-C", repo_path, "clean", "-fdx"],
["git", "-C", repo_path, "fetch"],
[
"git",
"-C",
repo_path,
"reset",
"--hard",
f"{rname}/{bname}",
],
]
else:
# Clone it as it does not exists yet
git_cmds = [["git", "-C", repo_local_path, "clone", gh_url]]

for cmd in git_cmds:
execute_cmd(cmd, None)
if repo_path.is_dir():
# Get tag
sha1_id = execute_cmd(
["git", "-C", repo_path, "rev-list", "--tags", "--max-count=1"], None
)
version_tag = execute_cmd(
["git", "-C", repo_path, "describe", "--tags", sha1_id], None
)
execute_cmd(
["git", "-C", repo_path, "checkout", version_tag],
subprocess.DEVNULL,
)
db_release = version_tag
return True
return False


Expand Down
83 changes: 45 additions & 38 deletions CI/update/stm32wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ def wrap(arg_core, arg_cmsis, log):
lower = serie.lower()

# Search stm32yyxx_[hal|ll]*.c file
filelist = src.glob(f"stm32{lower}xx_*.c")
filelist = src.glob(f"**/stm32{lower}xx_*.c")
for fp in filelist:
legacy = True if fp.parent.name == "Legacy" else False
# File name
fn = fp.name
found = peripheral_c_regex.match(fn)
Expand All @@ -194,14 +195,30 @@ def wrap(arg_core, arg_cmsis, log):
peripheral = found.group(1) if found else "hal"
if "_ll_" in fn:
if peripheral in ll_c_dict:
ll_c_dict[peripheral].append(lower)
if legacy:
# Change legacy value if exists
current_list = ll_c_dict.pop(peripheral)
if current_list[-1][0] == lower:
current_list.pop()
current_list.append((lower, legacy))
ll_c_dict[peripheral] = current_list
else:
ll_c_dict[peripheral].append((lower, legacy))
else:
ll_c_dict[peripheral] = [lower]
ll_c_dict[peripheral] = [(lower, legacy)]
else:
if peripheral in hal_c_dict:
hal_c_dict[peripheral].append(lower)
if legacy:
# Change legacy value if exists
current_list = hal_c_dict.pop(peripheral)
if current_list[-1][0] == lower:
current_list.pop()
current_list.append((lower, legacy))
hal_c_dict[peripheral] = current_list
else:
hal_c_dict[peripheral].append((lower, legacy))
else:
hal_c_dict[peripheral] = [lower]
hal_c_dict[peripheral] = [(lower, legacy)]

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

# Generate stm32yyxx_hal_*.c file
for key, value in hal_c_dict.items():
if key == "hal":
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace(
"_ppp", ""
)
else:
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace(
"ppp", key
)
out_file = open(filepath, "w", newline="\n")
out_file.write(
c_file_template.render(periph=key, type="hal", serieslist=value)
)
out_file.close()
# Generate stm32yyxx_ll_*.c file
for key, value in ll_c_dict.items():
filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace(
"ppp", key
)
out_file = open(filepath, "w", newline="\n")
out_file.write(
c_file_template.render(periph=key, type="ll", serieslist=value)
)
out_file.close()
# Generate stm32yyxx_ll_*.h file
for key, value in ll_h_dict.items():
filepath = LLoutInc_path / ll_h_file.replace("ppp", key)
out_file = open(filepath, "w", newline="\n")
out_file.write(ll_h_file_template.render(periph=key, serieslist=value))
out_file.close()
if log:
print("done")
# Generate stm32yyxx_hal_*.c file
for key, value in hal_c_dict.items():
if key == "hal":
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("_ppp", "")
else:
filepath = HALoutSrc_path / c_file.replace("zz", "hal").replace("ppp", key)
out_file = open(filepath, "w", newline="\n")
out_file.write(c_file_template.render(periph=key, type="hal", serieslist=value))
out_file.close()
# Generate stm32yyxx_ll_*.c file
for key, value in ll_c_dict.items():
filepath = LLoutSrc_path / c_file.replace("zz", "ll").replace("ppp", key)
out_file = open(filepath, "w", newline="\n")
out_file.write(c_file_template.render(periph=key, type="ll", serieslist=value))
out_file.close()
# Generate stm32yyxx_ll_*.h file
for key, value in ll_h_dict.items():
filepath = LLoutInc_path / ll_h_file.replace("ppp", key)
out_file = open(filepath, "w", newline="\n")
out_file.write(ll_h_file_template.render(periph=key, serieslist=value))
out_file.close()
if log:
print("done")

# Filter all LL header file
all_ll_h_list = sorted(set(all_ll_h_list))
Expand Down
5 changes: 4 additions & 1 deletion CI/update/templates/stm32yyxx_zz_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"

{% for serie in serieslist %}
{% for serie, legacy in serieslist %}
{% if loop.first %}
#ifdef STM32{{serie.upper()}}xx
{% else %}
Expand All @@ -11,6 +11,9 @@
{% if type == periph %}
#include "stm32{{serie}}xx_{{type}}.c"
{% else %}
{% if legacy %}
#include "Legacy/stm32{{serie}}xx_{{type}}_{{periph}}.c"
{% endif %}
#include "stm32{{serie}}xx_{{type}}_{{periph}}.c"
{% endif %}
{% if loop.last %}
Expand Down
2 changes: 1 addition & 1 deletion CI/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .pathlib_ext import *
from .common_ext import *
Loading