Skip to content

Commit a231311

Browse files
committed
[stm32variant] Add generic_clock.c generation
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent a520f2c commit a231311

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ boards.local.txt
44
platform.local.txt
55
path_config.json
66
update_config.json
7+
variant_config.json
78

89
# Backup
910
*.bak
@@ -34,4 +35,4 @@ __pycache__/
3435
!.vscode/tasks.json
3536
!.vscode/launch.json
3637
!.vscode/extensions.json
37-
*.code-workspace
38+
*.code-workspace

CI/utils/stm32variant.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,16 @@ def print_boards_entry():
13371337
return generic_list
13381338

13391339

1340+
def print_general_clock(generic_list):
1341+
generic_clock_template = j2_env.get_template(generic_clock_filename)
1342+
generic_clock_file.write(
1343+
generic_clock_template.render(
1344+
year=datetime.datetime.now().year,
1345+
generic_list=generic_list,
1346+
)
1347+
)
1348+
1349+
13401350
# List management
13411351
tokenize = re.compile(r"(\d+)|(\D+)").findall
13421352

@@ -1665,6 +1675,7 @@ def manage_repo():
16651675
variant_h_filename = "variant.h"
16661676
variant_cpp_filename = "variant.cpp"
16671677
boards_entry_filename = "boards_entry.txt"
1678+
generic_clock_filename = "generic_clock.c"
16681679
repo_local_path = cur_dir / "repo"
16691680
cubemxdir = ""
16701681
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
@@ -1678,7 +1689,13 @@ def manage_repo():
16781689
parser = argparse.ArgumentParser(
16791690
description=textwrap.dedent(
16801691
"""\
1681-
By default, generate {}, {}, {}, {} and {}
1692+
By default, generates:
1693+
- {},
1694+
- {},
1695+
- {},
1696+
- {},
1697+
- {}
1698+
- {}
16821699
for all xml files description available in STM32CubeMX internal database.
16831700
Internal database path must be defined in {}.
16841701
It can be the one from STM32CubeMX directory if defined:
@@ -1692,6 +1709,7 @@ def manage_repo():
16921709
variant_cpp_filename,
16931710
variant_h_filename,
16941711
boards_entry_filename,
1712+
generic_clock_filename,
16951713
config_filename,
16961714
cubemxdir,
16971715
gh_url,
@@ -1718,15 +1736,10 @@ def manage_repo():
17181736
metavar="xml",
17191737
help=textwrap.dedent(
17201738
"""\
1721-
Generate {}, {}, {} and {}
1722-
for specified mcu xml file description in database.
1739+
Generate all files for specified mcu xml file description in database.
17231740
This xml file can contain non alpha characters in its name,
1724-
you should call it with double quotes""".format(
1725-
periph_c_filename,
1726-
pinvar_h_filename,
1727-
variant_cpp_filename,
1728-
variant_h_filename,
1729-
)
1741+
you should call it with double quotes.
1742+
"""
17301743
),
17311744
)
17321745

@@ -1844,6 +1857,7 @@ def manage_repo():
18441857
variant_cpp_filepath = out_temp_path / variant_cpp_filename
18451858
variant_h_filepath = out_temp_path / variant_h_filename
18461859
boards_entry_filepath = out_temp_path / boards_entry_filename
1860+
generic_clock_filepath = out_temp_path / generic_clock_filename
18471861
out_temp_path.mkdir(parents=True, exist_ok=True)
18481862

18491863
# open output file
@@ -1852,12 +1866,13 @@ def manage_repo():
18521866
variant_cpp_file = open(variant_cpp_filepath, "w", newline="\n")
18531867
variant_h_file = open(variant_h_filepath, "w", newline="\n")
18541868
boards_entry_file = open(boards_entry_filepath, "w", newline="\n")
1855-
1869+
generic_clock_file = open(generic_clock_filepath, "w", newline="\n")
18561870
parse_pins()
18571871
sort_my_lists()
18581872
manage_alternate()
18591873

18601874
generic_list = print_boards_entry()
1875+
print_general_clock(generic_list)
18611876
print_peripheral()
18621877
print_pinamevar()
18631878
print_variant(generic_list)
@@ -1884,6 +1899,7 @@ def manage_repo():
18841899
variant_h_file.close()
18851900
variant_cpp_file.close()
18861901
boards_entry_file.close()
1902+
generic_clock_file.close()
18871903
xml_mcu.unlink()
18881904
xml_gpio.unlink()
18891905

@@ -2014,7 +2030,7 @@ def manage_repo():
20142030
new_line_c += " || {}".format(pre)
20152031
new_line_h += " && !{}".format(pre)
20162032
update_file(mcu_dir / variant_cpp_filename, update_regex, new_line_c)
2017-
2033+
update_file(mcu_dir / generic_clock_filename, update_regex, new_line_c)
20182034
update_file(mcu_dir / variant_h_filename, update_regex, new_line_h)
20192035

20202036
# Appending to board_entry file
@@ -2029,8 +2045,12 @@ def manage_repo():
20292045

20302046
# Move to variants/ folder
20312047
out_path = out_family_path / mcu_dir.stem
2048+
generic_clock_filepath = out_path / generic_clock_filename
20322049
out_path.mkdir(parents=True, exist_ok=True)
20332050
for fname in mcu_dir.glob("*.*"):
2034-
fname.replace(out_path / fname.name)
2051+
if fname.name == generic_clock_filename and generic_clock_filepath.exists():
2052+
fname.unlink()
2053+
else:
2054+
fname.replace(out_path / fname.name)
20352055
# Clean temporary dir
20362056
rm_tree(tmp_dir)

CI/utils/templates/generic_clock.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2020-{{year}}, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#if defined(ARDUINO_GENERIC_{{generic_list[0].board}}){% for name in generic_list[1:] %} || defined(ARDUINO_GENERIC_{{name.board}}){% endfor %}
14+
15+
#include "pins_arduino.h"
16+
17+
/**
18+
* @brief System Clock Configuration
19+
* @param None
20+
* @retval None
21+
*/
22+
WEAK void SystemClock_Config(void)
23+
{
24+
/* SystemClock_Config can be generated by STM32CubeMX */
25+
#warning "SystemClock_Config() is empty. Default clock at reset is used."
26+
}
27+
28+
#endif /* ARDUINO_GENERIC_* */
29+

0 commit comments

Comments
 (0)