Skip to content

Commit 9b5706d

Browse files
committed
script: stm32variant: fix database path management
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 3a5a025 commit 9b5706d

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

CI/utils/stm32variant.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,9 @@ def print_pinamevar():
11301130

11311131
# Variant files generation
11321132
def spi_pins_variant():
1133-
ss_pin = ss1_pin = ss2_pin = ss3_pin = mosi_pin = miso_pin = sck_pin = "PNUM_NOT_DEFINED"
1133+
ss_pin = (
1134+
ss1_pin
1135+
) = ss2_pin = ss3_pin = mosi_pin = miso_pin = sck_pin = "PNUM_NOT_DEFINED"
11341136

11351137
# Iterate to find match instance if any
11361138
for mosi in spimosi_list:
@@ -2030,28 +2032,30 @@ def aggregate_dir():
20302032
del mcu_dir1_files_list[:]
20312033

20322034

2035+
def default_cubemxdir():
2036+
global cubemxdir
2037+
if sys.platform.startswith("win32"):
2038+
print("Platform is Windows")
2039+
cubemxdir = Path(r"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX")
2040+
elif sys.platform.startswith("linux"):
2041+
print("Platform is Linux")
2042+
cubemxdir = Path.home() / "STM32CubeMX"
2043+
elif sys.platform.startswith("darwin"):
2044+
print("Platform is Mac OSX")
2045+
cubemxdir = Path(
2046+
"/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources"
2047+
)
2048+
else:
2049+
print("Platform unknown")
2050+
cubemxdir = "<Set CubeMX install directory>"
2051+
2052+
20332053
# Config management
20342054
def create_config():
20352055
# Create a Json file for a better path management
20362056
try:
20372057
print("Please set your configuration in '{}' file".format(config_filename))
20382058
config_file = open(config_filename, "w", newline="\n")
2039-
if sys.platform.startswith("win32"):
2040-
print("Platform is Windows")
2041-
cubemxdir = Path(
2042-
r"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX"
2043-
)
2044-
elif sys.platform.startswith("linux"):
2045-
print("Platform is Linux")
2046-
cubemxdir = Path.home() / "STM32CubeMX"
2047-
elif sys.platform.startswith("darwin"):
2048-
print("Platform is Mac OSX")
2049-
cubemxdir = Path(
2050-
"/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources"
2051-
)
2052-
else:
2053-
print("Platform unknown")
2054-
cubemxdir = "<Set CubeMX install directory>"
20552059
config_file.write(
20562060
json.dumps(
20572061
{
@@ -2071,21 +2075,23 @@ def check_config():
20712075
global cubemxdir
20722076
global repo_local_path
20732077
global repo_path
2074-
2078+
default_cubemxdir()
20752079
if config_filename.is_file():
20762080
try:
20772081
config_file = open(config_filename, "r")
20782082
config = json.load(config_file)
20792083
config_file.close()
20802084

2081-
conf = config["REPO_LOCAL_PATH"]
2082-
if conf:
2083-
if conf != "":
2084-
repo_local_path = Path(conf)
2085-
repo_path = repo_local_path / repo_name
2086-
conf = config["CUBEMX_DIRECTORY"]
2087-
if conf:
2088-
cubemxdir = Path(conf)
2085+
if "REPO_LOCAL_PATH" in config:
2086+
conf = config["REPO_LOCAL_PATH"]
2087+
if conf:
2088+
if conf != "":
2089+
repo_local_path = Path(conf)
2090+
repo_path = repo_local_path / repo_name
2091+
if "CUBEMX_DIRECTORY" in config:
2092+
conf = config["CUBEMX_DIRECTORY"]
2093+
if conf:
2094+
cubemxdir = Path(conf)
20892095
except IOError:
20902096
print("Failed to open " + config_filename)
20912097
else:
@@ -2096,9 +2102,9 @@ def manage_repo():
20962102
global db_release
20972103
repo_local_path.mkdir(parents=True, exist_ok=True)
20982104

2099-
print("Updating " + repo_name + "...")
21002105
try:
21012106
if not args.skip:
2107+
print("Updating " + repo_name + "...")
21022108
if repo_path.is_dir():
21032109
# Get new tags from the remote
21042110
git_cmds = [
@@ -2156,7 +2162,7 @@ def manage_repo():
21562162
boards_entry_filename = "boards_entry.txt"
21572163
generic_clock_filename = "generic_clock.c"
21582164
repo_local_path = cur_dir / "repo"
2159-
cubemxdir = ""
2165+
cubemxdir = Path()
21602166
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
21612167
repo_name = gh_url.rsplit("/", 1)[-1]
21622168
repo_path = repo_local_path / repo_name
@@ -2255,6 +2261,7 @@ def manage_repo():
22552261
if manage_repo():
22562262
dirMCU = repo_path / "mcu"
22572263
dirIP = dirMCU / "IP"
2264+
print("Using GitHub repository database")
22582265
else:
22592266
fallback = True
22602267
if fallback or args.cube:
@@ -2271,6 +2278,7 @@ def manage_repo():
22712278

22722279
dirMCU = cubemxdir / "db" / "mcu"
22732280
dirIP = dirMCU / "IP"
2281+
print("Using STM32CubeMX internal database")
22742282
version_file = cubemxdir / "db" / "package.xml"
22752283
if version_file.is_file():
22762284
xml_file = parse(str(version_file))

0 commit comments

Comments
 (0)